@w5s/eslint-config 1.0.0-alpha.6 → 1.0.0-alpha.9

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/ignore.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ignorePatterns: ['**/dist/**', '**/lib/**'],
3
+ };
package/index.js CHANGED
@@ -1,11 +1,37 @@
1
1
  // http://eslint.org/docs/user-guide/configuring
2
+ /**
3
+ * @param {string} name
4
+ */
5
+ function tryResolve(name) {
6
+ try {
7
+ require.resolve(name);
8
+ return true;
9
+ } catch (_error) {
10
+ return false;
11
+ }
12
+ }
13
+
14
+ /**
15
+ * @template T
16
+ * @param {boolean} condition
17
+ * @param {T} value
18
+ */
19
+ function includeIf(condition, value) {
20
+ return condition ? [value] : [];
21
+ }
22
+
2
23
  module.exports = {
3
- extends: [require.resolve('./es'), require.resolve('./react'), require.resolve('./json')],
24
+ extends: [
25
+ require.resolve('./ignore'),
26
+ require.resolve('./es'),
27
+ require.resolve('./json'),
28
+ ...includeIf(tryResolve('react'), require.resolve('./react')),
29
+ ],
4
30
  overrides: [
5
- {
31
+ ...includeIf(tryResolve('typescript'), {
6
32
  extends: [require.resolve('./ts')],
7
33
  files: ['*.+(ts|tsx)'],
8
- },
34
+ }),
9
35
  {
10
36
  extends: [require.resolve('./jest')],
11
37
  files: [
@@ -13,6 +39,11 @@ module.exports = {
13
39
  '**/__tests__/**/*.+(ts|tsx|js|jsx)',
14
40
  '**/?(*.)+(spec|test).+(ts|tsx|js|jsx)',
15
41
  ],
42
+ settings: {
43
+ jest: {
44
+ version: 'latest',
45
+ },
46
+ },
16
47
  },
17
48
  ],
18
49
  root: true,
package/json.js CHANGED
@@ -1,4 +1,5 @@
1
1
  module.exports = {
2
+ ignorePatterns: ['**/tsconfig.json', '.vscode/**'], // To remove warning
2
3
  plugins: ['json-format'],
3
4
  settings: {
4
5
  'json/ignore-files': ['**/package-lock.json'],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@w5s/eslint-config",
3
- "version": "1.0.0-alpha.6",
3
+ "version": "1.0.0-alpha.9",
4
4
  "description": "ESLint configuration presets",
5
5
  "keywords": [
6
6
  "eslint",
@@ -55,7 +55,7 @@
55
55
  "eslint-plugin-prettier": "^4.0.0",
56
56
  "eslint-plugin-react": "^7.28.0",
57
57
  "eslint-plugin-total-functions": "^5.0.0",
58
- "eslint-plugin-unicorn": "^40.0.0"
58
+ "eslint-plugin-unicorn": "^41.0.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@babel/eslint-parser": "7.17.0",
@@ -83,5 +83,5 @@
83
83
  "publishConfig": {
84
84
  "access": "public"
85
85
  },
86
- "gitHead": "79cf1b971006e8a0255763db12dd46938d228c78"
86
+ "gitHead": "0bf05f35388f1ddb53438a017186cf64d2ce99f2"
87
87
  }
package/rules/_rule.js CHANGED
@@ -72,7 +72,7 @@ module.exports = {
72
72
  concatESConfig,
73
73
  error,
74
74
  // eslint-disable-next-line no-unused-vars
75
- fixme: (/** @type {'off'|'warn'|'error'} */ _status) => off,
75
+ fixme: (/** @type {'off'|'warn'|'error'|undefined} */ _status) => off,
76
76
  off,
77
77
  warn,
78
78
  };
package/rules/base.js CHANGED
@@ -34,6 +34,12 @@ module.exports = concatESConfig(
34
34
  // @ts-ignore
35
35
  ({ selector }) => selector !== 'ForOfStatement'
36
36
  ),
37
+ // underscore is often used (mongodb, etc)
38
+ 'no-underscore-dangle': off,
39
+ // Ignore underscore case arguments
40
+ 'no-unused-vars': [error, { argsIgnorePattern: '^_' }],
41
+ // Allow in some cases https://github.com/airbnb/javascript/issues/1089#issuecomment-1024351821
42
+ 'no-use-before-define': [error, 'nofunc'],
37
43
  },
38
44
  }
39
45
  );
package/rules/jest.js CHANGED
@@ -10,26 +10,21 @@ module.exports = concatESConfig(
10
10
  rules: {
11
11
  'jest/expect-expect': off, // Disabled because it does not handle functions that does the expect
12
12
  'jest/no-alias-methods': error,
13
- 'jest/no-commented-out-tests': error,
14
- 'jest/no-deprecated-functions': off,
15
- 'jest/no-disabled-tests': off,
16
- 'jest/no-done-callback': error,
17
- 'jest/no-export': off,
18
- 'jest/no-focused-tests': error,
19
- 'jest/no-identical-title': error,
20
- 'jest/no-restricted-matchers': [
21
- error,
22
- {
23
- toBeFalsy: 'Avoid `toBeFalsy`',
24
- toBeTruthy: 'Avoid `toBeTruthy`',
25
- },
26
- ],
27
13
  'jest/prefer-spy-on': error,
28
14
  'jest/prefer-to-contain': error,
29
- 'jest/valid-expect': error,
30
15
  'jest/valid-title': [error, { ignoreTypeOfDescribeName: true }],
31
16
  },
32
17
  },
18
+ /**
19
+ * Unicorn less strict to help writing tests
20
+ */
21
+ {
22
+ rules: {
23
+ 'unicorn/consistent-function-scoping': off,
24
+ 'unicorn/no-useless-undefined': off,
25
+ 'unicorn/prefer-module': off,
26
+ },
27
+ },
33
28
  /**
34
29
  * Typescript config is set to be less strict because we often have "hack", "mock" in tests
35
30
  */
package/rules/jsdoc.js CHANGED
@@ -1,20 +1,9 @@
1
- const { off, warn, error } = require('./_rule');
1
+ const { off } = require('./_rule');
2
2
 
3
3
  module.exports = {
4
+ extends: ['plugin:jsdoc/recommended'],
4
5
  plugins: ['jsdoc'],
5
6
  rules: {
6
- 'jsdoc/check-param-names': warn,
7
- 'jsdoc/check-tag-names': warn,
8
- 'jsdoc/check-types': warn,
9
- 'jsdoc/newline-after-description': [warn, 'always'],
10
- 'jsdoc/require-description': off,
11
- 'jsdoc/require-description-complete-sentence': off,
12
- 'jsdoc/require-hyphen-before-param-description': off,
13
- 'jsdoc/require-param': off,
14
- 'jsdoc/require-param-description': off,
15
- 'jsdoc/require-param-name': error,
16
- 'jsdoc/require-param-type': off,
17
- 'jsdoc/require-returns-description': off,
18
- 'jsdoc/require-returns-type': off,
7
+ 'jsdoc/require-jsdoc': off,
19
8
  },
20
9
  };
@@ -130,6 +130,18 @@ module.exports = concatESConfig(
130
130
  '@typescript-eslint/type-annotation-spacing': error,
131
131
  },
132
132
  },
