@foray1010/eslint-config 7.11.0 → 8.0.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,22 @@
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
+ ## [8.0.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@7.12.0...@foray1010/eslint-config@8.0.0) (2022-10-21)
7
+
8
+ ### ⚠ BREAKING CHANGES
9
+
10
+ - enforce file extension and use native esm typescript
11
+
12
+ ### Features
13
+
14
+ - enforce file extension and use native esm typescript ([c885710](https://github.com/foray1010/common-presets/commit/c8857103a3f828d2cf9946885495bd92d15b8d5d))
15
+
16
+ ## [7.12.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@7.11.0...@foray1010/eslint-config@7.12.0) (2022-10-20)
17
+
18
+ ### Features
19
+
20
+ - **eslint-config:** add checking on circular dependency and self import ([a42e38a](https://github.com/foray1010/common-presets/commit/a42e38a0a08de73265cf70185569b45587284a2f))
21
+
6
22
  ## [7.11.0](https://github.com/foray1010/common-presets/compare/@foray1010/eslint-config@7.10.0...@foray1010/eslint-config@7.11.0) (2022-10-18)
7
23
 
8
24
  ### 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.11.0",
4
+ "version": "8.0.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": {
@@ -28,6 +28,7 @@
28
28
  "@typescript-eslint/parser": "^5.38.1",
29
29
  "confusing-browser-globals": "^1.0.10",
30
30
  "eslint-config-prettier": "^8.3.0",
31
+ "eslint-import-resolver-typescript": "^3.5.2",
31
32
  "eslint-plugin-compat": "^4.0.0",
32
33
  "eslint-plugin-deprecation": "^1.3.2",
33
34
  "eslint-plugin-eslint-comments": "^3.2.0",
@@ -58,5 +59,5 @@
58
59
  "publishConfig": {
59
60
  "access": "public"
60
61
  },
61
- "gitHead": "084439e84e55f473a6f87f18f4b84c7df94d6a28"
62
+ "gitHead": "c6310f72bc0c02649d5b7fe7cdb059e1c36e8200"
62
63
  }
package/presets/base.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // @ts-expect-error
4
4
  const { hasDep, isESM } = require('@foray1010/common-presets-utils')
5
5
 
6
- const { testFileGlobs } = require('./utils/testUtil')
6
+ const { testFileGlobs } = require('./utils/testUtil.js')
7
7
 
8
8
  /** @type {import('eslint').Linter.BaseConfig} */
9
9
  const cjsConfig = {
@@ -33,19 +33,6 @@ const esmConfig = {
33
33
  },
34
34
  }
35
35
 
36
- /** @type {import('eslint').Linter.BaseConfig} */
37
- const esmConfigForJs = {
38
- ...esmConfig,
39
- rules: {
40
- ...esmConfig.rules,
41
- 'import/extensions': [
42
- 'error',
43
- // https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_mandatory_file_extensions
44
- 'always',
45
- ],
46
- },
47
- }
48
-
49
36
  /** @type {import('eslint').Linter.Config} */
50
37
  module.exports = {
51
38
  extends: [
@@ -84,6 +71,21 @@ module.exports = {
84
71
  'func-names': ['error', 'as-needed'],
85
72
  // this rule doesn't support commonjs, some dependencies are using commonjs
86
73
  'import/default': 'off',
74
+ // enforce extensions for both cjs and esm
75
+ 'import/extensions': [
76
+ 'error',
77
+ // https://nodejs.org/docs/latest-v14.x/api/esm.html#esm_mandatory_file_extensions
78
+ 'always',
79
+ {
80
+ pattern: {
81
+ // ignore cts/mts/ts/tsx because typescript uses cjs/mjs/js instead
82
+ cts: 'never',
83
+ mts: 'never',
84
+ ts: 'never',
85
+ tsx: 'never',
86
+ },
87
+ },
88
+ ],
87
89
  // make sure import statements above the others
88
90
  'import/first': 'error',
89
91
  // separate import statements from the others
@@ -102,6 +104,14 @@ module.exports = {
102
104
  allowObject: false,
103
105
  },
104
106
  ],
107
+ // no circular dependency
108
+ 'import/no-cycle': [
109
+ 'error',
110
+ {
111
+ // speed up linting time
112
+ ignoreExternal: true,
113
+ },
114
+ ],
105
115
  // do not allow import packages that are not listed in dependencies or peerDependencies
106
116
  'import/no-extraneous-dependencies': [
107
117
  'error',
@@ -113,6 +123,8 @@ module.exports = {
113
123
  ],
114
124
  },
115
125
  ],
126
+ // forbid a module from importing itself
127
+ 'import/no-self-import': 'error',
116
128
  // use the shortest path in import statement, but allow /index because it will be standard to omit index as default file in directory
117
129
  'import/no-useless-path-segments': [
118
130
  'error',
@@ -133,7 +145,7 @@ module.exports = {
133
145
  overrides: [
134
146
  {
135
147
  files: ['*.js'],
136
- ...(isESM() ? esmConfigForJs : cjsConfig),
148
+ ...(isESM() ? esmConfig : cjsConfig),
137
149
  },
138
150
  {
139
151
  files: ['*.cjs'],
@@ -141,7 +153,7 @@ module.exports = {
141
153
  },
142
154
  {
143
155
  files: ['*.mjs'],
144
- ...esmConfigForJs,
156
+ ...esmConfig,
145
157
  },
146
158
  {
147
159
  files: testFileGlobs,
@@ -176,15 +188,16 @@ module.exports = {
176
188
  // allowAutomaticSingleRunInference: true,
177
189
  project: ['./tsconfig*.json', './packages/*/tsconfig*.json'],
178
190
  },
191
+ settings: {
192
+ 'import/resolver': {
193
+ typescript: true,
194
+ },
195
+ },
179
196
  plugins: [
180
197
  '@typescript-eslint/eslint-plugin',
181
198
  'eslint-plugin-deprecation',
182
199
  'eslint-plugin-functional',
183
200
  ],
184
- env: {
185
- // allow commonjs globals as we haven't moved to es modules
186
- commonjs: true,
187
- },
188
201
  rules: {
189
202
  // extend existing rule
190
203
  '@typescript-eslint/ban-types': [
package/presets/node.js CHANGED
@@ -1,13 +1,20 @@
1
1
  'use strict'
2
2
 
3
+ // @ts-expect-error
4
+ const { isESM } = require('@foray1010/common-presets-utils')
5
+
6
+ /** @type {import('eslint').Linter.BaseConfig} */
7
+ const cjsConfig = {
8
+ globals: {
9
+ __dirname: 'readonly',
10
+ __filename: 'readonly',
11
+ },
12
+ }
13
+
3
14
  /** @type {import('eslint').Linter.Config} */
4
15
  module.exports = {
5
16
  plugins: ['eslint-plugin-n'],
6
17
  globals: {
7
- // used in commonjs and typescript
8
- __dirname: 'readonly',
9
- // used in commonjs and typescript
10
- __filename: 'readonly',
11
18
  // hack to mute no-undef error, and show n/prefer-global/buffer error instead
12
19
  Buffer: 'readonly',
13
20
  // hack to mute no-undef error, and show n/prefer-global/process error instead
@@ -41,4 +48,14 @@ module.exports = {
41
48
  // enforce shebang on the entry bin file
42
49
  'n/shebang': 'error',
43
50
  },
51
+ overrides: [
52
+ {
53
+ files: ['*.js'],
54
+ ...(isESM() ? {} : cjsConfig),
55
+ },
56
+ {
57
+ files: ['*.cjs', '*.cts'],
58
+ ...cjsConfig,
59
+ },
60
+ ],
44
61
  }
package/presets/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const { testFileGlobs } = require('./utils/testUtil')
3
+ const { testFileGlobs } = require('./utils/testUtil.js')
4
4
 
5
5
  /** @type {import('eslint').Linter.Config} */
6
6
  module.exports = {