Skip to content

Commit 5bc5c72

Browse files
committed
refactor(lint): eslint and prettier update, format code
1 parent 533a3b5 commit 5bc5c72

15 files changed

Lines changed: 106 additions & 62 deletions

.eslintrc.json

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
{
22
"parser": "babel-eslint",
3-
"extends": ["airbnb", "prettier"],
4-
"plugins": ["prettier"],
3+
"parserOptions": {
4+
"ecmaVersion": 2020,
5+
"sourceType": "module",
6+
"ecmaFeatures": {
7+
"jsx": true
8+
}
9+
},
10+
"settings": {
11+
"react": {
12+
"version": "detect"
13+
}
14+
},
15+
"env": {
16+
"browser": true,
17+
"amd": true,
18+
"node": true,
19+
"es6": true
20+
},
21+
"extends": [
22+
"airbnb",
23+
"eslint:recommended",
24+
"plugin:prettier/recommended"
25+
],
526
"rules": {
6-
"prettier/prettier": ["error"],
27+
"prettier/prettier": ["error", {}, { "usePrettierrc": true }],
728
"import/prefer-default-export": "off",
829
"import/no-extraneous-dependencies": "off",
930
"import/no-mutable-exports": "off",
@@ -16,7 +37,8 @@
1637
"react/state-in-constructor": "off",
1738
"react/jsx-props-no-spreading": "off",
1839
"react/prop-types": "off",
19-
"react/jsx-one-expression-per-line": "off"
40+
"react/jsx-one-expression-per-line": "off",
41+
"react/jsx-closing-bracket-location": "off"
2042
},
2143
"globals": {
2244
"window": true,

.vscode/settings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"files.insertFinalNewline": true,
3-
"files.trimFinalNewlines": true,
4-
"editor.defaultFormatter": "esbenp.prettier-vscode",
5-
"editor.formatOnSave": true
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": true
4+
},
5+
"eslint.validate": ["javascript"]
66
}

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Every pull request will require an approved review before merging.
2222

2323
## Linters
2424

