Skip to content
This repository was archived by the owner on Sep 17, 2021. It is now read-only.

Commit ba2b782

Browse files
ideexpbot
authored andcommitted
Update linter with support for prettier, easier installation, new configs
This new linter config integrates Prettier with ESLint and relies on ESLint's `--fix` option instead of running Prettier separately. ESLint delegates to Prettier, so `// prettier-ignore` and the `.prettierignore` file still work in addition to ESLint's inline-comment options. There are four linter configs: default, native, web, node. You usually want to use one of the latter three. All three include support for React and Prettier. This also bumps the line length to 100. Going to publish this as 6.0.0-rc.0 and using it in a few projects. Test Plan: Added Jest tests that (a) verify the configs are properly formatted, (b) can run on files as expected, and (c) don't have rules that overlap with Prettier's. (c) is a subjective choice -- it means that if you tell Prettier to ignore some code, ESLint won't enforce some stylistic rules that Prettier normally would take care of -- sometimes that's what you want and sometimes it isn't so I picked the option that gets out of your hair. Also some ESLint rules that support `--fix` ended up duplicating Prettier's work and would add two semicolons or two commas in some places. fbshipit-source-id: cdda43f
1 parent 8bc3070 commit ba2b782

27 files changed

+1051
-349
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
extends: './react.js',
2+
extends: './node.js',
33
};

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Shared ESLint configs for Expo's JS.
77
yarn add --dev eslint-config-expo
88
```
99

10-
You will also need to install `eslint`, `babel-eslint`, `eslint-plugin-babel`, `eslint-plugin-import`, and `eslint-plugin-react` (if you want to lint React and JSX):
10+
You will also need to install `eslint` and `prettier`:
1111

1212
```sh
13-
yarn add --dev eslint babel-eslint eslint-plugin-babel eslint-plugin-import eslint-plugin-react
13+
yarn add --dev eslint prettier
1414
```
1515

1616
## Usage
@@ -33,16 +33,26 @@ module.exports = {
3333
};
3434
```
3535

36-
## React and JSX Support
36+
## Support for Different Platforms
3737

38-
There are two configs: one for JavaScript and one for React. The React configuration extends the JavaScript one and adds support and linter rules for JSX.
38+
There are several configs for different platforms. They are:
39+
* `expo`: the basic config for JavaScript projects for which there isn't a more specific config
40+
* `expo/native`: the config for React Native projects, including Expo projects, with support for React and JSX
41+
* `expo/web`: the config for code that runs in web browsers, with support for React and JSX
42+
* `expo/node`: the config for code that runs in Node
43+
44+
For an Expo project, your configuration might look like this:
3945

40-
###
4146
```js
4247
"eslintConfig": {
43-
"extends": "expo"
44-
// or
45-
"extends": "expo/react"
48+
"extends": "expo/native"
4649
}
4750
```
4851

