@w5s/eslint-config 1.0.0-alpha.2 → 1.0.0-alpha.20

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/es.js CHANGED
@@ -2,6 +2,7 @@
2
2
  module.exports = {
3
3
  extends: [
4
4
  require.resolve('./rules/base'),
5
+ require.resolve('./rules/promise'),
5
6
  require.resolve('./rules/jsdoc'),
6
7
  require.resolve('./rules/import'),
7
8
  require.resolve('./rules/unicorn'),
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 {
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.2",
3
+ "version": "1.0.0-alpha.20",
4
4
  "description": "ESLint configuration presets",
5
5
  "keywords": [
6
6
  "eslint",
@@ -27,8 +27,9 @@
27
27
  "build": "npm-run-all -p 'build:*'",
28
28
  "build:empty": ":",
29
29
  "docs": "md-magic --path '**/*.md' --ignore='node_modules'",
30
- "format": "eslint . --fix",
31
- "lint": "eslint .",
30
+ "format": "eslint . --fix --ext=mjs,cjs,js,jsx,ts,tsx,json",
31
+ "lint": "eslint . --ext=mjs,cjs,js,jsx,ts,tsx,json",
32
+ "spellcheck": "cspell --no-progress '**'",
32
33
  "test": "scripts/test"
33
34
  },
34
35
  "eslintConfig": {
@@ -45,36 +46,44 @@
45
46
  "@babel/plugin-syntax-jsx": "^7.0.0",
46
47
  "@typescript-eslint/eslint-plugin": "^5.0.0",
47
48
  "@typescript-eslint/parser": "^5.0.0",
49
+ "eslint-config-airbnb-base": "^15.0.0",
48
50
  "eslint-config-prettier": "^8.0.0",
49
51
  "eslint-plugin-functional": "^4.2.0",
50
52
  "eslint-plugin-import": "^2.25.0",
51
53
  "eslint-plugin-jest": "^26.0.0",
52
- "eslint-plugin-jsdoc": "^37.0.0",
54
+ "eslint-plugin-jsdoc": "^39.0.0",
53
55
  "eslint-plugin-json-format": "^2.0.1",
54
56
  "eslint-plugin-prettier": "^4.0.0",
57
+ "eslint-plugin-promise": "^6.0.0",
55
58
  "eslint-plugin-react": "^7.28.0",
56
59
  "eslint-plugin-total-functions": "^5.0.0",
57
- "eslint-plugin-unicorn": "^40.0.0"
60
+ "eslint-plugin-unicorn": "^42.0.0"
58
61
  },
59
62
  "devDependencies": {
60
- "@babel/eslint-parser": "7.17.0",
63
+ "@babel/eslint-parser": "7.18.2",
61
64
  "@types/eslint": "8.4.1",
62
65
  "@types/eslint-plugin-prettier": "^3.1.0",
63
66
  "@types/prettier": "2.4.4",
64
67
  "@types/react": "17.0.2",
65
- "@typescript-eslint/parser": "5.11.0",
66
- "eslint": "8.9.0",
67
- "eslint-config-prettier": "8.3.0",
68
+ "@typescript-eslint/parser": "5.27.1",
69
+ "eslint": "8.17.0",
70
+ "eslint-config-prettier": "8.5.0",
68
71
  "eslint-index": "1.5.0",
69
- "prettier": "2.5.1",
70
- "react": "17.0.2"
72
+ "prettier": "2.6.2",
73
+ "react": "18.1.0"
71
74
  },
72
75
  "peerDependencies": {
73
76
  "eslint": "5.x || 6.x || 7.x || 8.x",
74
- "prettier": "2.x"
77
+ "prettier": "2.x",
78
+ "typescript": "4.x"
79
+ },
80
+ "peerDependenciesMeta": {
81
+ "typescript": {
82
+ "optional": true
83
+ }
75
84
  },
76
85
  "publishConfig": {
77
86
  "access": "public"
78
87
  },
79
- "gitHead": "1fd5f03e6f071785cc5be4f9a57430485cf9d6fc"
88
+ "gitHead": "02b48fa163171d16c982ff0c4bae8156db13f891"
80
89
  }
package/rules/_rule.js CHANGED
@@ -7,9 +7,72 @@ const warn = 'warn';
7
7
  /** @type {'off'} */
8
8
  const off = 'off';
9
9
 
10
+ /**
11
+ * @typedef {{
12
+ * env?: Record<string, boolean>,
13
+ * extends?: string[]|string,
14
+ * plugins?: string[]|string,
15
+ * rules?: Record<string, unknown>,
16
+ * settings?: Record<string, unknown>,
17
+ * }} ESLintConfigInit
18
+ */
19
+ /**
20
+ * @typedef {{
21
+ * env: Record<string, boolean>,
22
+ * extends: string[],
23
+ * plugins: string[],
24
+ * rules: Record<string, unknown>,
25
+ * settings: Record<string, unknown>,
26
+ * }} ESLintConfig
27
+ */
28
+
29
+ /**
30
+ * @template T
31
+ @type {(value: T[]|T|undefined) => T[]} */
32
+ function toArray(value) {
33
+ if (value == null) {
34
+ return [];
35
+ }
36
+ if (Array.isArray(value)) {
37
+ return value;
38
+ }
39
+ return [value];
40
+ }
41
+
42
+ /**
43
+ * @template T
44
+ * @type {(left: T[]|T|undefined, right:T[]|T|undefined) => T[]}
45
+ */
46
+ function concatArray(left, right) {
47
+ return toArray(left).concat(toArray(right));
48
+ }
49
+
50
+ /** @type {(...configs: ESLintConfigInit[]) => ESLintConfig} */
51
+ function concatESConfig(...configs) {
52
+ return configs.reduce(
53
+ (/** @type {ESLintConfig} */ returnValue, /** @type {ESLintConfigInit} */ config) =>
54
+ Object.assign({}, returnValue, config, {
55
+ env: Object.assign({}, returnValue.env, config.env),
56
+ extends: concatArray(returnValue.extends, config.extends),
57
+ plugins: concatArray(returnValue.plugins, config.plugins),
58
+ rules: Object.assign({}, returnValue.rules, config.rules),
59
+ settings: Object.assign({}, returnValue.settings, config.settings),
60
+ }),
61
+ {
62
+ env: {},
63
+ extends: [],
64
+ plugins: [],
65
+ rules: {},
66
+ settings: {},
67
+ }
68
+ );
69
+ }
70
+
10
71
  module.exports = {
72
+ concatESConfig,
11
73
  error,
12
- fixme: (/** @type {'off'|'warn'|'error'} */ _status) => off,
74
+ // eslint-disable-next-line no-unused-vars
75
+ fixme: (/** @type {'off'|'warn'|'error'|undefined} */ _status) => off,
13
76
  off,
14
77
  warn,
15
78
  };