25-
This project is using [ESLint](https://eslint.org/) for linting and [Prettier](https://prettier.io/) for code formatting. Please follow their standards on contributing. Your code is automatically formatted on saving a file when using [VSCode](https://code.visualstudio.com/) or [Atom](https://atom.io/). [Husky](https://github.com/typicode/husky) ensures that your changes are properly linted before making a commit. If you want to lint manually, you can use `lint` and `lint --fix` npm scripts to lint the source code and the test files.
25+
This project is using [ESLint](https://eslint.org/) for linting and [Prettier](https://prettier.io/) for code formatting. Please follow their standards on contributing. Your code is automatically formatted on saving a file when using [VSCode](https://code.visualstudio.com/) or [Atom](https://atom.io/). [Husky](https://github.com/typicode/husky) ensures that your changes are properly linted before making a commit. If you want to lint manually, you can use `lint` and `lint-fix` npm scripts to lint the source code and the test files.
2626

2727
## Tests
2828

__tests__/batching.test.jsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ describe('batching', () => {
272272
expect(renderCount).toBe(1);
273273
expect(container).toHaveTextContent('Bob');
274274
await new Promise(
275-
resolve =>
275+
(resolve) =>
276276
setTimeout(() => {
277277
person.name = 'Ann';
278278
person.name = 'Rick';
@@ -295,7 +295,7 @@ describe('batching', () => {
295295
const { container } = render(<MyComp />);
296296
expect(renderCount).toBe(1);
297297
expect(container).toHaveTextContent('Bob');
298-
await new Promise(resolve =>
298+
await new Promise((resolve) =>
299299
// eslint-disable-next-line
300300
requestAnimationFrame(() => {
301301
person.name = 'Ann';
@@ -418,18 +418,18 @@ describe('batching', () => {
418418

419419
test('should not break Promises', async () => {
420420
await Promise.resolve(12)
421-
.then(value => {
421+
.then((value) => {
422422
expect(value).toBe(12);
423423
// eslint-disable-next-line
424424
throw 15;
425425
})
426-
.catch(err => {
426+
.catch((err) => {
427427
expect(err).toBe(15);
428428
});
429429
});
430430

431431
test('should not break setTimeout', async () => {
432-
await new Promise(resolve => {
432+
await new Promise((resolve) => {
433433
setTimeout(
434434
(arg1, arg2, arg3) => {
435435
expect(arg1).toBe('Hello');
@@ -459,10 +459,10 @@ describe('batching', () => {
459459
expect(callCount).toBe(1);
460460
});
461461

462-
test('should not break method this value and args', done => {
462+
test('should not break method this value and args', (done) => {
463463
const socket = new WebSocket('ws://www.example.com');
464464

465-
socket.onclose = function(ev) {
465+
socket.onclose = function (ev) {
466466
expect(ev).toBeDefined();
467467
expect(this).toBe(socket);
468468
done();
@@ -471,11 +471,11 @@ describe('batching', () => {
471471
socket.close();
472472
});
473473

474-
test('should not break callback this value and args', done => {
474+
test('should not break callback this value and args', (done) => {
475475
const ctx = {};
476476

477477
setTimeout(
478-
function(arg1, arg2) {
478+
function (arg1, arg2) {
479479
expect(arg1).toBe('Test');
480480
expect(arg2).toBe('Test2');
481481
expect(this).toBe(ctx);

__tests__/edgeCases.test.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('edge cases', () => {
6464
state = { counter: 0 };
6565

6666
handleIncrement = () => {
67-
this.setState(prevState => ({
67+
this.setState((prevState) => ({
6868
counter: prevState.counter + 1,
6969
}));
7070
};
@@ -91,7 +91,7 @@ describe('edge cases', () => {
9191
state = { counter: 0 };
9292

9393
handleIncrement = () => {
94-
this.setState(prevState => ({
94+
this.setState((prevState) => ({
9595
counter: prevState.counter + 1,
9696
}));
9797
};
@@ -127,7 +127,7 @@ describe('edge cases', () => {
127127
<StrictMode>
128128
<div>
129129
<button
130-
onClick={() => setChild(value => !value)}
130+
onClick={() => setChild((value) => !value)}
131131
type="button"
132132
>
133133
Toggle Child

__tests__/staticProps.test.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('static props', () => {
2626
});
2727

2828
test('view() should proxy defaultProps for functional components', () => {
29-
const MyCustomCompName = props => {
29+
const MyCustomCompName = (props) => {
3030
return <div>{props.name}</div>;
3131
};
3232

@@ -54,7 +54,7 @@ describe('static props', () => {
5454

5555
const errorSpy = jest
5656
.spyOn(console, 'error')
57-
.mockImplementation(message =>
57+
.mockImplementation((message) =>
5858
expect(message.indexOf('Failed prop type')).not.toBe(-1),
5959
);
6060
render(<ViewComp number="Bob" />);
@@ -63,7 +63,7 @@ describe('static props', () => {
6363
});
6464

6565
test('view() should proxy propTypes for functional components', () => {
66-
const MyCustomCompName = props => {
66+
const MyCustomCompName = (props) => {
6767
return <div>{props.number}</div>;
6868
};
6969

@@ -75,7 +75,7 @@ describe('static props', () => {
7575

7676
const errorSpy = jest
7777
.spyOn(console, 'error')
78-
.mockImplementation(message =>
78+
.mockImplementation((message) =>
7979
expect(message.indexOf('Failed prop type')).not.toBe(-1),
8080
);
8181
render(<ViewComp number="Bob" />);

package-lock.json

Lines changed: 41 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"coveralls": "cat ./coverage/lcov.info | coveralls",
2020
"test-builds": "node ./scripts/testBuilds.js",
2121
"lint": "eslint --max-warnings 0 --ext js,jsx src scripts __tests__ __mocks__",
22+
"lint-fix": "eslint --fix --max-warnings 0 --ext js,jsx src scripts __tests__ __mocks__",
2223
"install-examples": "node ./scripts/installExamples.js",
2324
"build-examples": "node ./scripts/buildExamples.js",
2425
"build": "rollup --config",
@@ -87,7 +88,7 @@
8788
"coveralls": "^3.1.0",
8889
"eslint": "^7.18.0",
8990
"eslint-config-airbnb": "^18.2.1",
90-
"eslint-config-prettier": "^6.10.0",
91+
"eslint-config-prettier": "^7.2.0",
9192
"eslint-plugin-import": "^2.22.1",
9293
"eslint-plugin-jsx-a11y": "^6.4.1",
9394
"eslint-plugin-prettier": "^3.3.1",
@@ -101,7 +102,7 @@
101102
"no-hook-react-dom": "npm:react-dom@16.7.0",
102103
"no-hook-react-testing-library": "npm:react-testing-library@5.4.4",
103104
"nyc": "^15.1.0",
104-
"prettier": "^1.19.1",
105+
"prettier": "^2.2.1",
105106
"react": "^16.12.0",
106107
"react-dom": "^16.13.0",
107108
"react-native": "^0.63.4",

scripts/buildExamples.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const examplesPath = path.resolve('examples');
77
const examples = fs
88
.readdirSync(examplesPath)
99
.filter(
10-
dir =>
10+
(dir) =>
1111
dir.indexOf('native') === -1 &&
1212
fs.statSync(path.join(examplesPath, dir)).isDirectory(),
1313
);
1414

15-
examples.forEach(example => {
15+
examples.forEach((example) => {
1616
example = path.join(examplesPath, example);
1717
exec('npm run build', {
1818
cwd: example,

scripts/installExamples.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const examplesPath = path.resolve('examples');
66

77
const examples = fs
88
.readdirSync(examplesPath)
9-
.filter(dir =>
9+
.filter((dir) =>
1010
fs.statSync(path.join(examplesPath, dir)).isDirectory(),
1111
);
1212

13-
examples.forEach(example => {
13+
examples.forEach((example) => {
1414
example = path.join(examplesPath, example);
1515
exec('rm -rf node_modules && rm -f package-lock.json && npm i', {
1616
cwd: example,

0 commit comments

Comments
 (0)