52+
You also can extend multiple configs, which is useful for projects that span several platforms:
53+
54+
```js
55+
"eslintConfig": {
56+
"extends": ["expo/node", "expo/web"]
57+
}
58+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`fixtures/all-00.js 1`] = `
4+
Object {
5+
"errorCount": 0,
6+
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/all-00.js",
7+
"fixableErrorCount": 0,
8+
"fixableWarningCount": 0,
9+
"messages": Array [],
10+
"output": "import 'hi';
11+
12+
import a from 'a';
13+
import { b } from 'b';
14+
import c, { c1 } from 'c';
15+
import * as d from 'd';
16+
17+
import e from './e';
18+
19+
@d
20+
export class Example {
21+
static s = {
22+
a,
23+
b,
24+
};
25+
26+
m = {};
27+
28+
hi() {
29+
_fn();
30+
}
31+
32+
async byeAsync() {
33+
_fn(a, b, c, c1, d, e);
34+
}
35+
}
36+
37+
function _fn() {}
38+
",
39+
"warningCount": 0,
40+
}
41+
`;
42+
43+
exports[`message 1`] = `
44+
"No rules that are unnecessary or conflict with Prettier were found.
45+
"
46+
`;
47+
48+
exports[`success 1`] = `true`;
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`fixtures/all-00.js 1`] = `
4+
Object {
5+
"errorCount": 0,
6+
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/all-00.js",
7+
"fixableErrorCount": 0,
8+
"fixableWarningCount": 0,
9+
"messages": Array [],
10+
"output": "import 'hi';
11+
12+
import a from 'a';
13+
import { b } from 'b';
14+
import c, { c1 } from 'c';
15+
import * as d from 'd';
16+
17+
import e from './e';
18+
19+
@d
20+
export class Example {
21+
static s = {
22+
a,
23+
b,
24+
};
25+
26+
m = {};
27+
28+
hi() {
29+
_fn();
30+
}
31+
32+
async byeAsync() {
33+
_fn(a, b, c, c1, d, e);
34+
}
35+
}
36+
37+
function _fn() {}
38+
",
39+
"warningCount": 0,
40+
}
41+
`;
42+
43+
exports[`fixtures/web-native-00.js 1`] = `
44+
Object {
45+
"errorCount": 0,
46+
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/web-native-00.js",
47+
"fixableErrorCount": 0,
48+
"fixableWarningCount": 0,
49+
"messages": Array [],
50+
"warningCount": 0,
51+
}
52+
`;
53+
54+
exports[`fixtures/web-native-01.js 1`] = `
55+
Object {
56+
"errorCount": 0,
57+
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/web-native-01.js",
58+
"fixableErrorCount": 0,
59+
"fixableWarningCount": 0,
60+
"messages": Array [
61+
Object {
62+
"column": 3,
63+
"endColumn": 22,
64+
"endLine": 4,
65+
"line": 4,
66+
"message": "props should be placed after render",
67+
"nodeType": "ClassProperty",
68+
"ruleId": "react/sort-comp",
69+
"severity": 1,
70+
"source": " props = { x: 'x' };",
71+
},
72+
Object {
73+
"column": 5,
74+
"endColumn": 19,
75+
"endLine": 7,
76+
"line": 7,
77+
"message": "Unexpected alert.",
78+
"nodeType": "CallExpression",
79+
"ruleId": "no-alert",
80+
"severity": 1,
81+
"source": " alert('uh oh');",
82+
},
83+
Object {
84+
"column": 5,
85+
"endColumn": 18,
86+
"endLine": 8,
87+
"line": 8,
88+
"message": "Do not use setState in componentDidMount",
89+
"nodeType": "MemberExpression",
90+
"ruleId": "react/no-did-mount-set-state",
91+
"severity": 1,
92+
"source": " this.setState({});",
93+
},
94+
],
95+
"output": "import React from 'react';
96+
97+
export default class Example extends React.Component {
98+
props = { x: 'x' };
99+
100+
componentDidMount() {
101+
alert('uh oh');
102+
this.setState({});
103+
}
104+
105+
render() {
106+
return (
107+
<div>
108+
{this.props.x}
109+
</div>
110+
);
111+
}
112+
}
113+
",
114+
"warningCount": 3,
115+
}
116+
`;
117+
118+
exports[`fixtures/web-native-02.js 1`] = `
119+
Object {
120+
"errorCount": 0,
121+
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/web-native-02.js",
122+
"fixableErrorCount": 0,
123+
"fixableWarningCount": 0,
124+
"messages": Array [
125+
Object {
126+
"column": 3,
127+
"endColumn": 25,
128+
"endLine": 10,
129+
"line": 10,
130+
"message": "componentDidMount should be placed before componentDidUpdate",
131+
"nodeType": "MethodDefinition",
132+
"ruleId": "react/sort-comp",
133+
"severity": 1,
134+
"source": " componentDidMount() {}",
135+
},
136+
],
137+
"source": "import React from 'react';
138+
139+
export default class Example extends React.Component {
140+
componentDidUpdate() {}
141+
142+
render() {
143+
return null;
144+
}
145+
146+
componentDidMount() {}
147+
148+
static getInitialProps() {}
149+
}
150+
",
151+
"warningCount": 1,
152+
}
153+
`;
154+
155+
exports[`message 1`] = `
156+
"No rules that are unnecessary or conflict with Prettier were found.
157+
"
158+
`;
159+
160+
exports[`success 1`] = `true`;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`fixtures/all-00.js 1`] = `
4+
Object {
5+
"errorCount": 0,
6+
"filePath": "/Users/ide/universe/libraries/eslint-config-expo/__tests__/fixtures/all-00.js",
7+
"fixableErrorCount": 0,
8+
"fixableWarningCount": 0,
9+
"messages": Array [],
10+
"output": "import 'hi';
11+
12+
import a from 'a';
13+
import { b } from 'b';
14+
import c, { c1 } from 'c';
15+
import * as d from 'd';
16+
17+
import e from './e';
18+
19+
@d
20+
export class Example {
21+
static s = {
22+
a,
23+
b,
24+
};
25+
26+
m = {};
27+
28+
hi() {
29+
_fn();
30+
}
31+
32+
async byeAsync() {
33+
_fn(a, b, c, c1, d, e);
34+
}
35+
}
36+
37+
function _fn() {}
38+
",
39+
"warningCount": 0,
40+
}
41+
`;
42+
43+
exports[`message 1`] = `
44+
"No rules that are unnecessary or conflict with Prettier were found.
45+
"
46+
`;
47+
48+
exports[`success 1`] = `true`;

0 commit comments

Comments
 (0)