@allthings/eslint-config 0.0.5 → 0.0.6

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.
Files changed (4) hide show
  1. package/README.md +8 -0
  2. package/index.js +1 -0
  3. package/node.js +324 -0
  4. package/package.json +6 -3
package/README.md CHANGED
@@ -20,6 +20,14 @@ module.exports = {
20
20
  }
21
21
  ```
22
22
 
23
+ ### Node.js projects
24
+
25
+ ```js
26
+ module.exports = {
27
+ extends: ['@allthings/eslint-config/node'],
28
+ }
29
+ ```
30
+
23
31
  ## Development
24
32
 
25
33
  Publishing to npm
package/index.js CHANGED
@@ -160,4 +160,5 @@ module.exports = {
160
160
  browser: true,
161
161
  node: true,
162
162
  },
163
+ root: true,
163
164
  }
package/node.js ADDED
@@ -0,0 +1,324 @@
1
+ /*
2
+ * @rushstack/eslint-patch is used to include plugins as dev
3
+ * dependencies instead of imposing them as peer dependencies
4
+ *
5
+ * https://www.npmjs.com/package/@rushstack/eslint-patch
6
+ */
7
+ const keptPaths = []
8
+ const sortedPaths = []
9
+ const cwd = process.cwd().replace(/\\/g, '/')
10
+ const originalPaths = require.resolve.paths('eslint-plugin-import')
11
+
12
+ // eslint throws a conflict error when plugins resolve to different
13
+ // locations, since we want to lock our dependencies by default
14
+ // but also need to allow using user dependencies this updates
15
+ // our resolve paths to first check the cwd and iterate to
16
+ // eslint-config-next's dependencies if needed
17
+
18
+ for (const currentPath of originalPaths) {
19
+ if (currentPath.replace(/\\/g, '/').startsWith(cwd)) {
20
+ sortedPaths.push(currentPath)
21
+ } else {
22
+ keptPaths.unshift(currentPath)
23
+ }
24
+ }
25
+
26
+ // maintain order of node_modules outside cwd
27
+ sortedPaths.push(...keptPaths.reverse())
28
+
29
+ const hookPropertyMap = new Map(
30
+ [
31
+ ['eslint-plugin-import', 'eslint-plugin-import'],
32
+ ['eslint-plugin-ternary', 'eslint-plugin-ternary'],
33
+ [
34
+ 'eslint-plugin-typescript-sort-keys',
35
+ 'eslint-plugin-typescript-sort-keys',
36
+ ],
37
+ ['eslint-plugin-prefer-arrow', 'eslint-plugin-prefer-arrow'],
38
+ ['eslint-plugin-simple-import-sort', 'eslint-plugin-simple-import-sort'],
39
+ ].map(([request, replacement]) => [
40
+ request,
41
+ require.resolve(replacement, { paths: sortedPaths }),
42
+ ]),
43
+ )
44
+
45
+ const mod = require('module')
46
+ const resolveFilename = mod._resolveFilename
47
+ mod._resolveFilename = function (request, parent, isMain, options) {
48
+ const hookResolved = hookPropertyMap.get(request)
49
+ if (hookResolved) {
50
+ request = hookResolved
51
+ }
52
+ return resolveFilename.call(mod, request, parent, isMain, options)
53
+ }
54
+
55
+ require('@rushstack/eslint-patch/modern-module-resolution')
56
+
57
+ module.exports = {
58
+ extends: [
59
+ 'plugin:import/recommended',
60
+ 'plugin:import/typescript',
61
+ 'eslint:recommended',
62
+ 'plugin:ternary/recommended',
63
+ 'plugin:@typescript-eslint/eslint-recommended',
64
+ 'plugin:@typescript-eslint/recommended',
65
+ 'plugin:typescript-sort-keys/recommended',
66
+ 'plugin:prettier/recommended',
67
+ ],
68
+ plugins: [
69
+ 'import',
70
+ 'typescript-sort-keys',
71
+ 'prefer-arrow',
72
+ 'simple-import-sort',
73
+ 'ternary',
74
+ ],
75
+ rules: {
76
+ '@typescript-eslint/adjacent-overload-signatures': 'error',
77
+ '@typescript-eslint/array-type': [
78
+ 'error',
79
+ {
80
+ default: 'array',
81
+ },
82
+ ],
83
+ '@typescript-eslint/ban-types': [
84
+ 'error',
85
+ {
86
+ types: {
87
+ Object: {
88
+ message: 'Avoid using the `Object` type. Did you mean `object`?',
89
+ },
90
+ Function: {
91
+ message:
92
+ 'Avoid using the `Function` type. Prefer a specific function type, like `() => void`.',
93
+ },
94
+ Boolean: {
95
+ message: 'Avoid using the `Boolean` type. Did you mean `boolean`?',
96
+ },
97
+ Number: {
98
+ message: 'Avoid using the `Number` type. Did you mean `number`?',
99
+ },
100
+ String: {
101
+ message: 'Avoid using the `String` type. Did you mean `string`?',
102
+ },
103
+ Symbol: {
104
+ message: 'Avoid using the `Symbol` type. Did you mean `symbol`?',
105
+ },
106
+ },
107
+ },
108
+ ],
109
+ '@typescript-eslint/consistent-type-assertions': 'error',
110
+ '@typescript-eslint/dot-notation': 'error',
111
+ '@typescript-eslint/explicit-function-return-type': [
112
+ 'warn', // TODO: strict later
113
+ {
114
+ allowExpressions: false,
115
+ allowTypedFunctionExpressions: false,
116
+ allowHigherOrderFunctions: false,
117
+ allowDirectConstAssertionInArrowFunctions: true,
118
+ allowConciseArrowFunctionExpressionsStartingWithVoid: true,
119
+ },
120
+ ],
121
+ '@typescript-eslint/explicit-module-boundary-types': [
122
+ 'warn', // TODO: strict later
123
+ {
124
+ allowArgumentsExplicitlyTypedAsAny: true,
125
+ allowDirectConstAssertionInArrowFunctions: true,
126
+ allowHigherOrderFunctions: false,
127
+ allowTypedFunctionExpressions: false,
128
+ },
129
+ ],
130
+ '@typescript-eslint/member-delimiter-style': [
131
+ 'error',
132
+ {
133
+ multiline: {
134
+ delimiter: 'none',
135
+ requireLast: true,
136
+ },
137
+ singleline: {
138
+ delimiter: 'semi',
139
+ requireLast: false,
140
+ },
141
+ },
142
+ ],
143
+ '@typescript-eslint/naming-convention': [
144
+ 'error',
145
+ {
146
+ custom: {
147
+ match: true,
148
+ regex: '^I[A-Z]',
149
+ },
150
+ format: ['PascalCase'],
151
+ selector: 'interface',
152
+ },
153
+ ],
154
+ '@typescript-eslint/no-empty-function': 'error',
155
+ '@typescript-eslint/no-empty-interface': 'error',
156
+ '@typescript-eslint/no-explicit-any': 'error',
157
+ '@typescript-eslint/no-for-in-array': 'error',
158
+ '@typescript-eslint/no-inferrable-types': 'error',
159
+ '@typescript-eslint/no-misused-new': 'error',
160
+ '@typescript-eslint/no-namespace': 'error',
161
+ '@typescript-eslint/no-shadow': [
162
+ 'error',
163
+ {
164
+ hoist: 'all',
165
+ },
166
+ ],
167
+ '@typescript-eslint/no-this-alias': 'error',
168
+ '@typescript-eslint/no-unused-expressions': 'error',
169
+ '@typescript-eslint/no-unused-vars': 'error',
170
+ '@typescript-eslint/no-use-before-define': 'error',
171
+ '@typescript-eslint/no-var-requires': 'error',
172
+ '@typescript-eslint/prefer-for-of': 'error',
173
+ '@typescript-eslint/prefer-function-type': 'error',
174
+ '@typescript-eslint/prefer-namespace-keyword': 'error',
175
+ '@typescript-eslint/quotes': [
176
+ 'error',
177
+ 'single',
178
+ {
179
+ avoidEscape: true,
180
+ },
181
+ ],
182
+ '@typescript-eslint/semi': ['error', 'never'],
183
+ '@typescript-eslint/triple-slash-reference': [
184
+ 'error',
185
+ {
186
+ path: 'always',
187
+ types: 'prefer-import',
188
+ lib: 'always',
189
+ },
190
+ ],
191
+ '@typescript-eslint/type-annotation-spacing': 'error',
192
+ '@typescript-eslint/typedef': 'error',
193
+ '@typescript-eslint/unified-signatures': 'error',
194
+ 'arrow-body-style': ['error', 'as-needed'],
195
+ complexity: [
196
+ 'error',
197
+ {
198
+ max: 15,
199
+ },
200
+ ],
201
+ 'constructor-super': 'error',
202
+ eqeqeq: ['error', 'smart'],
203
+ 'guard-for-in': 'error',
204
+ 'id-denylist': [
205
+ 'error',
206
+ 'any',
207
+ 'Number',
208
+ 'number',
209
+ 'String',
210
+ 'string',
211
+ 'Boolean',
212
+ 'boolean',
213
+ 'Undefined',
214
+ 'undefined',
215
+ ],
216
+ 'id-match': 'error',
217
+ 'import/no-anonymous-default-export': [
218
+ 'error',
219
+ {
220
+ allowAnonymousClass: false,
221
+ allowAnonymousFunction: false,
222
+ allowArray: false,
223
+ allowArrowFunction: true,
224
+ allowCallExpression: true,
225
+ // The true value here is for backward compatibility
226
+ allowLiteral: false,
227
+ allowObject: true,
228
+ },
229
+ ],
230
+ 'import/no-extraneous-dependencies': [
231
+ 'error',
232
+ {
233
+ devDependencies: true,
234
+ },
235
+ ],
236
+ 'max-classes-per-file': ['error', 1],
237
+ 'no-bitwise': 'error',
238
+ 'no-caller': 'error',
239
+ 'no-cond-assign': 'error',
240
+ 'no-console': 'error',
241
+ 'no-debugger': 'error',
242
+ 'no-duplicate-case': 'error',
243
+ 'no-duplicate-imports': 'error',
244
+ 'no-empty': 'error',
245
+ 'no-eval': 'error',
246
+ 'no-extra-bind': 'error',
247
+ 'no-multiple-empty-lines': 'error',
248
+ 'no-new-func': 'error',
249
+ 'no-new-wrappers': 'error',
250
+ 'no-param-reassign': 'error',
251
+ 'no-redeclare': 'error',
252
+ 'no-return-await': 'error',
253
+ 'no-sequences': 'error',
254
+ 'no-sparse-arrays': 'error',
255
+ 'no-template-curly-in-string': 'error',
256
+ 'no-throw-literal': 'error',
257
+ 'no-trailing-spaces': 'error',
258
+ 'no-undef-init': 'error',
259
+ 'no-unsafe-finally': 'error',
260
+ 'no-unused-labels': 'error',
261
+ 'no-var': 'error',
262
+ 'object-shorthand': 'error',
263
+ 'one-var': ['error', 'never'],
264
+ 'padding-line-between-statements': [
265
+ 'error',
266
+ {
267
+ blankLine: 'always',
268
+ prev: '*',
269
+ next: 'return',
270
+ },
271
+ ],
272
+ 'prefer-arrow/prefer-arrow-functions': 'error',
273
+ 'prefer-const': 'error',
274
+ 'prefer-object-spread': 'error',
275
+ 'prefer-template': 'error',
276
+ quotes: ['error', 'single', { avoidEscape: true }],
277
+ radix: 'error',
278
+ 'simple-import-sort/imports': 'error',
279
+ 'simple-import-sort/exports': 'error',
280
+ 'sort-keys': 'error',
281
+ 'spaced-comment': [
282
+ 'error',
283
+ 'always',
284
+ {
285
+ markers: ['/'],
286
+ },
287
+ ],
288
+ 'use-isnan': 'error',
289
+ },
290
+ parser: '@typescript-eslint/parser',
291
+ parserOptions: {
292
+ ecmaFeatures: {
293
+ jsx: true,
294
+ },
295
+ ecmaVersion: 2021,
296
+ project: 'tsconfig.json',
297
+ sourceType: 'module',
298
+ warnOnUnsupportedTypeScriptVersion: false,
299
+ },
300
+ settings: {
301
+ 'import/parsers': {
302
+ [require.resolve('@typescript-eslint/parser')]: [
303
+ '.ts',
304
+ '.mts',
305
+ '.cts',
306
+ '.tsx',
307
+ '.d.ts',
308
+ ],
309
+ },
310
+ 'import/resolver': {
311
+ [require.resolve('eslint-import-resolver-node')]: {
312
+ extensions: ['.js', '.jsx', '.ts', '.tsx'],
313
+ },
314
+ [require.resolve('eslint-import-resolver-typescript')]: {
315
+ alwaysTryTypes: true,
316
+ },
317
+ },
318
+ },
319
+ env: {
320
+ node: true,
321
+ es6: true,
322
+ },
323
+ root: true,
324
+ }
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@allthings/eslint-config",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "ESlint shareable config for Allthings style",
5
5
  "main": "index.js",
6
6
  "files": [
7
- "index.js"
7
+ "index.js",
8
+ "node.js"
8
9
  ],
9
10
  "scripts": {
10
11
  "lint": "prettier --check .",
11
12
  "test": "eslint test/",
12
13
  "predeploy": "yarn test",
13
14
  "deploy": "yarn publish --new-version $npm_package_version --tag latest --access public",
14
- "poatdeploy": "git push --tags origin HEAD"
15
+ "postdeploy": "git push --tags origin HEAD"
15
16
  },
16
17
  "dependencies": {
17
18
  "@rushstack/eslint-patch": "^1.2.0",
@@ -23,10 +24,12 @@
23
24
  "eslint-plugin-import": "^2.26.0",
24
25
  "eslint-plugin-jsx-a11y": "^6.6.1",
25
26
  "eslint-plugin-n": "^15.5.1",
27
+ "eslint-plugin-prefer-arrow": "^1.2.3",
26
28
  "eslint-plugin-prettier": "^4.2.1",
27
29
  "eslint-plugin-react": "^7.31.11",
28
30
  "eslint-plugin-react-hooks": "^4.6.0",
29
31
  "eslint-plugin-simple-import-sort": "^8.0.0",
32
+ "eslint-plugin-ternary": "^2.0.0",
30
33
  "eslint-plugin-typescript-sort-keys": "^2.1.0"
31
34
  },
32
35
  "peerDependencies": {