@foray1010/eslint-config 7.6.0 → 7.7.0

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,24 @@
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.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@7.6.1...@foray1010/eslint-config@7.7.0) (2022-10-01)
7
+
8
+ ### Features
9
+
10
+ - **eslint-config:** do not allow node.js modules in frontend ([972f434](https://github.com/foray1010/common-presets/commit/972f434064891238cfc71db5379ac77be8f5e10d))
11
+ - **eslint-config:** do not allow unknown global variables ([a62994e](https://github.com/foray1010/common-presets/commit/a62994e1aeee48202a03484ec1772a4016f86d93))
12
+
13
+ ### Bug Fixes
14
+
15
+ - **eslint-config:** better error description when using global Buffer or process ([00e14ee](https://github.com/foray1010/common-presets/commit/00e14ee9c2f0afab8ebe78ecc89c3ab79b8a93f0))
16
+ - **eslint-config:** skip nodejs related rules for react ([a7b12d7](https://github.com/foray1010/common-presets/commit/a7b12d7d0d428189ead3ecce7f4a59ae87c72536))
17
+
18
+ ## [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)
19
+
20
+ ### Bug Fixes
21
+
22
+ - **eslint-config:** disable functional/prefer-tacit ([e921649](https://github.com/foray1010/common-presets/commit/e921649d17802d3e866b075b1a5be39200e96991))
23
+
6
24
  ## [7.6.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@7.5.0...@foray1010/eslint-config@7.6.0) (2022-09-30)
7
25
 
8
26
  ### Features
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.0",
4
+ "version": "7.7.0",
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": "78887040561cbee1de447df3c885414f81cbefba"
59
+ "gitHead": "8a9de7e7659db21109b2b328116706ff9e9d48ec"
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'],
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,
23
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,7 +172,6 @@ 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',
@@ -255,7 +268,11 @@ module.exports = {
255
268
  },
256
269
  ],
257
270
  // forbid unnecessary callback wrapper
258
- 'functional/prefer-tacit': 'error',
271
+ // disabled due to https://github.com/eslint-functional/eslint-plugin-functional/issues/486
272
+ // 'functional/prefer-tacit': 'error',
273
+ // @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
274
+ // 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
275
+ 'no-undef': 'error',
259
276
  },
260
277
  overrides: [
261
278
  {
@@ -15,5 +15,7 @@ module.exports = {
15
15
  },
16
16
  rules: {
17
17
  'no-restricted-globals': ['error', ...restrictedGlobals],
18
+ // frontend environment doesn't support node.js modules
19
+ 'import/no-nodejs-modules': 'error',
18
20
  },
19
21
  }
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
  }