Skip to content

Commit 8ef7f49

Browse files
authored
Configure ESLint (#1084)
* Add eslint * Configure import formatting / linting * Format and lint code * Format and lint demo * Fix tests
1 parent 7fc7cd5 commit 8ef7f49

File tree

143 files changed

+4497
-1484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+4497
-1484
lines changed

.prettierrc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"singleQuote": true,
44
"bracketSpacing": false,
55
"arrowParens": "avoid",
6-
"trailingComma": "none"
6+
"trailingComma": "none",
7+
"importOrder": ["^react$", "<THIRD_PARTY_MODULES>", "^@/.*$", "^[./]"],
8+
"importOrderSeparation": true,
9+
"plugins": ["@trivago/prettier-plugin-sort-imports"]
710
}

demo/Demo.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
/* eslint-disable react/prop-types */
12
import React, {useState} from 'react';
3+
24
import {
35
Alert,
46
Badge,
@@ -37,29 +39,29 @@ import {
3739
Tooltip
3840
} from '../src';
3941

40-
const StateWrapper = ({tag: Tag, ...otherProps}) => {
42+
function StateWrapper({tag: Tag, ...otherProps}) {
4143
// helper to mimic setProps functionality
4244
const [state, setState] = useState(otherProps);
4345
return <Tag setProps={props => setState({...state, ...props})} {...state} />;
44-
};
46+
}
4547

46-
const CollapseComponent = ({children}) => {
48+
function CollapseComponent({children}) {
4749
const [isOpen, setIsOpen] = useState(false);
4850

4951
return (
5052
<div>
51-
<Button onClick={() => setIsOpen(!isOpen)}>Toggle collapse</Button>
53+
<Button setProps={() => setIsOpen(!isOpen)}>Toggle collapse</Button>
5254
<Collapse is_open={isOpen}>{children}</Collapse>
5355
</div>
5456
);
55-
};
57+
}
5658

5759
const FadeComponent = ({children}) => {
5860
const [isIn, setIsIn] = useState(false);
5961

6062
return (
6163
<div>
62-
<Button onClick={() => setIsOpen(!isIn)}>Toggle fade</Button>
64+
<Button setProps={() => setIsIn(!isIn)}>Toggle fade</Button>
6365
<Fade is_in={isIn}>{children}</Fade>
6466
</div>
6567
);
@@ -212,7 +214,7 @@ const Demo = () => (
212214
<Col md={3}>
213215
<Card>
214216
<CardBody>
215-
<h5 className="card-title">Here's another card</h5>
217+
<h5 className="card-title">Here&apos;s another card</h5>
216218
<p className="card-text">With some text, and a button</p>
217219
<Button color="success">Click here</Button>
218220
</CardBody>
@@ -221,7 +223,7 @@ const Demo = () => (
221223
<Col md={3}>
222224
<Card>
223225
<CardBody>
224-
<h5 className="card-title">Here's yet another card</h5>
226+
<h5 className="card-title">Here&apos;s yet another card</h5>
225227
<p className="card-text">With some text, and some links</p>
226228
<CardLink href="https://www.asidatascience.com">
227229
External

demo/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
2+
3+
import {createRoot} from 'react-dom/client';
34

45
import Demo from './Demo';
56

6-
const rootInstance = ReactDOM.render(
7-
<Demo />,
8-
document.getElementById('react-demo-entry-point')
9-
);
7+
const root = createRoot(document.getElementById('react-demo-entry-point'));
8+
9+
root.render(<Demo />);

eslint.config.mjs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import pluginJs from '@eslint/js';
2+
import pluginJest from 'eslint-plugin-jest';
3+
import pluginReact from 'eslint-plugin-react';
4+
import unusedImports from 'eslint-plugin-unused-imports';
5+
import globals from 'globals';
6+
7+
/** @type {import('eslint').Linter.Config[]} */
8+
export default [
9+
{
10+
files: ['**/*.{js,mjs,cjs,jsx}'],
11+
settings: {react: {version: 'detect'}},
12+
plugins: {jest: pluginJest, 'unused-imports': unusedImports},
13+
languageOptions: {
14+
globals: pluginJest.environments.globals.globals
15+
},
16+
rules: {
17+
'no-unused-vars': 'off',
18+
'unused-imports/no-unused-imports': 'error',
19+
'unused-imports/no-unused-vars': [
20+
'warn',
21+
{
22+
vars: 'all',
23+
varsIgnorePattern: '^_',
24+
args: 'after-used',
25+
argsIgnorePattern: '^_'
26+
}
27+
],
28+
'jest/no-disabled-tests': 'warn',
29+
'jest/no-focused-tests': 'error',
30+
'jest/no-identical-title': 'error',
31+
'jest/prefer-to-have-length': 'warn',
32+
'jest/valid-expect': 'error'
33+
}
34+
},
35+
{languageOptions: {globals: globals.browser}},
36+
37+
pluginJs.configs.recommended,
38+
pluginReact.configs.flat.recommended
39+
];

0 commit comments

Comments
 (0)