|
4 | 4 | const { map } = require( 'lodash' );
|
5 | 5 |
|
6 | 6 | module.exports = {
|
7 |
| - parser: "babel-eslint", |
8 |
| - env: { |
9 |
| - browser: true, |
10 |
| - "jest/globals": true |
11 |
| - }, |
12 |
| - globals: { |
13 |
| - __DEV__: true |
14 |
| - }, |
15 |
| - plugins: [ |
16 |
| - "react", |
17 |
| - "react-native", |
18 |
| - "jest", |
19 |
| - "flowtype" |
20 |
| - ], |
21 |
| - extends: [ |
22 |
| - "plugin:@wordpress/eslint-plugin/recommended", |
23 |
| - "plugin:flowtype/recommended", |
24 |
| - ], |
25 |
| - settings: { |
26 |
| - flowtype: { |
27 |
| - onlyFilesWithFlowAnnotation: true, |
28 |
| - }, |
29 |
| - react: { |
30 |
| - pragma: "React", |
31 |
| - version: "16.8.3", |
32 |
| - flowVersion: "0.92.0", |
33 |
| - }, |
34 |
| - }, |
35 |
| - rules: { |
36 |
| - 'no-restricted-syntax': [ |
37 |
| - 'error', |
38 |
| - // NOTE: We can't include the forward slash in our regex or |
39 |
| - // we'll get a `SyntaxError` (Invalid regular expression: \ at end of pattern) |
40 |
| - // here. That's why we use \\u002F in the regexes below. |
41 |
| - { |
42 |
| - selector: 'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]', |
43 |
| - message: 'Path access on WordPress dependencies is not allowed.', |
44 |
| - }, |
45 |
| - { |
46 |
| - selector: 'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]', |
47 |
| - message: 'Use ellipsis character (…) in place of three dots', |
48 |
| - }, |
49 |
| - { |
50 |
| - selector: 'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]', |
51 |
| - message: 'Use memize instead of Lodash’s memoize', |
52 |
| - }, |
53 |
| - { |
54 |
| - selector: 'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]', |
55 |
| - message: 'Prefer page.waitForSelector instead.', |
56 |
| - }, |
57 |
| - { |
58 |
| - selector: 'JSXAttribute[name.name="id"][value.type="Literal"]', |
59 |
| - message: 'Do not use string literals for IDs; use withInstanceId instead.', |
60 |
| - }, |
61 |
| - { |
62 |
| - // Discourage the usage of `Math.random()` as it's a code smell |
63 |
| - // for UUID generation, for which we already have a higher-order |
64 |
| - // component: `withInstanceId`. |
65 |
| - selector: 'CallExpression[callee.object.name="Math"][callee.property.name="random"]', |
66 |
| - message: 'Do not use Math.random() to generate unique IDs; use withInstanceId instead. (If you’re not generating unique IDs: ignore this message.)', |
67 |
| - }, |
68 |
| - { |
69 |
| - selector: 'CallExpression[callee.name="withDispatch"] > :function > BlockStatement > :not(VariableDeclaration,ReturnStatement)', |
70 |
| - message: 'withDispatch must return an object with consistent keys. Avoid performing logic in `mapDispatchToProps`.', |
71 |
| - }, |
72 |
| - ], |
73 |
| - }, |
| 7 | + parser: "babel-eslint", |
| 8 | + env: { |
| 9 | + browser: true, |
| 10 | + "jest/globals": true |
| 11 | + }, |
| 12 | + globals: { |
| 13 | + __DEV__: true |
| 14 | + }, |
| 15 | + plugins: [ |
| 16 | + "react", |
| 17 | + "react-native", |
| 18 | + "jest", |
| 19 | + "flowtype" |
| 20 | + ], |
| 21 | + extends: [ |
| 22 | + "plugin:@wordpress/eslint-plugin/recommended", |
| 23 | + "plugin:flowtype/recommended", |
| 24 | + ], |
| 25 | + settings: { |
| 26 | + flowtype: { |
| 27 | + onlyFilesWithFlowAnnotation: true, |
| 28 | + }, |
| 29 | + react: { |
| 30 | + pragma: "React", |
| 31 | + version: "16.8.3", |
| 32 | + flowVersion: "0.92.0", |
| 33 | + }, |
| 34 | + }, |
| 35 | + rules: { |
| 36 | + 'no-restricted-syntax': [ |
| 37 | + 'error', |
| 38 | + // NOTE: We can't include the forward slash in our regex or |
| 39 | + // we'll get a `SyntaxError` (Invalid regular expression: \ at end of pattern) |
| 40 | + // here. That's why we use \\u002F in the regexes below. |
| 41 | + { |
| 42 | + selector: 'ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]', |
| 43 | + message: 'Path access on WordPress dependencies is not allowed.', |
| 44 | + }, |
| 45 | + { |
| 46 | + selector: 'CallExpression[callee.name=/^(__|_x|_n|_nx)$/] Literal[value=/\\.{3}/]', |
| 47 | + message: 'Use ellipsis character (…) in place of three dots', |
| 48 | + }, |
| 49 | + { |
| 50 | + selector: 'ImportDeclaration[source.value="lodash"] Identifier.imported[name="memoize"]', |
| 51 | + message: 'Use memize instead of Lodash’s memoize', |
| 52 | + }, |
| 53 | + { |
| 54 | + selector: 'CallExpression[callee.object.name="page"][callee.property.name="waitFor"]', |
| 55 | + message: 'Prefer page.waitForSelector instead.', |
| 56 | + }, |
| 57 | + { |
| 58 | + selector: 'JSXAttribute[name.name="id"][value.type="Literal"]', |
| 59 | + message: 'Do not use string literals for IDs; use withInstanceId instead.', |
| 60 | + }, |
| 61 | + { |
| 62 | + // Discourage the usage of `Math.random()` as it's a code smell |
| 63 | + // for UUID generation, for which we already have a higher-order |
| 64 | + // component: `withInstanceId`. |
| 65 | + selector: 'CallExpression[callee.object.name="Math"][callee.property.name="random"]', |
| 66 | + message: 'Do not use Math.random() to generate unique IDs; use withInstanceId instead. (If you’re not generating unique IDs: ignore this message.)', |
| 67 | + }, |
| 68 | + { |
| 69 | + selector: 'CallExpression[callee.name="withDispatch"] > :function > BlockStatement > :not(VariableDeclaration,ReturnStatement)', |
| 70 | + message: 'withDispatch must return an object with consistent keys. Avoid performing logic in `mapDispatchToProps`.', |
| 71 | + }, |
| 72 | + ], |
| 73 | + }, |
74 | 74 | }
|
0 commit comments