@nice-move/eslint-config-base 0.11.35 → 0.12.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/README.md CHANGED
@@ -21,15 +21,11 @@ npm install eslint @nice-move/eslint-config-base --save-dev
21
21
 
22
22
  ## Usage
23
23
 
24
- Add to package.json
25
-
26
- ```jsonc
27
- // example: package.json
28
- {
29
- "eslintConfig": {
30
- "extends": "@nice-move/eslint-config-base"
31
- }
32
- }
24
+ Add to eslint.config.mjs
25
+
26
+ ```js
27
+ // example: eslint.config.mjs
28
+ export { default } from '@nice-move/eslint-config-base';
33
29
  ```
34
30
 
35
31
  Then run
@@ -40,17 +36,12 @@ eslint --fix .
40
36
 
41
37
  ## Specification
42
38
 
43
- [ava]: https://github.com/avajs/ava
44
- [webpack]: https://webpack.js.org/
45
-
46
39
  | Environment | pattern |
47
40
  | :---------- | :------------------------------------------------------------------------------------------- |
48
41
  | browser | `.js`, `.html` |
49
42
  | node.js | `.mjs`, `.mts`, `.cjs`, `.cts` |
50
43
  | es modules | `.mjs`, `.mts`, `.js`, `.html` |
51
44
  | commonjs | `.cjs`, source code in webpack project |
52
- | [webpack] | `src/**`, `packages/*/**` |
53
- | [ava] | `{test,tests,spec,specs}/**`, `**/*.{test,spec}.*` <br /> when `eslint-plugin-ava` installed |
54
45
 
55
46
  ## Tips
56
47
 
package/index.mjs ADDED
@@ -0,0 +1,107 @@
1
+ import { dirname } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ import { FlatCompat } from '@eslint/eslintrc';
5
+ import js from '@eslint/js';
6
+ import { recommended as html } from '@nice-move/eslint-plugin-html/lib/configs-next.mjs';
7
+ import airbnb from 'eslint-config-airbnb-base';
8
+ import prettier from 'eslint-config-prettier';
9
+
10
+
11
+ import { getPkg, readJson } from 'settingz';
12
+
13
+ import base from './lib/base.mjs';
14
+ import imports from './lib/import.mjs';
15
+ import markdown from './lib/markdown.mjs';
16
+ import mini from './lib/mini.mjs';
17
+ import node from './lib/node.mjs';
18
+ import promise from './lib/promise.mjs';
19
+ import typescript from './lib/typescript.mjs';
20
+ import unicorn from './lib/unicorn.mjs';
21
+ import { pkgHas } from './lib/utils.mjs';
22
+
23
+ function ignoreList() {
24
+ const { ignore: { all = [], eslint = [] } = {} } = getPkg('nice-move');
25
+
26
+ return [...all, ...eslint];
27
+ }
28
+
29
+ function BestShot() {
30
+ const { git = [], eslint = git } = readJson(
31
+ '@best-shot/cli/config/ignore.json',
32
+ );
33
+
34
+ return eslint;
35
+ }
36
+
37
+ const __filename = fileURLToPath(import.meta.url);
38
+ const __dirname = dirname(__filename);
39
+
40
+ const compat = new FlatCompat({
41
+ baseDirectory: __dirname,
42
+ resolvePluginsRelativeTo: __dirname,
43
+ });
44
+
45
+ const old = compat.config(airbnb).map((item) => {
46
+ delete item.plugins;
47
+ return item;
48
+ });
49
+
50
+ export default [
51
+ js.configs.recommended,
52
+ ...old,
53
+ ...unicorn,
54
+ ...promise,
55
+ ...imports,
56
+ ...base,
57
+ ...pkgHas(
58
+ ({ devDependencies: { electron } = {} }) => electron,
59
+ () => [
60
+ {
61
+ files: ['src/**'],
62
+ settings: {
63
+ 'import/core-modules': ['electron'],
64
+ },
65
+ },
66
+ ],
67
+ ),
68
+ ...pkgHas(
69
+ ({ peerDependencies: { '@playwright/test': playwright } = {} }) =>
70
+ playwright,
71
+ () => [
72
+ {
73
+ files: ['test/**'],
74
+ settings: {
75
+ 'import/core-modules': ['@playwright/test'],
76
+ },
77
+ },
78
+ ],
79
+ ),
80
+ ...node,
81
+ ...typescript,
82
+ ...markdown,
83
+ ...mini,
84
+ ...html,
85
+ ...compat.config(prettier),
86
+ {
87
+ linterOptions: {
88
+ noInlineConfig: false,
89
+ reportUnusedDisableDirectives: true,
90
+ },
91
+ },
92
+ {
93
+ ignores: [
94
+ '.cache/',
95
+ '.git/',
96
+ '.svn/',
97
+ '*.min.*',
98
+ '**/.docusaurus/**',
99
+ '**/.obsidian/**',
100
+ '**/dist/**',
101
+ '**/miniprogram_npm/**',
102
+ '**/node_modules/**',
103
+ ...BestShot(),
104
+ ...ignoreList(),
105
+ ],
106
+ },
107
+ ];
package/lib/base.mjs ADDED
@@ -0,0 +1,191 @@
1
+ import comments from '@eslint-community/eslint-plugin-eslint-comments/configs';
2
+ import * as regexpPlugin from 'eslint-plugin-regexp';
3
+
4
+ import { getGlobals } from './utils.mjs';
5
+
6
+ const all = ['**/*.{js,jsx,ts,tsx,mjs,mts,cjs,cts,qs,wxs,vue}'];
7
+
8
+ export default [
9
+ {
10
+ files: all,
11
+ ...comments.recommended,
12
+ },
13
+ {
14
+ files: all,
15
+ ...regexpPlugin.configs['flat/recommended'],
16
+ },
17
+ {
18
+ files: all,
19
+ rules: {
20
+ 'lines-around-directive': 0,
21
+ 'array-callback-return': [
22
+ 'error',
23
+ {
24
+ allowImplicit: true,
25
+ checkForEach: true,
26
+ },
27
+ ],
28
+ 'arrow-body-style': 0,
29
+ camelcase: 0,
30
+ 'global-require': 0,
31
+ 'class-methods-use-this': 'warn',
32
+ 'consistent-return': 'warn',
33
+ 'grouped-accessor-pairs': 0,
34
+ 'lines-between-class-members': 0,
35
+ 'max-classes-per-file': 0,
36
+ 'no-await-in-loop': 0,
37
+ 'no-console': 0,
38
+ 'no-constant-binary-expression': 'error',
39
+ 'no-constructor-return': 0,
40
+ 'no-empty': [
41
+ 'error',
42
+ {
43
+ allowEmptyCatch: true,
44
+ },
45
+ ],
46
+ 'no-implicit-coercion': [
47
+ 'warn',
48
+ {
49
+ disallowTemplateShorthand: true,
50
+ },
51
+ ],
52
+ 'no-nested-ternary': 0,
53
+ 'no-restricted-exports': [
54
+ 'error',
55
+ {
56
+ restrictedNamedExports: ['then', 'await'],
57
+ },
58
+ ],
59
+ 'no-param-reassign': [
60
+ 'warn',
61
+ {
62
+ ignorePropertyModificationsFor: [],
63
+ props: true,
64
+ },
65
+ ],
66
+ 'no-restricted-syntax': [
67
+ 'error',
68
+ {
69
+ message:
70
+ 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
71
+ selector: 'ForInStatement',
72
+ },
73
+ {
74
+ message:
75
+ 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
76
+ selector: 'LabeledStatement',
77
+ },
78
+ ],
79
+ 'no-plusplus': 0,
80
+ 'no-template-curly-in-string': 0,
81
+ 'no-undef-init': 0,
82
+ 'no-underscore-dangle': 0,
83
+ 'no-unreachable-loop': 0,
84
+ 'no-unused-expressions': [
85
+ 'error',
86
+ {
87
+ allowTaggedTemplates: true,
88
+ },
89
+ ],
90
+ 'no-unused-vars': [
91
+ 'error',
92
+ {
93
+ argsIgnorePattern: '^_+$',
94
+ varsIgnorePattern: '^_+$',
95
+ ignoreRestSiblings: true,
96
+ reportUsedIgnorePattern: true,
97
+ },
98
+ ],
99
+ 'no-useless-rename': 0,
100
+ 'object-shorthand': 0,
101
+ 'prefer-arrow-callback': 'warn',
102
+ 'prefer-exponentiation-operator': 0,
103
+ 'prefer-template': 'warn',
104
+ 'spaced-comment': 0,
105
+ '@eslint-community/eslint-comments/no-unused-enable': 'warn',
106
+ '@eslint-community/eslint-comments/disable-enable-pair': 0,
107
+ },
108
+ },
109
+ {
110
+ files: ['**/*.{js,jsx,ts,tsx,mjs,mts,cjs,cts,vue}'],
111
+ languageOptions: {
112
+ ecmaVersion: 'latest',
113
+ globals: {
114
+ ...getGlobals({ es2025: true }),
115
+ },
116
+ },
117
+ },
118
+ {
119
+ files: ['**/*.js', '**/*.ts', '**/*.jsx', '**/*.tsx'],
120
+ languageOptions: {
121
+ sourceType: 'module',
122
+ globals: {
123
+ ...getGlobals({ es2025: true, browser: true }),
124
+ },
125
+ parserOptions: {
126
+ ecmaFeatures: {
127
+ impliedStrict: true,
128
+ globalReturn: false,
129
+ },
130
+ },
131
+ },
132
+ },
133
+ {
134
+ files: ['**/*.js', '**/*.ts'],
135
+ languageOptions: {
136
+ parserOptions: {
137
+ ecmaFeatures: {
138
+ jsx: false,
139
+ },
140
+ },
141
+ },
142
+ },
143
+ {
144
+ files: ['**/*.jsx', '**/*.tsx'],
145
+ languageOptions: {
146
+ parserOptions: {
147
+ ecmaFeatures: {
148
+ jsx: true,
149
+ },
150
+ },
151
+ },
152
+ },
153
+ {
154
+ files: ['**/*.mjs', '**/*.mts', '**/*.cts'],
155
+ languageOptions: {
156
+ globals: {
157
+ ...getGlobals({ es2025: true, node: true }),
158
+ },
159
+ sourceType: 'module',
160
+ parserOptions: {
161
+ ecmaFeatures: {
162
+ impliedStrict: true,
163
+ jsx: false,
164
+ },
165
+ },
166
+ },
167
+ },
168
+ {
169
+ files: ['**/*.{cjs,cts}'],
170
+ languageOptions: {
171
+ globals: {
172
+ ...getGlobals({ es2025: true, commonjs: true, node: true }),
173
+ },
174
+ },
175
+ rules: {
176
+ strict: ['error', 'global'],
177
+ },
178
+ },
179
+ {
180
+ files: ['**/*.cjs'],
181
+ languageOptions: {
182
+ sourceType: 'commonjs',
183
+ parserOptions: {
184
+ ecmaFeatures: {
185
+ jsx: false,
186
+ impliedStrict: false,
187
+ },
188
+ },
189
+ },
190
+ },
191
+ ];
package/lib/import.mjs ADDED
@@ -0,0 +1,102 @@
1
+ import { fileURLToPath } from 'node:url';
2
+
3
+ import imports from 'eslint-plugin-import';
4
+
5
+ import { configHas, pkgHas } from './utils.mjs';
6
+
7
+ const Vscode = pkgHas(
8
+ ({ engines: { vscode } = {} }) => vscode,
9
+ () => ({ 'import/core-modules': ['vscode'] }),
10
+ );
11
+
12
+ export default [
13
+ imports.flatConfigs.recommended,
14
+ {
15
+ files: ['**/*.{js,jsx,ts,tsx,cjs,mjs,cts,mts}'],
16
+ ignores: [
17
+ '*.config.{m,c}{j,t}s',
18
+ '.config/**/.{m,c}{j,t}s',
19
+ 'config/**/.{m,c}{j,t}s',
20
+ '**/*.md/*',
21
+ ],
22
+ rules: {
23
+ 'import/no-default-export': 'warn',
24
+ },
25
+ },
26
+ {
27
+ files: ['**/*.{js,jsx,ts,tsx,cjs,mjs,cts,mts,qs,wxs,vue}'],
28
+ rules: {
29
+ 'import/extensions': [
30
+ 'error',
31
+ 'always',
32
+ {
33
+ ignorePackages: true,
34
+ },
35
+ ],
36
+ 'import/no-extraneous-dependencies': [
37
+ 'error',
38
+ {
39
+ devDependencies: [
40
+ '**/*.{test,spec}.{m,c,}{t,j}s',
41
+ '{test,tests,try}.{m,c,}{t,j}s',
42
+ '{test,tests,config}/**/*.{m,c,}{t,j}s',
43
+ '**/.*rc.{m,c,}{t,j}s',
44
+ '**/*.config.{m,c,}{t,j}s',
45
+ '**/config.{m,c,}{t,j}s',
46
+ '.*/config.{m,c,}{t,j}s',
47
+ '**/.best-shot/**',
48
+ ...(configHas(
49
+ ({ bundle = [] }) => bundle,
50
+ (bundle) => bundle,
51
+ ) || []),
52
+ ],
53
+ },
54
+ ],
55
+ 'import/newline-after-import': 0,
56
+ 'import/no-dynamic-require': 0,
57
+ 'import/no-empty-named-blocks': 'error',
58
+ 'import/no-relative-packages': 0,
59
+ 'import/order': 0,
60
+ 'import/prefer-default-export': 0,
61
+ 'import/no-cycle': 0,
62
+ },
63
+ settings: {
64
+ ...Vscode,
65
+ 'import/extensions': [
66
+ '.tsx',
67
+ '.ts',
68
+ '.cts',
69
+ '.mts',
70
+ '.vue',
71
+ '.jsx',
72
+ '.js',
73
+ '.mjs',
74
+ '.cjs',
75
+ ],
76
+ 'import/parsers': {
77
+ '@typescript-eslint/parser': ['.ts', '.cts', '.mts', '.tsx'],
78
+ 'vue-eslint-parser': ['.vue'],
79
+ [fileURLToPath(import.meta.resolve('./jsx-parser.cjs'))]: ['.jsx'],
80
+ },
81
+ 'import/ignore': false,
82
+ ...configHas(
83
+ ({ 'internal-regex': internalRegex }) => internalRegex,
84
+ (internalRegex) => ({ 'import/internal-regex': internalRegex }),
85
+ ),
86
+ 'import/resolver': {
87
+ node: false,
88
+ [fileURLToPath(import.meta.resolve('./node-next-resolver.cjs'))]:
89
+ configHas(
90
+ ({ 'import-http': importHttp }) => importHttp,
91
+ (importHttp) => ({ importHttp }),
92
+ ) || {},
93
+ },
94
+ },
95
+ },
96
+ {
97
+ files: ['**/*.{js,jsx,ts,tsx,vue,qs,wxs}'],
98
+ rules: {
99
+ 'import/no-nodejs-modules': 'error',
100
+ },
101
+ },
102
+ ];
@@ -0,0 +1,44 @@
1
+ import markdown from 'eslint-plugin-markdown';
2
+
3
+ import { getGlobals } from './utils.mjs';
4
+
5
+ export default [
6
+ {
7
+ files: ['**/*.md'],
8
+ name: 'markdown/recommended/plugin',
9
+ plugins: {
10
+ markdown,
11
+ },
12
+ },
13
+ {
14
+ name: 'markdown/recommended/processor',
15
+ files: ['**/*.md'],
16
+ processor: 'markdown/markdown',
17
+ languageOptions: {
18
+ ecmaVersion: 'latest',
19
+ globals: {
20
+ ...getGlobals(),
21
+ },
22
+ },
23
+ },
24
+ {
25
+ files: ['**/*.md/**'],
26
+ // plugins: {
27
+ // markdown,
28
+ // },
29
+ rules: {
30
+ strict: 'off',
31
+ 'eol-last': 'off',
32
+ 'no-undef': 'off',
33
+ 'no-unused-expressions': 'off',
34
+ 'no-unused-vars': 'off',
35
+ 'unicode-bom': 'off',
36
+ 'import/no-extraneous-dependencies': 'off',
37
+ 'import/no-unresolved': 'off',
38
+ 'unicorn/filename-case': 'off',
39
+ 'unicorn/custom-error-definition': 'off',
40
+ '@typescript-eslint/no-unused-vars': 'off',
41
+ '@typescript-eslint/no-extraneous-class': 'off',
42
+ },
43
+ },
44
+ ];
@@ -1,10 +1,8 @@
1
- 'use strict';
2
-
3
- const { relative } = require('node:path');
4
- const { reaching } = require('settingz');
1
+ import { relative } from 'node:path';
2
+ import { reaching } from 'settingz';
3
+ import { getGlobals } from './utils.mjs';
5
4
 
6
5
  const cwd = process.cwd();
7
- const { getGlobals } = require('../lib/utils.cjs');
8
6
 
9
7
  function relativeToCWD(path) {
10
8
  return relative(cwd, path);
@@ -29,65 +27,71 @@ function generate({
29
27
  .filter(Boolean)
30
28
  .map((item) => relativeToCWD(item));
31
29
 
32
- const excludedFiles = ['*.wxs', '*.qs'];
30
+ const ignores = ['**/*.wxs', '**/*.qs'];
33
31
 
34
32
  const cloudMatcher = cloudfunctionRoot
35
33
  ? matcher([relativeToCWD(cloudfunctionRoot)], '**')
36
34
  : undefined;
37
35
 
38
- const globals = {
39
- clearInterval: 'readonly',
40
- clearTimeout: 'readonly',
41
- console: 'readonly',
42
- setInterval: 'readonly',
43
- setTimeout: 'readonly',
44
- };
36
+ // const globals = {
37
+ // clearInterval: 'readonly',
38
+ // clearTimeout: 'readonly',
39
+ // console: 'readonly',
40
+ // setInterval: 'readonly',
41
+ // setTimeout: 'readonly',
42
+ // };
45
43
 
46
44
  return [
47
45
  {
48
- files: matcher(paths, '**'),
49
- excludedFiles,
50
- globals: {
51
- ...getGlobals({ es2025: true }),
52
- ...globals,
53
- wx: 'readonly',
54
- getApp: 'readonly',
55
- getCurrentPages: 'readonly',
56
- requirePlugin: 'readonly',
57
- requireMiniProgram: 'readonly',
46
+ files: [matcher(paths, '**')],
47
+ ignores,
48
+ languageOptions: {
49
+ globals: {
50
+ wx: 'readonly',
51
+ getApp: 'readonly',
52
+ getCurrentPages: 'readonly',
53
+ requirePlugin: 'readonly',
54
+ requireMiniProgram: 'readonly',
55
+ },
58
56
  },
59
57
  },
60
58
  {
61
- files: matcher(paths, 'component{,s}/**'),
62
- excludedFiles,
63
- globals: {
64
- Component: 'readonly',
65
- Behavior: 'readonly',
59
+ files: [matcher(paths, 'component{,s}/**')],
60
+ ignores,
61
+ languageOptions: {
62
+ globals: {
63
+ Component: 'readonly',
64
+ Behavior: 'readonly',
65
+ },
66
66
  },
67
67
  },
68
68
  {
69
- files: matcher(paths, 'page{,s}/**'),
70
- excludedFiles,
71
- globals: {
72
- Behavior: 'readonly',
73
- Component: 'readonly',
74
- Page: 'readonly',
69
+ files: [matcher(paths, 'page{,s}/**')],
70
+ ignores,
71
+ languageOptions: {
72
+ globals: {
73
+ Behavior: 'readonly',
74
+ Component: 'readonly',
75
+ Page: 'readonly',
76
+ },
75
77
  },
76
78
  },
77
79
  {
78
- files: matcher(paths, 'app.js'),
79
- globals: {
80
- App: 'readonly',
80
+ files: [matcher(paths, 'app.js')],
81
+ languageOptions: {
82
+ globals: {
83
+ App: 'readonly',
84
+ },
81
85
  },
82
86
  },
83
87
  cloudMatcher
84
88
  ? {
85
89
  files: [cloudMatcher],
86
- globals: {
87
- ...getGlobals(),
88
- ...globals,
89
- require: 'readonly',
90
- exports: 'readonly',
90
+ languageOptions: {
91
+ globals: {
92
+ require: 'readonly',
93
+ exports: 'readonly',
94
+ },
91
95
  },
92
96
  rules: {
93
97
  'import/no-commonjs': 'off',
@@ -96,37 +100,40 @@ function generate({
96
100
  }
97
101
  : undefined,
98
102
  {
99
- files: excludedFiles,
100
- parserOptions: {
103
+ files: ignores,
104
+ languageOptions: {
101
105
  ecmaVersion: 5,
102
- sourceType: 'script',
103
- ecmaFeatures: {
104
- globalReturn: false,
105
- impliedStrict: false,
106
- jsx: false,
106
+ sourceType: 'commonjs',
107
+ globals: {
108
+ ...getGlobals(),
109
+ Date: false,
110
+ decodeURI: false,
111
+ decodeURIComponent: false,
112
+ encodeURI: false,
113
+ encodeURIComponent: false,
114
+ getDate: false,
115
+ getRegExp: false,
116
+ Infinity: false,
117
+ isFinite: false,
118
+ isNaN: false,
119
+ JSON: false,
120
+ Math: false,
121
+ module: false,
122
+ NaN: false,
123
+ Number: false,
124
+ parseFloat: false,
125
+ parseInt: false,
126
+ require: false,
127
+ undefined: false,
128
+ },
129
+ parserOptions: {
130
+ ecmaFeatures: {
131
+ globalReturn: false,
132
+ impliedStrict: false,
133
+ jsx: false,
134
+ objectLiteralDuplicateProperties: false,
135
+ },
107
136
  },
108
- },
109
- globals: {
110
- ...getGlobals(),
111
- Date: false,
112
- decodeURI: false,
113
- decodeURIComponent: false,
114
- encodeURI: false,
115
- encodeURIComponent: false,
116
- getDate: false,
117
- getRegExp: false,
118
- Infinity: false,
119
- isFinite: false,
120
- isNaN: false,
121
- JSON: false,
122
- Math: false,
123
- module: false,
124
- NaN: false,
125
- Number: false,
126
- parseFloat: false,
127
- parseInt: false,
128
- require: false,
129
- undefined: false,
130
137
  },
131
138
  rules: {
132
139
  'import/no-commonjs': 0,
@@ -194,6 +201,4 @@ function generate({
194
201
  ].filter(Boolean);
195
202
  }
196
203
 
197
- module.exports = {
198
- overrides: config.appid ? generate(config) : [],
199
- };
204
+ export default config.appid ? generate(config) : [];