Skip to content

Commit 1136095

Browse files
author
Matthew Holloway
authored
Merge pull request #276 from springload/feat/enable-eslint
feat(tslint): adopt eslint & fix issues it raised
2 parents 00355ad + 4521042 commit 1136095

13 files changed

+3813
-2174
lines changed

.eslintrc.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
parser: "@typescript-eslint/parser",
3+
parserOptions: {
4+
jsx: true,
5+
},
6+
plugins: ["react", "@typescript-eslint", "jsx-a11y"],
7+
extends: [
8+
"eslint:recommended",
9+
"plugin:react/recommended",
10+
"plugin:@typescript-eslint/recommended",
11+
"plugin:jsx-a11y/recommended",
12+
],
13+
settings: {
14+
react: {
15+
pragma: "React",
16+
version: "detect",
17+
},
18+
},
19+
rules: {
20+
"@typescript-eslint/no-non-null-assertion": "off",
21+
"react/prop-types": "off",
22+
},
23+
};

demo/src/index.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ const App = (): JSX.Element => (
3838
<h1>React Accessible Accordion</h1>
3939

4040
<p>
41-
React Component for creating an 'Accordion' that adheres to the{' '}
41+
React Component for creating an &apos;Accordion&apos; that adheres
42+
to the{' '}
4243
<a
4344
href="https://www.w3.org/TR/wai-aria-practices-1.1/#accordion"
4445
target="_blank"
@@ -188,10 +189,10 @@ const App = (): JSX.Element => (
188189
<h2 className="u-margin-top">Accessing Item State</h2>
189190

190191
<p>
191-
If you'd like to apply different content or styling based on the{' '}
192-
<strong>expanded</strong> or <strong>disabled</strong> state of an
193-
item, you might like to use the <strong>AccordionItemState</strong>{' '}
194-
render-prop component.
192+
If you&apos;d like to apply different content or styling based on
193+
the <strong>expanded</strong> or <strong>disabled</strong> state of
194+
an item, you might like to use the{' '}
195+
<strong>AccordionItemState</strong> render-prop component.
195196
</p>
196197

197198
<Accordion>
@@ -206,7 +207,9 @@ const App = (): JSX.Element => (
206207
<br />
207208
<br />
208209
<AccordionItemState>
209-
{(state: object): React.ReactNode =>
210+
{(
211+
state: Record<string, unknown>,
212+
): React.ReactNode =>
210213
`State: ${JSON.stringify(state)}`
211214
}
212215
</AccordionItemState>

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test:coverage": "jest --coverage",
1414
"test:coverage:watch": "jest --coverage --watch",
1515
"coveralls": "cat ./coverage/lcov.info | coveralls",
16-
"lint": "tslint --project .",
16+
"lint": "eslint src",
1717
"typecheck": "tsc --project .",
1818
"build": "rimraf \"dist/**/*\" && yarn build:rollup && yarn build:types && yarn build:css",
1919
"build:css": "cp src/css/*.css dist",
@@ -96,11 +96,16 @@
9696
"@types/react-syntax-highlighter": "^11.0.4",
9797
"@types/react-test-renderer": "^16.8.2",
9898
"@types/uuid": "^3.4.4",
99+
"@typescript-eslint/eslint-plugin": "^3.6.0",
100+
"@typescript-eslint/parser": "^3.6.0",
99101
"babel-core": "^7.0.0-bridge.0",
100102
"babel-jest": "^24.8.0",
101103
"babel-loader": "^8.0.6",
102104
"coveralls": "^3.0.3",
103105
"css-loader": "^3.0.0",
106+
"eslint": "^7.4.0",
107+
"eslint-plugin-jsx-a11y": "^6.3.1",
108+
"eslint-plugin-react": "^7.20.3",
104109
"file-loader": "^4.0.0",
105110
"gh-pages": "^2.0.1",
106111
"html-webpack-plugin": "^3.2.0",
@@ -121,11 +126,6 @@
121126
"rollup-plugin-node-resolve": "^5.1.0",
122127
"rollup-plugin-replace": "^2.1.1",
123128
"style-loader": "^0.23.1",
124-
"tslint": "^6.1.2",
125-
"tslint-config-prettier": "^1.18.0",
126-
"tslint-microsoft-contrib": "^6.2.0",
127-
"tslint-plugin-prettier": "^2.3.0",
128-
"tslint-react": "^5.0.0",
129129
"typescript": "^3.9.5",
130130
"uuid": "^3.3.2",
131131
"webpack": "^4.29.6",

src/components/Accordion.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const Accordion = ({
2121
onChange,
2222
preExpanded,
2323
...rest
24-
}: AccordionProps) => {
24+
}: AccordionProps): JSX.Element => {
2525
return (
2626
<Provider
2727
preExpanded={preExpanded}

src/components/AccordionContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ export class Provider extends React.PureComponent<
7878
return this.state.getPanelAttributes(key, dangerouslySetExpanded);
7979
};
8080

81-
getHeadingAttributes = (key: UUID): InjectedHeadingAttributes => {
82-
return this.state.getHeadingAttributes(key);
81+
getHeadingAttributes = (): InjectedHeadingAttributes => {
82+
// uuid: UUID
83+
return this.state.getHeadingAttributes();
8384
};
8485

8586
getButtonAttributes = (

src/components/AccordionItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const AccordionItem = ({
2121
activeClassName,
2222
dangerouslySetExpanded,
2323
...rest
24-
}: Props) => {
24+
}: Props): JSX.Element => {
2525
const renderChildren = (itemContext: ItemContext): JSX.Element => {
2626
const { expanded } = itemContext;
2727
const cx = expanded && activeClassName ? activeClassName : className;

src/components/AccordionItemButton.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ const AccordionItemButton = ({
7373
<div
7474
className={className}
7575
{...rest}
76-
// tslint:disable-next-line react-a11y-event-has-role
76+
role="button"
77+
tabIndex={0}
7778
onClick={toggleExpanded}
7879
onKeyDown={handleKeyPress}
7980
data-accordion-component="AccordionItemButton"

src/components/AccordionItemState.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ type Props = Pick<DivAttributes, Exclude<keyof DivAttributes, 'children'>> & {
88
): React.ReactNode;
99
};
1010

11-
const AccordionItemState = ({ children }: Props) => {
11+
const AccordionItemState = ({ children }: Props): JSX.Element => {
1212
const renderChildren = (itemContext: ItemContext): JSX.Element => {
1313
const { expanded, disabled } = itemContext;
1414

src/components/ItemContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ class Provider extends React.Component<ProviderProps> {
6969
headingAttributes,
7070
buttonAttributes,
7171
}}
72-
children={this.props.children}
73-
/>
72+
>
73+
{this.props.children}
74+
</Context.Provider>
7475
);
7576
};
7677

src/helpers/AccordionStore.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,8 @@ export default class AccordionStore {
9696
};
9797
};
9898

99-
public readonly getHeadingAttributes = (
100-
uuid: UUID,
101-
): InjectedHeadingAttributes => {
99+
public readonly getHeadingAttributes = (): // uuid: UUID,
100+
InjectedHeadingAttributes => {
102101
return {
103102
role: 'heading',
104103
};

0 commit comments

Comments
 (0)