@bhsd/code-standard 3.2.0 → 3.3.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.
Files changed (2) hide show
  1. package/eslint.js +64 -37
  2. package/package.json +3 -3
package/eslint.js CHANGED
@@ -14,6 +14,17 @@ import globals from 'globals';
14
14
 
15
15
  const tsRecommended = typescriptEslint.configs['flat/recommended-type-checked'],
16
16
  files = ['**/*.ts'];
17
+ const off = (rules, ruleNames) => {
18
+ const newRules = {...rules};
19
+ for (const ruleName of ruleNames) {
20
+ const name = `es-x/${ruleName}`;
21
+ if (!(name in newRules)) {
22
+ throw new RangeError(`Rule ${name} does not exist!`);
23
+ }
24
+ delete newRules[name];
25
+ }
26
+ return newRules;
27
+ };
17
28
  const getConfig = (rules, ecmaVersion) => ({
18
29
  languageOptions: {
19
30
  globals: globals.browser,
@@ -80,7 +91,6 @@ export const ignores = {
80
91
  'unicorn/no-array-from-fill': 2,
81
92
  'unicorn/no-array-method-this-argument': 2,
82
93
  'unicorn/no-array-reduce': 2,
83
- 'unicorn/no-array-splice': 2,
84
94
  'unicorn/no-await-in-promise-methods': 2,
85
95
  'unicorn/no-chained-comparison': 2,
86
96
  'unicorn/no-confusing-array-splice': 2,
@@ -107,7 +117,12 @@ export const ignores = {
107
117
  'unicorn/no-mismatched-map-key': 2,
108
118
  'unicorn/no-misrefactored-assignment': 2,
109
119
  'unicorn/no-named-default': 2,
110
- 'unicorn/no-negated-comparison': 2,
120
+ 'unicorn/no-negated-comparison': [
121
+ 2,
122
+ {
123
+ checkLogicalExpressions: true,
124
+ },
125
+ ],
111
126
  'unicorn/no-negated-condition': 2,
112
127
  'unicorn/no-negation-in-equality-check': 2,
113
128
  'unicorn/no-new-array': 2,
@@ -131,7 +146,6 @@ export const ignores = {
131
146
  'unicorn/no-unnecessary-fetch-options': 2,
132
147
  'unicorn/no-unnecessary-global-this': 2,
133
148
  'unicorn/no-unnecessary-splice': 2,
134
- 'unicorn/no-unreadable-iife': 2,
135
149
  'unicorn/no-unsafe-buffer-conversion': 2,
136
150
  'unicorn/no-unsafe-promise-all-settled-values': 2,
137
151
  'unicorn/no-unsafe-string-replacement': 2,
@@ -173,6 +187,12 @@ export const ignores = {
173
187
  'unicorn/prefer-class-fields': 2,
174
188
  'unicorn/prefer-classlist-toggle': 2,
175
189
  'unicorn/prefer-code-point': 2,
190
+ 'unicorn/prefer-continue': [
191
+ 2,
192
+ {
193
+ maximumStatements: 2,
194
+ },
195
+ ],
176
196
  'unicorn/prefer-default-parameters': 2,
177
197
  'unicorn/prefer-direct-iteration': 2,
178
198
  'unicorn/prefer-dispose': 2,
@@ -198,7 +218,13 @@ export const ignores = {
198
218
  'unicorn/prefer-math-abs': 2,
199
219
  'unicorn/prefer-math-constants': 2,
200
220
  'unicorn/prefer-math-min-max': 2,
201
- 'unicorn/prefer-minimal-ternary': 2,
221
+ 'unicorn/prefer-minimal-ternary': [
222
+ 2,
223
+ {
224
+ checkVaryingBase: true,
225
+ checkComputedMemberAccess: true,
226
+ },
227
+ ],
202
228
  'unicorn/prefer-native-coercion-functions': 2,
203
229
  'unicorn/prefer-negative-index': 2,
204
230
  'unicorn/prefer-number-is-safe-integer': 2,
@@ -226,7 +252,6 @@ export const ignores = {
226
252
  'unicorn/prefer-string-repeat': 2,
227
253
  'unicorn/prefer-string-replace-all': 2,
228
254
  'unicorn/prefer-string-starts-ends-with': 2,
229
- 'unicorn/prefer-structured-clone': 2,
230
255
  'unicorn/prefer-switch': 2,
231
256
  'unicorn/prefer-ternary': 2,
232
257
  'unicorn/prefer-toggle-attribute': 2,
@@ -249,6 +274,12 @@ export const ignores = {
249
274
  'unicorn/throw-new-error': 2,
250
275
  },
251
276
  },
277
+ unicornForNode = {
278
+ 'unicorn/no-array-reverse': 2,
279
+ 'unicorn/no-array-sort': 2,
280
+ 'unicorn/no-array-splice': 2,
281
+ 'unicorn/prefer-structured-clone': 2,
282
+ },
252
283
  general = [
253
284
  js.configs.recommended,
254
285
  promise.configs['flat/recommended'],
@@ -854,11 +885,7 @@ export const ignores = {
854
885
  },
855
886
  },
856
887
  },
857
- noUnicorn = {
858
- 'unicorn/no-array-reverse': 0,
859
- 'unicorn/no-array-sort': 0,
860
- ...Object.fromEntries(Object.keys(unicornConfigs.rules).map(rule => [rule, 0])),
861
- },
888
+ noUnicorn = Object.fromEntries(Object.keys({...unicornConfigs.rules, ...unicornForNode}).map(rule => [rule, 0])),
862
889
  json = [
863
890
  ...jsonc.configs['recommended-with-json'],
864
891
  {
@@ -1148,6 +1175,7 @@ export const ignores = {
1148
1175
  },
1149
1176
  {
1150
1177
  rules: {
1178
+ ...unicornForNode,
1151
1179
  'n/exports-style': [
1152
1180
  2,
1153
1181
  'module.exports',
@@ -1167,8 +1195,6 @@ export const ignores = {
1167
1195
  allowExperimental: true,
1168
1196
  },
1169
1197
  ],
1170
- 'unicorn/no-array-reverse': 2,
1171
- 'unicorn/no-array-sort': 2,
1172
1198
  },
1173
1199
  settings: {
1174
1200
  n: {
@@ -1210,40 +1236,41 @@ export const ignores = {
1210
1236
  'es-x/no-set-prototype-union': 2,
1211
1237
  'es-x/no-string-prototype-iswellformed': 2,
1212
1238
  'es-x/no-string-prototype-towellformed': 2,
1213
- 'unicorn/prefer-structured-clone': 0,
1214
1239
  }),
1215
1240
  browserES8 = getConfig({
1216
- ...esX.configs['flat/restrict-to-es2017'].rules,
1217
- 'es-x/no-array-prototype-flat': 0,
1218
- 'es-x/no-class-instance-fields': 0,
1219
- 'es-x/no-class-private-fields': 0,
1220
- 'es-x/no-class-private-methods': 0,
1221
- 'es-x/no-class-static-blocks': 0,
1222
- 'es-x/no-class-static-fields': 0,
1223
- 'es-x/no-private-in': 0,
1224
- 'es-x/no-logical-assignment-operators': 0,
1225
- 'es-x/no-numeric-separators': 0,
1226
- 'es-x/no-nullish-coalescing-operator': 0,
1227
- 'es-x/no-optional-chaining': 0,
1228
- 'es-x/no-optional-catch-binding': 0,
1229
- 'es-x/no-rest-spread-properties': 0,
1241
+ ...off(esX.configs['flat/restrict-to-es2017'].rules, [
1242
+ 'no-array-prototype-flat',
1243
+ 'no-class-instance-fields',
1244
+ 'no-class-private-fields',
1245
+ 'no-class-private-methods',
1246
+ 'no-class-static-block',
1247
+ 'no-class-static-fields',
1248
+ 'no-private-in',
1249
+ 'no-logical-assignment-operators',
1250
+ 'no-numeric-separators',
1251
+ 'no-nullish-coalescing-operators',
1252
+ 'no-optional-chaining',
1253
+ 'no-optional-catch-binding',
1254
+ 'no-rest-spread-properties',
1255
+ ]),
1230
1256
  'unicorn/prefer-array-last-methods': 0,
1231
1257
  'unicorn/prefer-at': 0,
1232
1258
  'unicorn/prefer-bigint-literals': 0,
1233
1259
  'unicorn/prefer-global-this': 0,
1234
1260
  'unicorn/prefer-object-from-entries': 0,
1235
1261
  'unicorn/prefer-string-replace-all': 0,
1236
- 'unicorn/prefer-structured-clone': 0,
1237
1262
  }),
1238
- dist = getConfig({
1239
- ...esX.configs['flat/restrict-to-es2022'].rules,
1240
- 'es-x/no-array-prototype-findlast-findlastindex': 0,
1241
- 'es-x/no-iterator-prototype-flatmap': 0,
1242
- }),
1243
- distES8 = getConfig({
1244
- ...esX.configs['flat/restrict-to-es2017'].rules,
1245
- 'es-x/no-array-prototype-flat': 0,
1246
- }, 8);
1263
+ dist = getConfig(off(
1264
+ esX.configs['flat/restrict-to-es2022'].rules,
1265
+ [
1266
+ 'no-array-prototype-findlast-findlastindex',
1267
+ 'no-iterator-prototype-flatmap',
1268
+ ],
1269
+ )),
1270
+ distES8 = getConfig(off(
1271
+ esX.configs['flat/restrict-to-es2017'].rules,
1272
+ ['no-array-prototype-flat'],
1273
+ ), 8);
1247
1274
 
1248
1275
  /**
1249
1276
  * 添加ESLint配置项
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/code-standard",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "homepage": "https://github.com/bhsd-harry/code-standard#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/bhsd-harry/code-standard/issues"
@@ -49,12 +49,12 @@
49
49
  "@typescript-eslint/eslint-plugin": "^8.64.0",
50
50
  "@typescript-eslint/parser": "^8.64.0",
51
51
  "eslint-plugin-es-x": "^10.0.0",
52
- "eslint-plugin-jsdoc": "^63.0.13",
52
+ "eslint-plugin-jsdoc": "^63.1.0",
53
53
  "eslint-plugin-jsonc": "^3.3.0",
54
54
  "eslint-plugin-n": "^18.2.2",
55
55
  "eslint-plugin-promise": "^7.3.0",
56
56
  "eslint-plugin-regexp": "^3.1.1",
57
- "eslint-plugin-unicorn": "^71.1.0",
57
+ "eslint-plugin-unicorn": "^72.0.0",
58
58
  "eslint-plugin-yml": "^3.6.0",
59
59
  "globals": "^17.7.0",
60
60
  "stylelint-plugin-use-baseline": "^1.4.4",