@petbee/eslint-config 1.0.1-alpha-1.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,74 +1,28 @@
1
1
  module.exports = {
2
- parser: '@typescript-eslint/parser',
3
2
  parserOptions: {
4
3
  project: 'tsconfig.json',
5
4
  sourceType: 'module',
6
- warnOnUnsupportedTypeScriptVersion: false,
7
5
  },
8
6
  plugins: ['@typescript-eslint/eslint-plugin'],
9
7
  extends: [
10
- 'plugin:@typescript-eslint/eslint-recommended',
11
- 'plugin:@typescript-eslint/recommended',
12
- 'plugin:react/recommended',
13
- 'prettier',
8
+ 'eslint:recommended',
9
+ './rules/prettier.js',
10
+ './rules/errors.js',
11
+ './rules/node.js',
12
+ './rules/style.js',
13
+ './rules/variables.js',
14
+ './rules/best-practices.js',
15
+ './rules/imports.js',
16
+ './rules/typescript.js',
17
+ './rules/tests.js',
14
18
  ],
15
19
  root: true,
16
20
  env: {
17
21
  node: true,
18
22
  jest: true,
23
+ es6: true,
19
24
  },
20
- rules: {
21
- // Don't require a weird naming convention for interfaces
22
- '@typescript-eslint/interface-name-prefix': 'off',
23
-
24
- // Allow inferring types for functions
25
- '@typescript-eslint/explicit-function-return-type': 'off',
26
-
27
- // Allow inferring types for exported things
28
- '@typescript-eslint/explicit-module-boundary-types': 'off',
29
-
30
- // Don't allow "any" at all
31
- '@typescript-eslint/no-explicit-any': 'error',
32
-
33
- // Make sure we are awaiting or explicitly voiding all Promises
34
- '@typescript-eslint/no-floating-promises': 'error',
35
-
36
- // Allow using functions that are defined later in the file (fine thanks to hoisting)
37
- '@typescript-eslint/no-use-before-define': [
38
- 'error',
39
- { functions: false, classes: false, variables: true },
40
- ],
41
-
42
- // This rule makes no difference - ' and " are fine, > and } are already compile errors
43
- 'react/no-unescaped-entities': 'off',
44
-
45
- // Disable validation of prop types, because we use TS instead and it gets confused
46
- 'react/prop-types': 'off',
47
-
48
- // Make sure comments are starting with an uppercase letter, to encourage correct grammar
49
- 'capitalized-comments': [
50
- 'warn',
51
- 'always',
52
- {
53
- ignorePattern: 'prettier|c8',
54
- ignoreConsecutiveComments: true,
55
- },
56
- ],
57
-
58
- // Disable specific syntax features
59
- 'no-restricted-syntax': [
60
- 'error',
61
- // Don't allow TS enums at all, since they have multiple unintuitive footguns
62
- {
63
- selector: 'TSEnumDeclaration',
64
- message:
65
- 'Unexpected enum. Use a literal string union or a const object instead.',
66
- },
67
- ],
68
- },
69
- settings: {
70
- react: {
71
- version: 'detect',
72
- },
25
+ globals: {
26
+ __DEV__: true,
73
27
  },
74
28
  }
package/lib/utils.js ADDED
@@ -0,0 +1,11 @@
1
+ /* eslint-disable node/global-require */
2
+
3
+ exports.hasPackage = (pkg) => {
4
+ try {
5
+ require(pkg)
6
+
7
+ return true
8
+ } catch (e) {
9
+ return false
10
+ }
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@petbee/eslint-config",
3
- "version": "1.0.1-alpha-1.0",
3
+ "version": "1.0.2",
4
4
  "description": "Petbee's eslint config",
5
5
  "keywords": [
6
6
  "eslint",
@@ -11,7 +11,9 @@
11
11
  "license": "MIT",
12
12
  "main": "index.js",
13
13
  "files": [
14
- "index.js"
14
+ "index.js",
15
+ "rules/",
16
+ "lib/"
15
17
  ],
16
18
  "repository": {
17
19
  "type": "git",
@@ -31,17 +33,24 @@
31
33
  "url": "https://github.com/petbee/typescript/issues"
32
34
  },
33
35
  "dependencies": {
34
- "@typescript-eslint/eslint-plugin": "6.10.0",
35
- "@typescript-eslint/parser": "6.10.0",
36
- "eslint-config-prettier": "9.0.0",
36
+ "@typescript-eslint/eslint-plugin": "^6.10.0",
37
+ "@typescript-eslint/parser": "^6.10.0",
38
+ "confusing-browser-globals": "^1.0.11",
39
+ "eslint-config-prettier": "^9.0.0",
40
+ "eslint-plugin-cypress": "^2.15.1",
41
+ "eslint-plugin-import": "^2.29.0",
42
+ "eslint-plugin-jest": "^27.6.0",
43
+ "eslint-plugin-node": "^11.1.0",
44
+ "eslint-plugin-prettier": "^5.0.1",
37
45
  "eslint-plugin-react": "7.33.2"
38
46
  },
39
47
  "peerDependencies": {
40
48
  "eslint": "^8.0.0",
49
+ "prettier": "^2",
41
50
  "typescript": "^4.0.0 || ^5.0.0"
42
51
  },
43
52
  "devDependencies": {
44
- "@petbee/prettier-config": "2.0.2",
53
+ "@petbee/prettier-config": "^1.0.1",
45
54
  "@types/react": "18.2.37",
46
55
  "eslint": "8.53.0",
47
56
  "prettier": "3.0.3",
@@ -51,5 +60,5 @@
51
60
  "publishConfig": {
52
61
  "access": "public"
53
62
  },
54
- "gitHead": "c88132ca3b4e5269d65060a0f49ae7f2cbff9173"
63
+ "gitHead": "3c90a0ee37ac4f15cafa2778c9e132bfbb4b6082"
55
64
  }
@@ -0,0 +1,303 @@
1
+ module.exports = {
2
+ rules: {
3
+ // Enforces return statements in callbacks of array's methods
4
+ // https://eslint.org/docs/rules/array-callback-return
5
+ 'array-callback-return': ['error', { allowImplicit: true }],
6
+
7
+ // Treat var statements as if they were block scoped
8
+ // https://eslint.org/docs/rules/block-scoped-var
9
+ 'block-scoped-var': 'error',
10
+
11
+ // Require default case in switch statements
12
+ // https://eslint.org/docs/rules/default-case
13
+ 'default-case': ['error', { commentPattern: '^no default$' }],
14
+
15
+ // Disallow case statement fallthrough
16
+ // https://eslint.org/docs/rules/no-fallthrough
17
+ 'no-fallthrough': [
18
+ 'error',
19
+ {
20
+ commentPattern: '(break[\\s\\w]*omitted|falls\\s?through)',
21
+ },
22
+ ],
23
+
24
+ // Enforce parameters with default values to be last
25
+ // https://eslint.org/docs/rules/default-param-last
26
+ 'default-param-last': 'error',
27
+
28
+ // Encourages use of dot notation whenever possible
29
+ // https://eslint.org/docs/rules/dot-notation
30
+ 'dot-notation': ['error', { allowKeywords: true }],
31
+
32
+ // Require the use of === and !==
33
+ // https://eslint.org/docs/rules/eqeqeq
34
+ eqeqeq: ['error', 'always', { null: 'ignore' }],
35
+
36
+ // Require grouped accessor pairs in object literals and classes
37
+ // https://eslint.org/docs/rules/grouped-accessor-pairs
38
+ 'grouped-accessor-pairs': 'error',
39
+
40
+ // Enforce a maximum number of classes per file
41
+ // https://eslint.org/docs/rules/max-classes-per-file
42
+ // TODO, maybe turn on
43
+ 'max-classes-per-file': ['off', 1],
44
+
45
+ // Disallow the use of alert, confirm, and prompt
46
+ // https://eslint.org/docs/rules/no-alert
47
+ 'no-alert': 'warn',
48
+
49
+ // Disallow use of arguments.caller or arguments.callee
50
+ // https://eslint.org/docs/rules/no-caller
51
+ 'no-caller': 'error',
52
+
53
+ // Disallow lexical declarations in case/default clauses
54
+ // https://eslint.org/docs/rules/no-case-declarations
55
+ 'no-case-declarations': 'error',
56
+
57
+ // Disallow returning value in constructor
58
+ // https://eslint.org/docs/rules/no-constructor-return
59
+ 'no-constructor-return': 'error',
60
+
61
+ // Disallow else after a return in an if
62
+ // https://eslint.org/docs/rules/no-else-return
63
+ 'no-else-return': ['error', { allowElseIf: false }],
64
+
65
+ // Disallow empty functions, except for standalone funcs/arrows
66
+ // https://eslint.org/docs/rules/no-empty-function
67
+ 'no-empty-function': [
68
+ 'error',
69
+ {
70
+ allow: ['arrowFunctions', 'functions', 'methods'],
71
+ },
72
+ ],
73
+
74
+ // Disallow use of eval()
75
+ // https://eslint.org/docs/rules/no-eval
76
+ 'no-eval': 'error',
77
+
78
+ // Disallow adding to native types
79
+ // https://eslint.org/docs/rules/no-extend-native
80
+ 'no-extend-native': 'error',
81
+
82
+ // Disallow unnecessary function binding
83
+ // https://eslint.org/docs/rules/no-extra-bind
84
+ 'no-extra-bind': 'error',
85
+
86
+ // Disallow Unnecessary Labels
87
+ // https://eslint.org/docs/rules/no-extra-label
88
+ 'no-extra-label': 'error',
89
+
90
+ // Disallow the use of leading or trailing decimal points in numeric literals
91
+ // https://eslint.org/docs/rules/no-floating-decimal
92
+ // Disabled because prettier already handle this rule
93
+ 'no-floating-decimal': 'off',
94
+
95
+ // Disallow reassignments of native objects or read-only globals
96
+ // https://eslint.org/docs/rules/no-global-assign
97
+ 'no-global-assign': 'error',
98
+
99
+ // Disallow use of eval()-like methods
100
+ // https://eslint.org/docs/rules/no-implied-eval
101
+ 'no-implied-eval': 'error',
102
+
103
+ // Disallow usage of __iterator__ property
104
+ // https://eslint.org/docs/rules/no-iterator
105
+ 'no-iterator': 'error',
106
+
107
+ // Disallow use of labels for anything other then loops and switches
108
+ // https://eslint.org/docs/rules/no-labels
109
+ 'no-labels': 'error',
110
+
111
+ // Disallow unnecessary nested blocks
112
+ // https://eslint.org/docs/rules/no-lone-blocks
113
+ 'no-lone-blocks': 'error',
114
+
115
+ // Disallow creation of functions within loops
116
+ // https://eslint.org/docs/rules/no-loop-func
117
+ 'no-loop-func': 'error',
118
+
119
+ // Disallow magic numbers
120
+ // https://eslint.org/docs/rules/no-magic-numbers
121
+ // TODO enable? maybe too much
122
+ 'no-magic-numbers': [
123
+ 'off',
124
+ {
125
+ ignore: [0, 1, 2, 3],
126
+ ignoreArrayIndexes: true,
127
+ enforceConst: true,
128
+ detectObjects: false,
129
+ },
130
+ ],
131
+
132
+ // Disallow use of multiline strings
133
+ // https://eslint.org/docs/rules/no-multi-str
134
+ 'no-multi-str': 'error',
135
+
136
+ // Disallow use of new operator for Function object
137
+ // https://eslint.org/docs/rules/no-new-func
138
+ 'no-new-func': 'error',
139
+
140
+ // Disallows creating new instances of String, Number, and Boolean
141
+ // https://eslint.org/docs/rules/no-new-wrappers
142
+ 'no-new-wrappers': 'error',
143
+
144
+ // Disallow use of octal escape sequences in string literals, such as
145
+ // var foo = 'Copyright \251';
146
+ // https://eslint.org/docs/rules/no-octal-escape
147
+ 'no-octal-escape': 'error',
148
+
149
+ // Disallow usage of __proto__ property
150
+ // https://eslint.org/docs/rules/no-proto
151
+ 'no-proto': 'error',
152
+
153
+ // Disallow declaring the same variable more then once
154
+ // https://eslint.org/docs/rules/no-redeclare
155
+ 'no-redeclare': 'error',
156
+
157
+ // Disallow use of assignment in return statement
158
+ // https://eslint.org/docs/rules/no-return-assign
159
+ 'no-return-assign': ['error', 'except-parens'],
160
+
161
+ // Disallow redundant `return await`
162
+ // https://eslint.org/docs/rules/no-return-await
163
+ 'no-return-await': 'error',
164
+
165
+ // Disallow use of `javascript:` urls.
166
+ // https://eslint.org/docs/rules/no-script-url
167
+ 'no-script-url': 'error',
168
+
169
+ // Disallow comparisons where both sides are exactly the same
170
+ // https://eslint.org/docs/rules/no-self-compare
171
+ 'no-self-compare': 'error',
172
+
173
+ // Disallow use of comma operator
174
+ // https://eslint.org/docs/rules/no-sequences
175
+ 'no-sequences': 'error',
176
+
177
+ // Disallow unused labels
178
+ // https://eslint.org/docs/rules/no-unused-labels
179
+ 'no-unused-labels': 'error',
180
+
181
+ // Disallow unnecessary catch clauses
182
+ // https://eslint.org/docs/rules/no-useless-catch
183
+ // TODO enable?
184
+ 'no-useless-catch': 'off',
185
+
186
+ // Disallow unnecessary string escaping
187
+ // https://eslint.org/docs/rules/no-useless-escape
188
+ 'no-useless-escape': 'error',
189
+
190
+ // Disallow redundant return; keywords
191
+ // https://eslint.org/docs/rules/no-useless-return
192
+ 'no-useless-return': 'error',
193
+
194
+ // Disallow use of void operator
195
+ // https://eslint.org/docs/rules/no-void
196
+ 'no-void': 'error',
197
+
198
+ // Prefer using regex literals instead of constructor
199
+ // https://eslint.org/docs/rules/prefer-regex-literals
200
+ 'prefer-regex-literals': 'warn',
201
+
202
+ // Require use of the second argument for parseInt()
203
+ // https://eslint.org/docs/rules/radix
204
+ radix: 'error',
205
+
206
+ // Requires to declare all vars on top of their containing scope
207
+ // https://eslint.org/docs/rules/vars-on-top
208
+ 'vars-on-top': 'error',
209
+ // https://eslint.org/docs/rules/constructor-super
210
+ 'constructor-super': 'error',
211
+
212
+ // Disallow useless computed property keys
213
+ // https://eslint.org/docs/rules/no-useless-computed-key
214
+ 'no-useless-computed-key': 'error',
215
+
216
+ // Disallow unnecessary constructor
217
+ // https://eslint.org/docs/rules/no-useless-constructor
218
+ 'no-useless-constructor': 'error',
219
+
220
+ // Disallow renaming import, export, and destructured assignments to the same name
221
+ // https://eslint.org/docs/rules/no-useless-rename
222
+ 'no-useless-rename': ['error'],
223
+
224
+ // Require let or const instead of var
225
+ // https://eslint.org/docs/rules/no-var
226
+ 'no-var': 'error',
227
+
228
+ // Require method and property shorthand syntax for object literals
229
+ // https://eslint.org/docs/rules/object-shorthand
230
+ 'object-shorthand': [
231
+ 'error',
232
+ 'always',
233
+ {
234
+ ignoreConstructors: false,
235
+ avoidQuotes: true,
236
+ },
237
+ ],
238
+
239
+ // Suggest using arrow functions as callbacks
240
+ // https://eslint.org/docs/rules/prefer-arrow-callback
241
+ // TODO discussion
242
+ 'prefer-arrow-callback': [
243
+ 'off',
244
+ {
245
+ allowNamedFunctions: false,
246
+ allowUnboundThis: true,
247
+ },
248
+ ],
249
+
250
+ // Suggest using of const declaration for variables that are never modified after declared
251
+ // https://eslint.org/docs/rules/prefer-const
252
+ 'prefer-const': [
253
+ 'error',
254
+ {
255
+ destructuring: 'all',
256
+ ignoreReadBeforeAssign: true,
257
+ },
258
+ ],
259
+
260
+ // Prefer destructuring from arrays and objects
261
+ // https://eslint.org/docs/rules/prefer-destructuring
262
+ 'prefer-destructuring': [
263
+ 'warn',
264
+ {
265
+ VariableDeclarator: {
266
+ array: true,
267
+ object: true,
268
+ },
269
+ AssignmentExpression: {
270
+ array: false,
271
+ object: false,
272
+ },
273
+ },
274
+ {
275
+ enforceForRenamedProperties: false,
276
+ },
277
+ ],
278
+
279
+ // Disallow parseInt() in favor of binary, octal, and hexadecimal literals
280
+ // https://eslint.org/docs/rules/prefer-numeric-literals
281
+ 'prefer-numeric-literals': 'error',
282
+
283
+ // Use rest parameters instead of arguments
284
+ // https://eslint.org/docs/rules/prefer-rest-params
285
+ 'prefer-rest-params': 'error',
286
+
287
+ // Suggest using the spread operator instead of .apply()
288
+ // https://eslint.org/docs/rules/prefer-spread
289
+ 'prefer-spread': 'error',
290
+
291
+ // Suggest using template literals instead of string concatenation
292
+ // https://eslint.org/docs/rules/prefer-template
293
+ 'prefer-template': 'warn',
294
+
295
+ // Disallow generator functions that do not have yield
296
+ // https://eslint.org/docs/rules/require-yield
297
+ 'require-yield': 'error',
298
+
299
+ // Require a Symbol description
300
+ // https://eslint.org/docs/rules/symbol-description
301
+ 'symbol-description': 'error',
302
+ },
303
+ }
@@ -0,0 +1,41 @@
1
+ module.exports = {
2
+ // only rules not included in 'eslint:recommended' or with different values
3
+ rules: {
4
+ // Enforces that a return statement is present in property getters
5
+ // https://eslint.org/docs/rules/getter-return
6
+ 'getter-return': ['error', { allowImplicit: true }],
7
+
8
+ // Disallow await inside of loops
9
+ // https://eslint.org/docs/rules/no-await-in-loop
10
+ 'no-await-in-loop': 'error',
11
+
12
+ // Disallow assignment in conditional expressions
13
+ // https://eslint.org/docs/rules/no-cond-assign
14
+ 'no-cond-assign': ['error', 'except-parens'],
15
+
16
+ // Disallow use of console
17
+ // https://eslint.org/docs/rules/no-console
18
+ 'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
19
+
20
+ // Disallow template literal placeholder syntax in regular strings
21
+ // https://eslint.org/docs/rules/no-template-curly-in-string
22
+ 'no-template-curly-in-string': 'error',
23
+
24
+ // Disallow assignments that can lead to race conditions due to usage of await or yield
25
+ // https://eslint.org/docs/rules/require-atomic-updates
26
+ 'require-atomic-updates': 'warn',
27
+
28
+ //! Require eslint >= 6.7.0
29
+
30
+ // Disallow duplicate conditions in if-else-if chains
31
+ // https://eslint.org/docs/rules/no-dupe-else-if
32
+ 'no-dupe-else-if': 'error',
33
+
34
+ // https://eslint.org/docs/rules/no-import-assign
35
+ 'no-import-assign': 'error',
36
+
37
+ // Disallow returning values from setters
38
+ // https://eslint.org/docs/rules/no-setter-return
39
+ 'no-setter-return': 'error',
40
+ },
41
+ }
@@ -0,0 +1,54 @@
1
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules
2
+ module.exports = {
3
+ extends: ['plugin:import/typescript'],
4
+ plugins: ['import'],
5
+ rules: {
6
+ // Disallow non-import statements appearing before import statements
7
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/first.md
8
+ 'import/first': 'error',
9
+
10
+ // Disallow duplicate imports
11
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-duplicates.md
12
+ 'import/no-duplicates': 'error',
13
+
14
+ // Ensure native, external and internal imports are separated, above relative imports and that unassigned imports are ignored
15
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md
16
+ 'import/order': [
17
+ 'error',
18
+ {
19
+ 'newlines-between': 'always',
20
+ groups: [
21
+ 'builtin',
22
+ 'external',
23
+ 'internal',
24
+ ['parent', 'sibling', 'index'],
25
+ 'type',
26
+ ],
27
+ },
28
+ ],
29
+
30
+ // Require a newline after the last import/require in a group
31
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/newline-after-import.md
32
+ 'import/newline-after-import': 'error',
33
+
34
+ // Forbid import of modules using absolute paths
35
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-absolute-path.md
36
+ 'import/no-absolute-path': 'error',
37
+
38
+ // Forbid mutable exports
39
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-mutable-exports.md
40
+ 'import/no-mutable-exports': 'error',
41
+
42
+ // Disallow invalid exports, e.g. multiple defaults
43
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/export.md
44
+ 'import/export': 'error',
45
+
46
+ // Ensures that there are no useless path segments
47
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-useless-path-segments.md
48
+ 'import/no-useless-path-segments': ['error', { commonjs: true }],
49
+
50
+ // Forbid a module from importing itself
51
+ // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-self-import.md
52
+ 'import/no-self-import': 'error',
53
+ },
54
+ }
package/rules/node.js ADDED
@@ -0,0 +1,42 @@
1
+ module.exports = {
2
+ plugins: ['node'],
3
+ env: {
4
+ node: true,
5
+ },
6
+ rules: {
7
+ // Disallow use of process.env
8
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-process-env.md
9
+ 'node/no-process-env': 'off',
10
+
11
+ // Enforce a callback to return
12
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/callback-return.md
13
+ //! too annoying
14
+ 'node/callback-return': 'off',
15
+
16
+ // Require all requires be top-level
17
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/global-require.md
18
+ 'node/global-require': 'error',
19
+
20
+ // Disallow use of new operator with the require function
21
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-new-require.md
22
+ 'node/no-new-require': 'error',
23
+
24
+ // Disallow string concatenation with __dirname and __filename
25
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-path-concat.md
26
+ 'node/no-path-concat': 'error',
27
+
28
+ // Make process.exit() expressions the same code path as throw
29
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/process-exit-as-throw.md
30
+ 'node/process-exit-as-throw': 'error',
31
+
32
+ // Disallow deprecated APIs
33
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-deprecated-api.md
34
+ 'node/no-deprecated-api': 'error',
35
+
36
+ // Encourages use of promise APIs instead o callback APIs
37
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/prefer-promises/fs.md
38
+ // https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/prefer-promises/dns.md
39
+ 'node/prefer-promises/fs': 'warn',
40
+ 'node/prefer-promises/dns': 'warn',
41
+ },
42
+ }
@@ -0,0 +1,8 @@
1
+ // https://github.com/prettier/eslint-plugin-prettier
2
+ module.exports = {
3
+ extends: ['plugin:prettier/recommended'],
4
+ plugins: ['prettier'],
5
+ rules: {
6
+ 'prettier/prettier': 'error',
7
+ },
8
+ }
package/rules/style.js ADDED
@@ -0,0 +1,205 @@
1
+ module.exports = {
2
+ rules: {
3
+ // Allow brace-less single-line if, else if, else, for, while, or do, while still enforcing the use of curly braces for other instances.
4
+ // https://eslint.org/docs/rules/curly
5
+ // Disabled because conflicts with prettier
6
+ // https://github.com/prettier/eslint-config-prettier#curly
7
+ curly: 'off',
8
+
9
+ // Require camel case names
10
+ // https://eslint.org/docs/rules/camelcase
11
+ camelcase: [
12
+ 'error',
13
+ {
14
+ properties: 'never',
15
+ ignoreDestructuring: false,
16
+ },
17
+ ],
18
+
19
+ // Require function expressions to have a name
20
+ // https://eslint.org/docs/rules/func-names
21
+ 'func-names': 'warn',
22
+
23
+ // Enforce position of line comments
24
+ // https://eslint.org/docs/rules/line-comment-position
25
+ 'line-comment-position': [
26
+ 'off',
27
+ {
28
+ position: 'above',
29
+ applyDefaultPatterns: true,
30
+ },
31
+ ],
32
+
33
+ // Disallow comments inline after code
34
+ // https://eslint.org/docs/rules/no-inline-comments
35
+ 'no-inline-comments': 'off',
36
+
37
+ // Require or disallow newlines around directives
38
+ // https://eslint.org/docs/rules/lines-around-directive
39
+ 'lines-around-directive': [
40
+ 'error',
41
+ {
42
+ before: 'always',
43
+ after: 'always',
44
+ },
45
+ ],
46
+
47
+ // Limit the number of parameters that can be used in the function declaration.
48
+ // https://eslint.org/docs/rules/max-params
49
+ 'max-params': [
50
+ 'warn',
51
+ {
52
+ max: 3,
53
+ },
54
+ ],
55
+
56
+ // Require a capital letter for constructors
57
+ // https://eslint.org/docs/rules/new-cap
58
+ 'new-cap': [
59
+ 'error',
60
+ {
61
+ newIsCap: true,
62
+ capIsNew: false,
63
+ },
64
+ ],
65
+
66
+ // Disallow use of the Array constructor
67
+ // https://eslint.org/docs/rules/no-array-constructor
68
+ 'no-array-constructor': 'error',
69
+
70
+ // Disallow if as the only statement in an else block
71
+ // https://eslint.org/docs/rules/no-lonely-if
72
+ 'no-lonely-if': 'error',
73
+
74
+ // Disallow use of chained assignment expressions
75
+ // https://eslint.org/docs/rules/no-multi-assign
76
+ 'no-multi-assign': 'error',
77
+
78
+ // Disallow negated conditions
79
+ // https://eslint.org/docs/rules/no-negated-condition
80
+ 'no-negated-condition': 'warn',
81
+
82
+ // Disallow use of the Object constructor
83
+ // https://eslint.org/docs/rules/no-new-object
84
+ 'no-new-object': 'error',
85
+
86
+ // Disallow certain syntax forms
87
+ // https://eslint.org/docs/rules/no-restricted-syntax
88
+ 'no-restricted-syntax': [
89
+ 'error',
90
+ {
91
+ selector: 'LabeledStatement',
92
+ message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
93
+ },
94
+ {
95
+ selector: 'WithStatement',
96
+ message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
97
+ },
98
+ // ban all enums
99
+ {
100
+ selector: 'TSEnumDeclaration:not([const=true])',
101
+ message:
102
+ "Literal types and enums, in many cases, solve the same problem while enum has some trade-offs that usually literal types don't. Consider using a literal type instead.",
103
+ },
104
+ ],
105
+
106
+ // Disallow the use of Boolean literals in conditional expressions
107
+ // Also, prefer `a || b` over `a ? a : b`
108
+ // https://eslint.org/docs/rules/no-unneeded-ternary
109
+ 'no-unneeded-ternary': ['error', { defaultAssignment: false }],
110
+
111
+ // Allow just one var statement per function
112
+ // https://eslint.org/docs/rules/one-var
113
+ 'one-var': ['error', 'never'],
114
+
115
+ // Require assignment operator shorthand where possible or prohibit it entirely
116
+ // https://eslint.org/docs/rules/operator-assignment
117
+ 'operator-assignment': ['error', 'always'],
118
+
119
+ // Prefer use of an object spread over Object.assign
120
+ // https://eslint.org/docs/rules/prefer-object-spread
121
+ 'prefer-object-spread': 'error',
122
+
123
+ // Require or disallow a space immediately following the // or /* in a comment
124
+ // https://eslint.org/docs/rules/spaced-comment
125
+ 'spaced-comment': [
126
+ 'error',
127
+ 'always',
128
+ {
129
+ line: {
130
+ exceptions: ['-', '+'],
131
+ markers: ['-', '+', '?', '!'],
132
+ },
133
+ block: {
134
+ exceptions: ['-', '+'],
135
+ markers: ['-', '+', '?', '!'],
136
+ balanced: true,
137
+ },
138
+ },
139
+ ],
140
+
141
+ // Require or disallow padding lines between statements
142
+ // https://eslint.org/docs/rules/padding-line-between-statements
143
+ 'padding-line-between-statements': [
144
+ 'warn',
145
+ // empty lines after declarations
146
+ {
147
+ blankLine: 'always',
148
+ prev: ['const', 'let', 'var'],
149
+ next: '*',
150
+ },
151
+ // allow to have none or one blank line between declarations
152
+ {
153
+ blankLine: 'any',
154
+ prev: ['const', 'let', 'var'],
155
+ next: ['const', 'let', 'var'],
156
+ },
157
+ // enforce blank lines after multiline declarations
158
+ {
159
+ blankLine: 'always',
160
+ prev: ['multiline-const', 'multiline-let', 'multiline-var'],
161
+ next: '*',
162
+ },
163
+ // empty lines before returns
164
+ {
165
+ blankLine: 'always',
166
+ prev: '*',
167
+ next: 'return',
168
+ },
169
+ // empty lines between switch cases and breaks
170
+ {
171
+ blankLine: 'always',
172
+ prev: ['case', 'break'],
173
+ next: ['case', 'break', 'default'],
174
+ },
175
+ // always require blankline after function, class declarations and multiline blocks (if, try-catch, etc)
176
+ {
177
+ blankLine: 'always',
178
+ prev: ['function', 'class', 'multiline-block-like'],
179
+ next: '*',
180
+ },
181
+ // import/order already handle padding lines between cjs-imports
182
+ {
183
+ blankLine: 'any',
184
+ prev: ['cjs-import'],
185
+ next: ['cjs-import'],
186
+ },
187
+ ],
188
+
189
+ // Require or disallow padding lines between class members
190
+ // https://eslint.org/docs/rules/lines-between-class-members
191
+ 'lines-between-class-members': [
192
+ 'error',
193
+ 'always',
194
+ {
195
+ exceptAfterSingleLine: true,
196
+ },
197
+ ],
198
+
199
+ //! Require eslint >= 6.7.0
200
+
201
+ // Disallow the use of Math.pow in favor of the ** operator
202
+ // https://eslint.org/docs/rules/prefer-exponentiation-operator
203
+ 'prefer-exponentiation-operator': 'error',
204
+ },
205
+ }
package/rules/tests.js ADDED
@@ -0,0 +1,78 @@
1
+ // Jest:
2
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules
3
+ // Cypress: https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules
4
+ const { hasPackage } = require('../lib/utils')
5
+
6
+ const hasJest = hasPackage('jest')
7
+
8
+ module.exports = {
9
+ overrides: [
10
+ // ! CYPRESS
11
+ {
12
+ files: ['**/cypress/**/*.{ts,tsx,js,jsx}'],
13
+ extends: ['plugin:cypress/recommended'],
14
+ rules: {
15
+ // Enforce assertions before taking a screenshot
16
+ // https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/assertion-before-screenshot.md
17
+ 'cypress/assertion-before-screenshot': 'warn',
18
+ },
19
+ },
20
+ // ! JEST
21
+ {
22
+ // Run through every test file found
23
+ files: ['*.{test,spec}.{ts,tsx,js,jsx}'],
24
+ // Unless it's inside a cypress directory
25
+ excludedFiles: ['**/cypress/**'],
26
+ extends: ['plugin:jest/recommended', 'plugin:jest/style'],
27
+ settings: {
28
+ // need to explicitly set this for the IO apps.
29
+ // we need to explicitly define jest version because IO apps
30
+ // have jest installed in a subdirectory.
31
+ jest: {
32
+ ...(hasJest === false && {
33
+ version: 26,
34
+ }),
35
+ },
36
+ },
37
+ rules: {
38
+ // Enforce consistent a test method name
39
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/consistent-test-it.md
40
+ 'jest/consistent-test-it': [
41
+ 'warn',
42
+ {
43
+ fn: 'test',
44
+ withinDescribe: 'it',
45
+ },
46
+ ],
47
+
48
+ // Disallow alias methods
49
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-alias-methods.md
50
+ 'jest/no-alias-methods': 'error',
51
+
52
+ // Disallow duplicate setup/teardown hooks
53
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-duplicate-hooks.md
54
+ 'jest/no-duplicate-hooks': 'error',
55
+
56
+ // Suggest to have all hooks at top-level before tests
57
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-hooks-on-top.md
58
+ 'jest/prefer-hooks-on-top': 'error',
59
+
60
+ // Suggest jest.spyOn() instead of jest.fn()
61
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-spy-on.md
62
+ 'jest/prefer-spy-on': 'warn',
63
+
64
+ // Suggest using test.todo()
65
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/prefer-todo.md
66
+ 'jest/prefer-todo': 'warn',
67
+
68
+ // Disallow return statements from tests
69
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-test-return-statement.md
70
+ 'jest/no-test-return-statement': 'warn',
71
+
72
+ // Disallow deprecated jest functions
73
+ // https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-deprecated-functions.md
74
+ 'jest/no-deprecated-functions': 'error',
75
+ },
76
+ },
77
+ ],
78
+ }
@@ -0,0 +1,286 @@
1
+ const { hasPackage } = require('../lib/utils')
2
+
3
+ const hasTypescript = hasPackage('typescript')
4
+
5
+ module.exports = !hasTypescript
6
+ ? {}
7
+ : {
8
+ overrides: [
9
+ {
10
+ files: ['*.ts', '*.tsx'],
11
+ extends: ['plugin:@typescript-eslint/eslint-recommended', 'plugin:@typescript-eslint/recommended'],
12
+ plugins: ['@typescript-eslint'],
13
+ parser: '@typescript-eslint/parser',
14
+ parserOptions: {
15
+ ecmaVersion: 2019,
16
+ sourceType: 'module',
17
+ project: [
18
+ // look in the root
19
+ 'tsconfig{.eslint.json,.json}',
20
+ // look in dirs like node/react
21
+ '*/tsconfig{.eslint.json,.json}',
22
+ // look in dirs like packages/package/*
23
+ '*/*/tsconfig{.eslint.json,.json}',
24
+ ],
25
+ projectFolderIgnoreList: [/node_modules/i],
26
+ // We need this configuration to avoid performance issues in monorepos
27
+ // https://github.com/typescript-eslint/typescript-eslint/issues/1192#issuecomment-862414778
28
+ allowAutomaticSingleRunInference: true,
29
+ },
30
+ rules: {
31
+ //! extensions of native eslint rules
32
+ //! when modifying a rule here, make sure to modify the native one and vice-versa
33
+
34
+ // Don't require a weird naming convention for interfaces
35
+ '@typescript-eslint/interface-name-prefix': 'off',
36
+
37
+ // Disallow declaration of variables already declared in the outer scope
38
+ // https://eslint.org/docs/rules/no-shadow
39
+ 'no-shadow': 'off',
40
+ '@typescript-eslint/no-shadow': [
41
+ 'error',
42
+ {
43
+ allow: ['done', 'next', 'resolve', 'reject', 'cb'],
44
+ },
45
+ ],
46
+
47
+ // Prevent unused declared variables
48
+ // https://typescript-eslint.io/rules/no-unused-vars/
49
+ 'no-unused-vars': 'off',
50
+ '@typescript-eslint/no-unused-vars': [
51
+ 'warn',
52
+ {
53
+ ignoreRestSiblings: true,
54
+ argsIgnorePattern: '_+',
55
+ },
56
+ ],
57
+
58
+ // Disallows the use of eval()-like methods
59
+ // https://typescript-eslint.io/rules/no-magic-numbers/
60
+ 'no-magic-numbers': 'off',
61
+ '@typescript-eslint/no-magic-numbers': [
62
+ 'off',
63
+ {
64
+ ignore: [0, 1, 2, 3],
65
+ ignoreArrayIndexes: true,
66
+ enforceConst: true,
67
+ detectObjects: false,
68
+ ignoreNumericLiteralTypes: true,
69
+ ignoreEnums: true,
70
+ },
71
+ ],
72
+
73
+ // Enforce parameters with default values to be last
74
+ // https://typescript-eslint.io/rules/default-param-last/
75
+ 'default-param-last': 'off',
76
+ '@typescript-eslint/default-param-last': 'error',
77
+
78
+ // Disallow useless constructors
79
+ // https://typescript-eslint.io/rules/no-useless-constructor/
80
+ 'no-useless-constructor': 'off',
81
+ '@typescript-eslint/no-useless-constructor': 'error',
82
+
83
+ // Disallow empty functions, except for standalone funcs/arrows
84
+ // https://eslint.org/docs/rules/no-empty-function
85
+ 'no-empty-function': 'off',
86
+ '@typescript-eslint/no-empty-function': [
87
+ 'error',
88
+ {
89
+ allow: ['arrowFunctions', 'functions', 'methods'],
90
+ },
91
+ ],
92
+
93
+ // Require a consistent naming convention
94
+ // https://typescript-eslint.io/rules/naming-convention/
95
+ camelcase: 'off',
96
+ '@typescript-eslint/naming-convention': [
97
+ 'error',
98
+ {
99
+ selector: 'default',
100
+ format: ['camelCase'],
101
+ leadingUnderscore: 'allow',
102
+ trailingUnderscore: 'allow',
103
+ },
104
+ {
105
+ selector: 'variable',
106
+ format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
107
+ leadingUnderscore: 'allow',
108
+ trailingUnderscore: 'allow',
109
+ },
110
+ {
111
+ selector: 'function',
112
+ format: ['camelCase', 'PascalCase'],
113
+ },
114
+ {
115
+ selector: 'typeLike',
116
+ format: ['PascalCase'],
117
+ },
118
+ {
119
+ selector: 'memberLike',
120
+ format: null,
121
+ },
122
+ {
123
+ // have to leave this for now as this rule
124
+ // doesn't separate regular parameters from
125
+ // destructured parameters
126
+ selector: 'parameter',
127
+ format: null,
128
+ },
129
+ ],
130
+
131
+ // Disallow use of variables before they are defined
132
+ // https://typescript-eslint.io/rules/no-use-before-define/
133
+ 'no-use-before-define': 'off',
134
+ '@typescript-eslint/no-use-before-define': [
135
+ 'error',
136
+ {
137
+ functions: false,
138
+ classes: false,
139
+ variables: true,
140
+ enums: false,
141
+ typedefs: false,
142
+ },
143
+ ],
144
+ // ! ts only rules
145
+ // Enforce explicit accessibility modifiers on class properties and methods
146
+ // https://typescript-eslint.io/rules/explicit-member-accessibility/
147
+ '@typescript-eslint/explicit-member-accessibility': [
148
+ 'error',
149
+ {
150
+ accessibility: 'explicit',
151
+ overrides: {
152
+ accessors: 'explicit',
153
+ constructors: 'no-public',
154
+ methods: 'explicit',
155
+ parameterProperties: 'explicit',
156
+ },
157
+ },
158
+ ],
159
+
160
+ // Don't allow "any" at all
161
+ // https://typescript-eslint.io/rules/no-explicit-any
162
+ '@typescript-eslint/no-explicit-any': 'error',
163
+
164
+ // Enforce explicit function return type
165
+ // https://typescript-eslint.io/rules/explicit-function-return-type/
166
+ '@typescript-eslint/explicit-function-return-type': 'off',
167
+
168
+ // Enforce a consistent way of typing arrays
169
+ // https://typescript-eslint.io/rules/array-type/v
170
+ '@typescript-eslint/array-type': [
171
+ 'warn',
172
+ {
173
+ default: 'array-simple',
174
+ readonly: 'array-simple',
175
+ },
176
+ ],
177
+
178
+ // Enforce a consitent way to type objects
179
+ // https://typescript-eslint.io/rules/consistent-type-definitions/
180
+ '@typescript-eslint/consistent-type-definitions': 'off',
181
+
182
+ // Disallow non null assertions (!), comes from the recommended config
183
+ // https://typescript-eslint.io/rules/no-non-null-assertion/
184
+ '@typescript-eslint/no-non-null-assertion': 'warn',
185
+
186
+ // Enforce that when adding two variables, operands must both be of type number or of type string
187
+ // https://typescript-eslint.io/rules/restrict-plus-operands/
188
+ '@typescript-eslint/restrict-plus-operands': [
189
+ 'error',
190
+ {
191
+ skipCompoundAssignments: true,
192
+ },
193
+ ],
194
+
195
+ // Enforce optional chaining over chaining AND (&&) operators
196
+ // https://typescript-eslint.io/rules/prefer-optional-chain/
197
+ '@typescript-eslint/prefer-optional-chain': 'warn',
198
+
199
+ // Enforce optional chaining over chaining AND (&&) operators
200
+ // https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain/
201
+ '@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
202
+
203
+ // Enforce nullish coalescing over short-circuiting
204
+ // https://typescript-eslint.io/rules/prefer-nullish-coalescing/
205
+ '@typescript-eslint/prefer-nullish-coalescing': [
206
+ 'warn',
207
+ {
208
+ ignoreConditionalTests: true,
209
+ ignoreMixedLogicalExpressions: true,
210
+ },
211
+ ],
212
+
213
+ // Prefer usage of as const over literal type
214
+ // https://typescript-eslint.io/rules/prefer-as-const/
215
+ '@typescript-eslint/prefer-as-const': 'error',
216
+
217
+ // Prevent unnecessary type arguments
218
+ // https://typescript-eslint.io/rules/no-unnecessary-type-arguments/
219
+ '@typescript-eslint/no-unnecessary-type-arguments': 'warn',
220
+
221
+ // Warns when a namespace qualifier is unnecessary
222
+ // https://typescript-eslint.io/rules/no-unnecessary-qualifier/
223
+ '@typescript-eslint/no-unnecessary-qualifier': 'warn',
224
+
225
+ // Disallow throwing literals as exceptions
226
+ // https://typescript-eslint.io/rules/no-throw-literal/
227
+ '@typescript-eslint/no-throw-literal': 'warn',
228
+
229
+ // Disallows invocation of require() in favor of import statements
230
+ // https://typescript-eslint.io/rules/no-require-imports/
231
+ '@typescript-eslint/no-require-imports': 'warn',
232
+
233
+ // Disallows the use of eval()-like methods
234
+ // https://typescript-eslint.io/rules/no-implied-eval/
235
+ '@typescript-eslint/no-implied-eval': 'error',
236
+
237
+ // Requires Array#sort calls to always provide a compareFunction
238
+ // https://typescript-eslint.io/rules/require-array-sort-compare/
239
+ '@typescript-eslint/require-array-sort-compare': 'error',
240
+
241
+ // Enforce explicit enum item values
242
+ // https://typescript-eslint.io/rules/prefer-enum-initializers/
243
+ '@typescript-eslint/prefer-enum-initializers': 'warn',
244
+
245
+ // Explicitly defines what a module scoped method returns
246
+ // https://typescript-eslint.io/rules/explicit-module-boundary-types/
247
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
248
+
249
+ // Disallow // @ts comments
250
+ // https://typescript-eslint.io/rules/ban-ts-comment/
251
+ '@typescript-eslint/ban-ts-comment': [
252
+ 'error',
253
+ {
254
+ 'ts-expect-error': 'allow-with-description',
255
+ 'ts-ignore': true,
256
+ 'ts-nocheck': true,
257
+ 'ts-check': false,
258
+ minimumDescriptionLength: 3,
259
+ },
260
+ ],
261
+
262
+ // Disallows unnecessary constraints on generic types
263
+ // https://typescript-eslint.io/rules/no-unnecessary-type-constraint/
264
+ '@typescript-eslint/no-unnecessary-type-constraint': 'warn',
265
+
266
+ // Enforces consistent usage of type imports
267
+ // https://typescript-eslint.io/rules/consistent-type-imports/
268
+ '@typescript-eslint/consistent-type-imports': [
269
+ 'warn',
270
+ {
271
+ prefer: 'type-imports',
272
+ disallowTypeAnnotations: false,
273
+ },
274
+ ],
275
+ },
276
+ },
277
+ {
278
+ files: ['*.d.ts'],
279
+ rules: {
280
+ 'import/order': 'off',
281
+ 'import/no-duplicates': 'off',
282
+ 'import/export': 'off',
283
+ },
284
+ },
285
+ ],
286
+ }
@@ -0,0 +1,53 @@
1
+ const confusingBrowserGlobals = require('confusing-browser-globals')
2
+
3
+ module.exports = {
4
+ rules: {
5
+ // Disallow labels that share a name with a variable
6
+ // https://eslint.org/docs/rules/no-label-var
7
+ 'no-label-var': 'error',
8
+
9
+ // Disallow specific globals
10
+ // https://eslint.org/docs/rules/no-restricted-globals
11
+ 'no-restricted-globals': ['error', 'isFinite', 'isNaN'].concat(
12
+ confusingBrowserGlobals
13
+ ),
14
+
15
+ // Disallow declaration of variables already declared in the outer scope
16
+ // https://eslint.org/docs/rules/no-shadow
17
+ 'no-shadow': [
18
+ 'error',
19
+ {
20
+ allow: ['done', 'next', 'resolve', 'reject', 'cb'],
21
+ },
22
+ ],
23
+
24
+ // Disallow shadowing of names such as arguments
25
+ // https://eslint.org/docs/rules/no-shadow-restricted-names
26
+ 'no-shadow-restricted-names': 'error',
27
+
28
+ // Disallow use of undefined when initializing variables
29
+ // https://eslint.org/docs/rules/no-undef-init
30
+ 'no-undef-init': 'error',
31
+
32
+ // Disallow declaration of variables that are not used in the code
33
+ // https://eslint.org/docs/rules/no-unused-vars
34
+ 'no-unused-vars': [
35
+ 'error',
36
+ {
37
+ ignoreRestSiblings: true,
38
+ argsIgnorePattern: '_+',
39
+ },
40
+ ],
41
+
42
+ // Disallow use of variables before they are defined
43
+ // https://eslint.org/docs/rules/no-use-before-define
44
+ 'no-use-before-define': [
45
+ 'off',
46
+ {
47
+ functions: false,
48
+ classes: false,
49
+ variables: true,
50
+ },
51
+ ],
52
+ },
53
+ }