@nice-move/eslint-config-base 0.5.66 → 0.5.70

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/lib/base.cjs CHANGED
@@ -13,15 +13,17 @@ module.exports = {
13
13
  env: {
14
14
  browser: true,
15
15
  es2021: true,
16
+ es2020: true,
17
+ es2017: true,
16
18
  commonjs: false,
17
19
  node: false,
18
20
  },
19
21
  plugins: ['eslint-comments'],
20
22
  extends: ['plugin:sonarjs/recommended'],
21
23
  rules: {
22
- 'sonarjs/cognitive-complexity': 'off',
23
- 'sonarjs/no-duplicate-string': 'off',
24
- 'sonarjs/no-identical-functions': 'off',
24
+ 'sonarjs/cognitive-complexity': 0,
25
+ 'sonarjs/no-duplicate-string': 0,
26
+ 'sonarjs/no-identical-functions': 0,
25
27
  'array-callback-return': [
26
28
  'error',
27
29
  {
@@ -29,18 +31,22 @@ module.exports = {
29
31
  checkForEach: true,
30
32
  },
31
33
  ],
32
- 'no-useless-rename': 'off',
33
- 'object-shorthand': 'off',
34
- 'arrow-body-style': 'off',
35
- camelcase: 'off',
34
+ 'no-useless-rename': 0,
35
+ 'object-shorthand': 0,
36
+ 'arrow-body-style': 0,
37
+ camelcase: 0,
36
38
  'class-methods-use-this': 'warn',
37
39
  'consistent-return': 'warn',
38
40
  'eslint-comments/no-unused-disable': 'warn',
39
41
  'eslint-comments/no-unused-enable': 'warn',
40
- 'global-require': 'off',
41
- 'lines-between-class-members': 'off',
42
- 'max-classes-per-file': 'off',
43
- 'no-console': 'off',
42
+ 'global-require': 0,
43
+ 'no-unreachable-loop': 0,
44
+ 'grouped-accessor-pairs': 0,
45
+ 'no-constructor-return': 0,
46
+ 'lines-between-class-members': 0,
47
+ 'max-classes-per-file': 0,
48
+ 'no-console': 0,
49
+ 'prefer-exponentiation-operator': 0,
44
50
  'no-empty': [
45
51
  'error',
46
52
  {
@@ -53,7 +59,7 @@ module.exports = {
53
59
  disallowTemplateShorthand: true,
54
60
  },
55
61
  ],
56
- 'no-nested-ternary': 'off',
62
+ 'no-nested-ternary': 0,
57
63
  'no-param-reassign': [
58
64
  'warn',
59
65
  { props: true, ignorePropertyModificationsFor: [] },
@@ -72,9 +78,9 @@ module.exports = {
72
78
  selector: 'LabeledStatement',
73
79
  },
74
80
  ],
75
- 'no-template-curly-in-string': 'off',
76
- 'no-undef-init': 'off',
77
- 'no-underscore-dangle': 'off',
81
+ 'no-template-curly-in-string': 0,
82
+ 'no-undef-init': 0,
83
+ 'no-underscore-dangle': 0,
78
84
  'no-unused-vars': [
79
85
  'error',
80
86
  {
@@ -85,7 +91,7 @@ module.exports = {
85
91
  ],
86
92
  'prefer-arrow-callback': 'warn',
87
93
  'prefer-template': 'warn',
88
- 'spaced-comment': 'off',
94
+ 'spaced-comment': 0,
89
95
  },
90
96
  overrides: [
91
97
  {
package/lib/bundler.cjs CHANGED
@@ -1,55 +1,58 @@
1
1
  'use strict';
2
2
 
3
3
  const {
4
- existThenReturn,
5
- safeGet,
6
4
  matches: { source, sourceAndPackages },
7
5
  } = require('./utils.cjs');
8
6
 
7
+ const { reaching, isReachable } = require('settingz');
8
+
9
9
  function BestShot() {
10
- return existThenReturn('@best-shot/preset-env/package.json', () => [
11
- {
12
- files: sourceAndPackages,
13
- ...(safeGet('@best-shot/preset-env/eslint.cjs') ||
14
- safeGet('@best-shot/preset-env/eslint.js')),
15
- },
16
- ]);
10
+ return isReachable('@best-shot/preset-env/package.json')
11
+ ? [
12
+ {
13
+ files: sourceAndPackages,
14
+ ...reaching('@best-shot/preset-env/eslint.cjs'),
15
+ },
16
+ ]
17
+ : [];
17
18
  }
18
19
 
19
20
  function webpack() {
20
- return existThenReturn('webpack/package.json', () => [
21
- {
22
- files: sourceAndPackages,
23
- excludedFiles: ['*.mjs', '*.cjs', '*.html', '*.htm'],
24
- globals: {
25
- __resourceAndPackagesQuery: 'readonly',
26
- __non_webpack_require__: 'readonly',
27
- module: 'readonly',
28
- require: 'readonly',
29
- },
30
- rules: {
31
- 'import/no-commonjs': 'warn',
32
- },
33
- },
34
- {
35
- files: sourceAndPackages,
36
- excludedFiles: ['*.html', '*.htm'],
37
- globals: {
38
- __dirname: 'readonly',
39
- __filename: 'readonly',
40
- },
41
- },
42
- {
43
- files: source,
44
- excludedFiles: ['*.html', '*.htm'],
45
- globals: {
46
- __webpack_public_path__: true,
47
- __webpack_base_uri__: true,
48
- },
49
- },
50
- ]);
21
+ return isReachable('webpack/package.json')
22
+ ? [
23
+ {
24
+ files: sourceAndPackages,
25
+ excludedFiles: ['*.mjs', '*.cjs', '*.html', '*.htm'],
26
+ globals: {
27
+ __resourceAndPackagesQuery: 'readonly',
28
+ __non_webpack_require__: 'readonly',
29
+ module: 'readonly',
30
+ require: 'readonly',
31
+ },
32
+ rules: {
33
+ 'import/no-commonjs': 'warn',
34
+ },
35
+ },
36
+ {
37
+ files: sourceAndPackages,
38
+ excludedFiles: ['*.html', '*.htm'],
39
+ globals: {
40
+ __dirname: 'readonly',
41
+ __filename: 'readonly',
42
+ },
43
+ },
44
+ {
45
+ files: source,
46
+ excludedFiles: ['*.html', '*.htm'],
47
+ globals: {
48
+ __webpack_public_path__: true,
49
+ __webpack_base_uri__: true,
50
+ },
51
+ },
52
+ ]
53
+ : [];
51
54
  }
52
55
 
53
56
  module.exports = {
54
- overrides: [...(webpack() || []), ...(BestShot() || [])],
57
+ overrides: [...webpack(), ...BestShot()],
55
58
  };
package/lib/html.cjs CHANGED
@@ -3,10 +3,10 @@
3
3
  module.exports = {
4
4
  overrides: [
5
5
  {
6
- files: ['.html', '.htm'],
6
+ files: ['*.html', '*.htm', '*.svg'],
7
7
  plugins: ['html'],
8
8
  settings: {
9
- 'html/html-extensions': ['.html', '.htm'],
9
+ 'html/html-extensions': ['.html', '.htm', '.svg'],
10
10
  },
11
11
  },
12
12
  ],
package/lib/import.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { join } = require('path');
4
4
 
5
- const { pkgHas, configHas, existThenReturn } = require('./utils.cjs');
5
+ const { pkgHas, configHas } = require('./utils.cjs');
6
6
 
7
7
  const Vscode = pkgHas(
8
8
  ({ engines: { vscode } = {} }) => vscode,
@@ -33,23 +33,15 @@ module.exports = {
33
33
  ],
34
34
  },
35
35
  ],
36
- 'import/newline-after-import': 'off',
37
- 'import/no-dynamic-require': 'off',
38
- 'import/order': 'off',
39
- 'import/prefer-default-export': 'off',
36
+ 'import/newline-after-import': 0,
37
+ 'import/no-dynamic-require': 0,
38
+ 'import/order': 0,
39
+ 'import/prefer-default-export': 0,
40
+ 'import/no-relative-packages': 0,
40
41
  },
41
42
  settings: {
42
43
  ...Vscode,
43
- 'import/extensions': [
44
- '.tsx',
45
- '.ts',
46
- ...(existThenReturn('vue-eslint-parser/package.json', () => ['.vue']) ||
47
- []),
48
- '.jsx',
49
- '.js',
50
- '.mjs',
51
- '.cjs',
52
- ],
44
+ 'import/extensions': ['.tsx', '.ts', '.vue', '.jsx', '.js', '.mjs', '.cjs'],
53
45
  'import/parsers': {
54
46
  '@typescript-eslint/parser': ['.ts', '.tsx'],
55
47
  'vue-eslint-parser': ['.vue'],
package/lib/mini.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  const { relative } = require('path');
4
4
 
5
- const { projectHasConfig } = require('./utils.cjs');
5
+ const { reaching } = require('settingz');
6
6
 
7
7
  const cwd = process.cwd();
8
8
 
@@ -16,98 +16,110 @@ function matcher(paths, globs) {
16
16
  : `{${paths.join(',')}}/${globs}`;
17
17
  }
18
18
 
19
- module.exports = {
20
- ...projectHasConfig(({ miniprogramRoot, pluginRoot, cloudfunctionRoot }) => {
21
- const paths = [miniprogramRoot, pluginRoot]
22
- .filter(Boolean)
23
- .map((item) => relativeToCWD(item));
19
+ const config = reaching('./project.config.json');
20
+
21
+ function generate({ miniprogramRoot, pluginRoot, cloudfunctionRoot }) {
22
+ const paths = [miniprogramRoot, pluginRoot]
23
+ .filter(Boolean)
24
+ .map((item) => relativeToCWD(item));
24
25
 
25
- const excludedFiles = ['*.wxs', '*.qs'];
26
+ const excludedFiles = ['*.wxs', '*.qs'];
26
27
 
27
- const cloudMatcher = cloudfunctionRoot
28
- ? matcher([relativeToCWD(cloudfunctionRoot)], '**')
29
- : undefined;
28
+ const cloudMatcher = cloudfunctionRoot
29
+ ? matcher([relativeToCWD(cloudfunctionRoot)], '**')
30
+ : undefined;
30
31
 
31
- const globals = {
32
- clearInterval: 'readonly',
33
- clearTimeout: 'readonly',
34
- console: 'readonly',
35
- setInterval: 'readonly',
36
- setTimeout: 'readonly',
37
- };
32
+ const globals = {
33
+ clearInterval: 'readonly',
34
+ clearTimeout: 'readonly',
35
+ console: 'readonly',
36
+ setInterval: 'readonly',
37
+ setTimeout: 'readonly',
38
+ };
38
39
 
39
- return {
40
- overrides: [
41
- {
42
- files: matcher(paths, '**'),
43
- excludedFiles,
40
+ return [
41
+ {
42
+ files: matcher(paths, '**'),
43
+ excludedFiles,
44
+ env: {
45
+ browser: false,
46
+ },
47
+ globals: {
48
+ ...globals,
49
+ wx: 'readonly',
50
+ getApp: 'readonly',
51
+ getCurrentPages: 'readonly',
52
+ requirePlugin: 'readonly',
53
+ requireMiniProgram: 'readonly',
54
+ },
55
+ },
56
+ {
57
+ files: matcher(paths, 'component{,s}/**'),
58
+ excludedFiles,
59
+ globals: {
60
+ Component: 'readonly',
61
+ Behavior: 'readonly',
62
+ },
63
+ },
64
+ {
65
+ files: matcher(paths, 'page{,s}/**'),
66
+ excludedFiles,
67
+ globals: {
68
+ Page: 'readonly',
69
+ },
70
+ },
71
+ {
72
+ files: matcher(paths, 'app.js'),
73
+ globals: {
74
+ App: 'readonly',
75
+ },
76
+ },
77
+ cloudMatcher
78
+ ? {
79
+ files: [cloudMatcher],
44
80
  env: {
45
81
  browser: false,
46
82
  },
47
83
  globals: {
48
84
  ...globals,
49
- wx: 'readonly',
50
- getApp: 'readonly',
51
- getCurrentPages: 'readonly',
52
- requirePlugin: 'readonly',
53
- requireMiniProgram: 'readonly',
54
- },
55
- },
56
- {
57
- files: matcher(paths, 'component{,s}/**'),
58
- excludedFiles,
59
- globals: {
60
- Component: 'readonly',
61
- Behavior: 'readonly',
62
- },
63
- },
64
- {
65
- files: matcher(paths, 'page{,s}/**'),
66
- excludedFiles,
67
- globals: {
68
- Page: 'readonly',
69
- },
70
- },
71
- {
72
- files: matcher(paths, 'app.js'),
73
- globals: {
74
- App: 'readonly',
75
- },
76
- },
77
- cloudMatcher
78
- ? {
79
- files: [cloudMatcher],
80
- env: {
81
- browser: false,
82
- },
83
- globals: {
84
- ...globals,
85
- require: 'readonly',
86
- exports: 'readonly',
87
- },
88
- rules: {
89
- 'import/no-commonjs': 'off',
90
- 'unicorn/prefer-module': 'off',
91
- },
92
- }
93
- : undefined,
94
- {
95
- files: excludedFiles,
96
- env: {
97
- browser: false,
98
- },
99
- globals: {
100
85
  require: 'readonly',
101
- module: 'readonly',
86
+ exports: 'readonly',
102
87
  },
103
88
  rules: {
104
- 'no-var': 'off',
105
- 'object-shorthand': ['error', 'never'],
106
89
  'import/no-commonjs': 'off',
107
90
  'unicorn/prefer-module': 'off',
108
91
  },
109
- },
110
- ].filter(Boolean),
111
- };
112
- }),
92
+ }
93
+ : undefined,
94
+ {
95
+ files: excludedFiles,
96
+ env: {
97
+ browser: false,
98
+ es2021: false,
99
+ es2020: false,
100
+ es2017: false,
101
+ es6: false,
102
+ },
103
+ parserOptions: {
104
+ ecmaVersion: 5,
105
+ },
106
+ globals: {
107
+ require: 'readonly',
108
+ module: 'readonly',
109
+ },
110
+ rules: {
111
+ 'import/no-commonjs': 0,
112
+ 'no-var': 0,
113
+ 'object-shorthand': ['error', 'never'],
114
+ 'prefer-spread': 0,
115
+ 'prefer-template': 0,
116
+ 'unicorn/prefer-includes': 0,
117
+ 'unicorn/prefer-module': 0,
118
+ },
119
+ },
120
+ ].filter(Boolean);
121
+ }
122
+
123
+ module.exports = {
124
+ overrides: config.appid ? generate(config) : [],
113
125
  };
package/lib/node.cjs CHANGED
@@ -69,8 +69,8 @@ module.exports = {
69
69
  },
70
70
  },
71
71
  {
72
- files: '*.{js,ts,jsx,tsx,vue,html,htm}',
73
- excludedFiles: ['**/*.md/*'],
72
+ files: '*.*',
73
+ excludedFiles: ['**/*.md/*', '*.mjs', '*.cjs', '*.md'],
74
74
  rules: {
75
75
  'node/file-extension-in-import': 'error',
76
76
  },
package/lib/test.cjs CHANGED
@@ -1,17 +1,22 @@
1
1
  'use strict';
2
2
 
3
- const { existThenReturn } = require('./utils.cjs');
3
+ const { reaching } = require('settingz');
4
+
5
+ const { configs: { recommended: { rules } = {} } = {} } = reaching(
6
+ 'eslint-plugin-ava/index.js',
7
+ );
4
8
 
5
9
  module.exports = {
6
- overrides: [
7
- existThenReturn('eslint-plugin-ava/package.json', () => ({
8
- files: [
9
- '**/{test,tests,spec,specs}/*.{m,c,}js',
10
- '*.{test,spec}.{m,c,}js}',
11
- ],
12
- plugins: ['ava'],
13
- // eslint-disable-next-line import/no-extraneous-dependencies
14
- rules: require('eslint-plugin-ava/index.js').configs.recommended.rules,
15
- })),
16
- ].filter(Boolean),
10
+ overrides: rules
11
+ ? [
12
+ {
13
+ files: [
14
+ '**/{test,tests,spec,specs}/*.{m,c,}js',
15
+ '*.{test,spec}.{m,c,}js}',
16
+ ],
17
+ plugins: ['ava'],
18
+ rules,
19
+ },
20
+ ]
21
+ : [],
17
22
  };
package/lib/utils.cjs CHANGED
@@ -1,66 +1,30 @@
1
1
  'use strict';
2
2
 
3
- const { resolve } = require('path');
4
-
5
- function isSafeError(error) {
6
- return (
7
- error.code === 'MODULE_NOT_FOUND' && error.requireStack[0] === __filename
8
- );
9
- }
10
-
11
- // eslint-disable-next-line consistent-return
12
- function existThenReturn(checker, getResult) {
13
- try {
14
- require.resolve(checker);
15
- return getResult();
16
- } catch (error) {
17
- if (!isSafeError(error)) {
18
- throw error;
19
- }
20
- }
21
- }
22
-
23
- function safeGet(name) {
24
- try {
25
- return require(name);
26
- } catch (error) {
27
- if (isSafeError(error)) {
28
- return {};
29
- }
30
- throw error;
31
- }
32
- }
33
-
34
- const cwd = process.cwd();
35
-
36
- const pkg = safeGet(resolve(cwd, 'package.json'));
3
+ const { getPkg } = require('settingz');
37
4
 
38
5
  // eslint-disable-next-line consistent-return
39
6
  function pkgHas(checker, getResult) {
7
+ const pkg = getPkg();
8
+
40
9
  const io = checker(pkg);
41
10
  if (io) {
42
11
  return getResult(io, pkg);
43
12
  }
44
13
  }
45
14
 
15
+ // eslint-disable-next-line consistent-return
46
16
  function configHas(checker, getResult) {
47
- return pkgHas(({ 'nice-move': config = {} }) => checker(config), getResult);
48
- }
17
+ const pkg = getPkg('nice-move');
49
18
 
50
- // eslint-disable-next-line consistent-return
51
- function projectHasConfig(getResult) {
52
- const config = safeGet(resolve(cwd, 'project.config.json'));
53
- if (config.appid) {
54
- return getResult(config);
19
+ const io = checker(pkg);
20
+ if (io) {
21
+ return getResult(io, pkg);
55
22
  }
56
23
  }
57
24
 
58
25
  module.exports = {
59
- configHas,
60
26
  pkgHas,
61
- safeGet,
62
- existThenReturn,
63
- projectHasConfig,
27
+ configHas,
64
28
  matches: {
65
29
  sourceAndPackages: '{src,packages/*}/**',
66
30
  source: 'src/**',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice-move/eslint-config-base",
3
- "version": "0.5.66",
3
+ "version": "0.5.70",
4
4
  "description": "A `eslint` config for best practice",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -34,19 +34,20 @@
34
34
  },
35
35
  "main": "index.cjs",
36
36
  "dependencies": {
37
- "@typescript-eslint/eslint-plugin": "^5.2.0",
38
- "@typescript-eslint/parser": "^5.2.0",
39
- "eslint-config-airbnb-base": "^14.2.1",
37
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
38
+ "@typescript-eslint/parser": "^5.4.0",
39
+ "eslint-config-airbnb-base": "^15.0.0",
40
40
  "eslint-config-prettier": "^8.3.0",
41
41
  "eslint-plugin-eslint-comments": "^3.2.0",
42
42
  "eslint-plugin-html": "^6.2.0",
43
- "eslint-plugin-import": "^2.25.2",
43
+ "eslint-plugin-import": "^2.25.3",
44
44
  "eslint-plugin-markdown": "^2.2.1",
45
45
  "eslint-plugin-node": "^11.1.0",
46
46
  "eslint-plugin-promise": "^5.1.1",
47
47
  "eslint-plugin-sonarjs": "^0.10.0",
48
- "eslint-plugin-unicorn": "^37.0.1",
49
- "espree": "9.0.0"
48
+ "eslint-plugin-unicorn": "^39.0.0",
49
+ "espree": "9.1.0",
50
+ "settingz": "^0.1.0"
50
51
  },
51
52
  "peerDependencies": {
52
53
  "eslint": "^7.32.0"