@foray1010/eslint-config 7.6.1 → 7.7.1

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/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [7.7.1](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@7.7.0...@foray1010/eslint-config@7.7.1) (2022-10-01)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **eslint-config:** allow commonjs globals as we haven't moved to es modules ([08ab8d0](https://github.com/foray1010/common-presets/commit/08ab8d09244e2314de611a4fb1fda8552a958515))
11
+ - **eslint-config:** allow webextensions globals in frontend ([7624ed5](https://github.com/foray1010/common-presets/commit/7624ed5f5e2c710a5d1abbb831b476190aca32d5))
12
+
13
+ ## [7.7.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@7.6.1...@foray1010/eslint-config@7.7.0) (2022-10-01)
14
+
15
+ ### Features
16
+
17
+ - **eslint-config:** do not allow node.js modules in frontend ([972f434](https://github.com/foray1010/common-presets/commit/972f434064891238cfc71db5379ac77be8f5e10d))
18
+ - **eslint-config:** do not allow unknown global variables ([a62994e](https://github.com/foray1010/common-presets/commit/a62994e1aeee48202a03484ec1772a4016f86d93))
19
+
20
+ ### Bug Fixes
21
+
22
+ - **eslint-config:** better error description when using global Buffer or process ([00e14ee](https://github.com/foray1010/common-presets/commit/00e14ee9c2f0afab8ebe78ecc89c3ab79b8a93f0))
23
+ - **eslint-config:** skip nodejs related rules for react ([a7b12d7](https://github.com/foray1010/common-presets/commit/a7b12d7d0d428189ead3ecce7f4a59ae87c72536))
24
+
6
25
  ## [7.6.1](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@7.6.0...@foray1010/eslint-config@7.6.1) (2022-09-30)
7
26
 
8
27
  ### Bug Fixes
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@foray1010/eslint-config",
4
- "version": "7.6.1",
4
+ "version": "7.7.1",
5
5
  "homepage": "https://github.com/foray1010/common-presets/tree/master/packages/eslint-config#readme",
6
6
  "bugs": "https://github.com/foray1010/common-presets/issues",
7
7
  "repository": {
@@ -56,5 +56,5 @@
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
- "gitHead": "2db2510ae90fd5b609aaad1e8c41934d29e310b7"
59
+ "gitHead": "ecc4d8bbdfe9a51e4c6214723f029978a777a37e"
60
60
  }
package/presets/base.js CHANGED
@@ -13,14 +13,31 @@ const cjsConfig = {
13
13
  env: {
14
14
  commonjs: true,
15
15
  },
16
+ rules: {
17
+ // commonjs must use strict mode
18
+ strict: ['error', 'global'],
19
+ },
16
20
  }
17
21
 
18
22
  /** @type {import('eslint').Linter.BaseConfig} */
19
- const esmConfigForJs = {
23
+ const esmConfig = {
20
24
  parserOptions: {
21
25
  sourceType: 'module',
22
26
  },
27
+ plugins: ['eslint-plugin-simple-import-sort'],
23
28
  rules: {
29
+ // auto sort export statements
30
+ 'simple-import-sort/exports': 'error',
31
+ // auto sort import statements
32
+ 'simple-import-sort/imports': 'error',
33
+ },
34
+ }
35
+
36
+ /** @type {import('eslint').Linter.BaseConfig} */
37
+ const esmConfigForJs = {
38
+ ...esmConfig,
39
+ rules: {
40
+ ...esmConfig.rules,
24
41
  'import/extensions': [
25
42
  'error',
26
43
  // https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_mandatory_file_extensions
@@ -47,7 +64,6 @@ module.exports = {
47
64
  'eslint-plugin-import',
48
65
  'eslint-plugin-jsdoc',
49
66
  'eslint-plugin-prettier',
50
- 'eslint-plugin-simple-import-sort',
51
67
  ],
52
68
  env: {
53
69
  // should align with parserOptions.ecmaVersion
@@ -110,12 +126,6 @@ module.exports = {
110
126
  'jsdoc/valid-types': 'off',
111
127
  // avoid assigning anonymous function to object key which is harder to trace when debug
112
128
  'object-shorthand': ['error', 'always'],
113
- // auto sort export statements
114
- 'simple-import-sort/exports': 'error',
115
- // auto sort import statements
116
- 'simple-import-sort/imports': 'error',
117
- // commonjs must use strict mode
118
- strict: ['error', 'global'],
119
129
  },
120
130
  overrides: [
121
131
  {
@@ -142,6 +152,10 @@ module.exports = {
142
152
  // typescript plugins are depended on `typescript` package
143
153
  ...(hasDep('typescript')
144
154
  ? [
155
+ {
156
+ files: ['*.{cts,mts,ts,tsx}'],
157
+ ...esmConfig,
158
+ },
145
159
  {
146
160
  files: ['*.{cts,mts,ts,tsx}'],
147
161
  extends: [
@@ -158,12 +172,15 @@ module.exports = {
158
172
  // turned off because @typescript-eslint/no-unsafe-* rules will output wrong errors
159
173
  // allowAutomaticSingleRunInference: true,
160
174
  project: ['./tsconfig*.json', './packages/*/tsconfig*.json'],
161
- sourceType: 'module',
162
175
  },
163
176
  plugins: [
164
177
  '@typescript-eslint/eslint-plugin',
165
178
  'eslint-plugin-functional',
166
179
  ],
180
+ env: {
181
+ // allow commonjs globals as we haven't moved to es modules
182
+ commonjs: true,
183
+ },
167
184
  rules: {
168
185
  // extend existing rule
169
186
  '@typescript-eslint/ban-types': [
@@ -257,6 +274,9 @@ module.exports = {
257
274
  // forbid unnecessary callback wrapper
258
275
  // disabled due to https://github.com/eslint-functional/eslint-plugin-functional/issues/486
259
276
  // 'functional/prefer-tacit': 'error',
277
+ // @typescript-eslint/eslint-plugin suggests to disable it: https://github.com/typescript-eslint/typescript-eslint/blob/2588e9ea55f78352fdd6ae92a306135aabb49a1a/docs/linting/TROUBLESHOOTING.md#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
278
+ // It is disabled in recommended config but re-enabled here to enforce a subset of global variables that supported by both node.js and browsers
279
+ 'no-undef': 'error',
260
280
  },
261
281
  overrides: [
262
282
  {
@@ -8,6 +8,7 @@ module.exports = {
8
8
  plugins: ['eslint-plugin-compat'],
9
9
  env: {
10
10
  browser: true,
11
+ webextensions: true,
11
12
  },
12
13
  globals: {
13
14
  // keep it until webpack has an official way to define env: https://github.com/webpack/webpack/issues/15833
@@ -15,5 +16,7 @@ module.exports = {
15
16
  },
16
17
  rules: {
17
18
  'no-restricted-globals': ['error', ...restrictedGlobals],
19
+ // frontend environment doesn't support node.js modules
20
+ 'import/no-nodejs-modules': 'error',
18
21
  },
19
22
  }
package/presets/node.js CHANGED
@@ -3,6 +3,12 @@
3
3
  /** @type {import('eslint').Linter.Config} */
4
4
  module.exports = {
5
5
  plugins: ['eslint-plugin-n'],
6
+ globals: {
7
+ // hack to mute no-undef error, and show n/prefer-global/buffer error instead
8
+ Buffer: 'readonly',
9
+ // hack to mute no-undef error, and show n/prefer-global/process error instead
10
+ process: 'readonly',
11
+ },
6
12
  rules: {
7
13
  // disallow deprecated node APIs
8
14
  'n/no-deprecated-api': 'error',
@@ -12,6 +18,10 @@ module.exports = {
12
18
  'n/no-unpublished-bin': 'error',
13
19
  // disallow unsupported Node.js built-in APIs on the specified version
14
20
  'n/no-unsupported-features/node-builtins': 'error',
21
+ // prefer `import { Buffer } from 'node:buffer'`
22
+ 'n/prefer-global/buffer': ['error', 'never'],
23
+ // prefer `import process from 'node:process'`
24
+ 'n/prefer-global/process': ['error', 'never'],
15
25
  // make `process.exit()` expressions the same code path as `throw`
16
26
  'n/process-exit-as-throw': 'error',
17
27
  // enforce shebang on the entry bin file
package/react.js CHANGED
@@ -1,10 +1,5 @@
1
1
  'use strict'
2
2
 
3
3
  module.exports = {
4
- extends: [
5
- './presets/base.js',
6
- './presets/node.js',
7
- './presets/browser.js',
8
- './presets/react.js',
9
- ],
4
+ extends: ['./presets/base.js', './presets/browser.js', './presets/react.js'],
10
5
  }