-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
169 lines (169 loc) · 6.77 KB
/
.eslintrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
module.exports = {
env: {
// window object etc part of browser are made available globally.
browser: true,
es6: true,
commonjs: true,
node: true
},
/*
* The order of extending each plugin matters a LOT!!
* Thus don't change order of items in this array
* unless you're sure of it.
*/
extends: [
"plugin:json/recommended",
"eslint:recommended",
"plugin:react/recommended",
"prettier"
],
settings: {
react: {
version: "detect"
}
},
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly",
// Makes logger function available everywhere. Else eslint will complaint of undef-var.
logger: true,
module: true
},
parserOptions: {
ecmaFeatures: {
jsx: true
},
ecmaVersion: 2018,
sourceType: "module"
},
parser: "babel-eslint",
plugins: ["react", "prettier", "import", "react-hooks"],
rules: {
// auto-fixable: Respect all Prettier rules and apply it.
"prettier/prettier": "error",
// auto-fixable: Indent by 2 spaces. Same as editorconfig and Rubocop config.
indent: ["error", 2, { SwitchCase: 1 }],
// not-auto-fixable: No unused variables allowed.
"no-unused-vars": "error",
// not-auto-fixable: No undefined variables allowed.
"no-undef": "error",
// not-auto-fixable: Dont use console statements. Use logger which babel will remove during bundling.
"no-console": "error",
// not-auto-fixable: require `return` statements to either always or never specify values.
"consistent-return": "error",
// auto-fixable: require or disallow padding lines between statements. Helps maintain blank space after guard clauses etc.
"padding-line-between-statements": [
"error",
{ blankLine: "always", prev: "var", next: "return" }
],
// not-auto-fixable: Prevent missing props validation in a React component definition.
"react/prop-types": "off",
// not-auto-fixable: Detect unescaped HTML entities, which might represent malformed tags.
"react/no-unescaped-entities": "off",
// not-auto-fixable: Prevent missing displayName in a React component definition. Useful when using React extensions in browser and checking for component name.
"react/display-name": "error",
// not-auto-fixable: Reports when this.state is accessed within setState.
"react/no-access-state-in-setstate": "error",
// not-auto-fixable: Prevent usage of dangerous JSX props.
"react/no-danger": "error",
// not-auto-fixable: Report when a DOM element is using both children and dangerouslySetInnerHTML.
"react/no-danger-with-children": "error",
// not-auto-fixable: Prevent definitions of unused prop types.
"react/no-unused-prop-types": "error",
// not-auto-fixable: Report missing key props in iterators/collection literals. Important rule!
"react/jsx-key": "error",
// not-auto-fixable: Enforce no duplicate props.
"react/jsx-no-duplicate-props": "error",
// not-auto-fixable: Disallow undeclared variables in JSX.
"react/jsx-no-undef": "error",
// not-auto-fixable: Enforce PascalCase for user-defined JSX components.
"react/jsx-pascal-case": ["error", { allowNamespace: true }],
// not-auto-fixable: Prevent variables used in JSX to be marked as unused.
"react/jsx-uses-vars": "error",
// not-auto-fixable: Ensures https://reactjs.org/docs/hooks-rules.html.
"react-hooks/rules-of-hooks": "error",
// not-auto-fixable: Ensures https://reactjs.org/docs/hooks-rules.html - Checks effect dependencies.
"react-hooks/exhaustive-deps": "off",
// not-auto-fixable: Prefer a default export if module exports a single name.
"import/prefer-default-export": "off",
// not-auto-fixable: Forbid a module from importing a module with a dependency path back to itself.
"import/no-cycle": ["error", { maxDepth: 1, ignoreExternal: true }],
// not-auto-fixable: Prevent unnecessary path segments in import and require statements.
"import/no-useless-path-segments": ["error", { noUselessIndex: true }],
// not-auto-fixable: Report any invalid exports, i.e. re-export of the same name.
"import/export": "error",
// not-auto-fixable: Forbid the use of mutable exports with var or let.
"import/no-mutable-exports": "error",
// not-auto-fixable: Ensure all imports appear before other statements.
"import/first": "error",
// not-auto-fixable: Ensure all exports appear after other statements.
"import/exports-last": "error",
// auto-fixable: Enforce a newline after import statements.
"import/newline-after-import": ["error", { count: 1 }],
// auto-fixable: Enforce a convention in module import order - we enforce https://www.bigbinary.com/react-best-practices/sort-import-statements
"import/order": [
"error",
{
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
warnOnUnassignedImports: true,
groups: [
"builtin",
"external",
"internal",
"index",
"sibling",
"parent",
"object",
"type"
],
/*
* These are the paths defined in our alias.js file.
* Thus when making change in alias.js, ensure that
* change is reflected over here. All aliases should be
* marked as "internal" group.
* TODO: find a dynamic way to fetch this content
* from the alias.js itself.
* TODO: Also check the possiblity of using "@/" prefix
* to import aliases. This way we can mark all "@/" pattern
* as "internal" group.
*/
pathGroups: [
{ pattern: "apis/**", group: "internal" },
{ pattern: "common/**", group: "internal" },
{ pattern: "components/**", group: "internal" },
{ pattern: "constants/**", group: "internal" },
{ pattern: "contexts/**", group: "internal" },
{ pattern: "reducers/**", group: "internal" },
{ pattern: "neetoui/**", group: "external" },
// react imports should be at the top.
{ pattern: "react+(-native|)", group: "external", position: "before" }
],
// Ignore react imports so that they're always ordered to the top of the file.
pathGroupsExcludedImportTypes: ["react", "react-native"]
}
]
},
// Currently we are using this section for excluding certain files from certain rules.
overrides: [
{
files: [
".eslintrc.js",
".prettierrc.js",
"app/assets/**/*.{js,jsx}",
"app/javascript/packs/**/*.{js,jsx}",
"*.json"
],
rules: {
"import/order": "off",
"react-hooks/rules-of-hooks": "off"
}
},
{
files: ["app/javascript/packs/**/*.{js,jsx}"],
rules: {
"no-redeclare": "off"
}
}
]
};