133
+ /**
134
+ * JSDoc overrides
135
+ */
136
+ {
137
+ rules: {
138
+ 'jsdoc/no-types': error,
139
+ 'jsdoc/require-param': off,
140
+ 'jsdoc/require-param-type': off,
141
+ 'jsdoc/require-returns': off,
142
+ 'jsdoc/require-returns-type': off,
143
+ },
144
+ },
133
145
  /**
134
146
  * Import overrides
135
147
  */
@@ -214,7 +226,7 @@ module.exports = concatESConfig(
214
226
  'no-undef': off,
215
227
  'no-unreachable': off,
216
228
  'no-unsafe-negation': off,
217
- 'no-unused-expression': off,
229
+ 'no-unused-expressions': off,
218
230
  'no-unused-vars': off,
219
231
  'no-use-before-define': off,
220
232
  'no-useless-constructor': off,
package/rules/unicorn.js CHANGED
@@ -49,7 +49,10 @@ module.exports = concatESConfig(
49
49
  {
50
50
  rules: {
51
51
  'unicorn/consistent-destructuring': off,
52
+ 'unicorn/no-array-callback-reference': off, // Many false positive reported
52
53
  'unicorn/no-array-for-each': off, // This rule could change browser compatibility
54
+ 'unicorn/no-array-method-this-argument': off, // Many false positive reported
55
+ 'unicorn/no-array-reduce': off, // Array#reduce can be used
53
56
  'unicorn/no-object-as-default-parameter': off,
54
57
  'unicorn/prefer-default-parameters': off,
55
58
  'unicorn/prevent-abbreviations': off, // This rule is so dangerous : it potentially break code while fixing in many cases !!