@so1ve/eslint-plugin 0.43.0 → 0.43.1

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/dist/index.cjs CHANGED
@@ -118,6 +118,7 @@ const genericSpacing = createEslintRule({
118
118
  }
119
119
  }
120
120
  },
121
+ // add space around = in type Foo<T = true>
121
122
  TSTypeParameter: (node) => {
122
123
  if (!node.default) {
123
124
  return;
@@ -168,6 +169,7 @@ const genericSpacing = createEslintRule({
168
169
  }
169
170
  }
170
171
  },
172
+ // type T = Generic< any >
171
173
  TSTypeParameterInstantiation: (node) => {
172
174
  const params = node.params;
173
175
  for (let i = 0; i < params.length; i++) {
@@ -217,6 +219,10 @@ const genericSpacing = createEslintRule({
217
219
  }
218
220
  }
219
221
  },
222
+ // Add spaces before extends
223
+ // interface a {}
224
+ // interface A<B extends 1>extends a {}
225
+ // Fix to: interface A<B extends 1> extends a {}
220
226
  TSInterfaceDeclaration: (node) => {
221
227
  if (!node.extends || !node.typeParameters) {
222
228
  return;
@@ -299,6 +305,7 @@ const importDedupe = createEslintRule({
299
305
  }
300
306
  });
301
307
 
308
+ const operatorOrAnyBracketOrKeywordRE = /^(\||&|\*|\+|\-|\/|%|<|>|<=|>=|==|!=|===|!==|\[|\(|\{|as|extends|implements|keyof|new|readonly|typeof|unique|unknown)/;
302
309
  const RULE_NAME$4 = "space-between-generic-and-paren";
303
310
  const spaceBetweenGenericAndParen = createEslintRule({
304
311
  name: RULE_NAME$4,
@@ -326,8 +333,8 @@ const spaceBetweenGenericAndParen = createEslintRule({
326
333
  const postEqual = post.slice(postSpace.length).match(/^(=)/)?.[0];
327
334
  const postComma = text.slice(node.range[1]).match(/^(,)/)?.[0];
328
335
  const postQuestionMark = text.slice(spaceStartRange + postSpace.length).match(/^(\?)/)?.[0];
329
- const postOperatorOrAnyBracketOrKeyword = text.slice(spaceStartRange + postSpace.length).match(/^(\||&|\*|\+|\-|\/|%|<|>|<=|>=|==|!=|===|!==|\[|\(|\{|as|extends|implements|keyof|new|readonly|typeof|unique|unknown)/)?.[0];
330
- if (postSpace && postSpace.length && !postEqual && !postComma && !postQuestionMark && !postOperatorOrAnyBracketOrKeyword) {
336
+ const postOperatorOrAnyBracketOrKeyword = text.slice(spaceStartRange + postSpace.length).match(operatorOrAnyBracketOrKeywordRE)?.[0];
337
+ if (postSpace && postSpace.length && !postEqual && !postComma && !postQuestionMark && !postOperatorOrAnyBracketOrKeyword && node.parent.type !== "TSInferType") {
331
338
  context.report({
332
339
  loc: {
333
340
  start: {
package/dist/index.mjs CHANGED
@@ -116,6 +116,7 @@ const genericSpacing = createEslintRule({
116
116
  }
117
117
  }
118
118
  },
119
+ // add space around = in type Foo<T = true>
119
120
  TSTypeParameter: (node) => {
120
121
  if (!node.default) {
121
122
  return;
@@ -166,6 +167,7 @@ const genericSpacing = createEslintRule({
166
167
  }
167
168
  }
168
169
  },
170
+ // type T = Generic< any >
169
171
  TSTypeParameterInstantiation: (node) => {
170
172
  const params = node.params;
171
173
  for (let i = 0; i < params.length; i++) {
@@ -215,6 +217,10 @@ const genericSpacing = createEslintRule({
215
217
  }
216
218
  }
217
219
  },
220
+ // Add spaces before extends
221
+ // interface a {}
222
+ // interface A<B extends 1>extends a {}
223
+ // Fix to: interface A<B extends 1> extends a {}
218
224
  TSInterfaceDeclaration: (node) => {
219
225
  if (!node.extends || !node.typeParameters) {
220
226
  return;
@@ -297,6 +303,7 @@ const importDedupe = createEslintRule({
297
303
  }
298
304
  });
299
305
 
306
+ const operatorOrAnyBracketOrKeywordRE = /^(\||&|\*|\+|\-|\/|%|<|>|<=|>=|==|!=|===|!==|\[|\(|\{|as|extends|implements|keyof|new|readonly|typeof|unique|unknown)/;
300
307
  const RULE_NAME$4 = "space-between-generic-and-paren";
301
308
  const spaceBetweenGenericAndParen = createEslintRule({
302
309
  name: RULE_NAME$4,
@@ -324,8 +331,8 @@ const spaceBetweenGenericAndParen = createEslintRule({
324
331
  const postEqual = post.slice(postSpace.length).match(/^(=)/)?.[0];
325
332
  const postComma = text.slice(node.range[1]).match(/^(,)/)?.[0];
326
333
  const postQuestionMark = text.slice(spaceStartRange + postSpace.length).match(/^(\?)/)?.[0];
327
- const postOperatorOrAnyBracketOrKeyword = text.slice(spaceStartRange + postSpace.length).match(/^(\||&|\*|\+|\-|\/|%|<|>|<=|>=|==|!=|===|!==|\[|\(|\{|as|extends|implements|keyof|new|readonly|typeof|unique|unknown)/)?.[0];
328
- if (postSpace && postSpace.length && !postEqual && !postComma && !postQuestionMark && !postOperatorOrAnyBracketOrKeyword) {
334
+ const postOperatorOrAnyBracketOrKeyword = text.slice(spaceStartRange + postSpace.length).match(operatorOrAnyBracketOrKeywordRE)?.[0];
335
+ if (postSpace && postSpace.length && !postEqual && !postComma && !postQuestionMark && !postOperatorOrAnyBracketOrKeyword && node.parent.type !== "TSInferType") {
329
336
  context.report({
330
337
  loc: {
331
338
  start: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "0.43.0",
3
+ "version": "0.43.1",
4
4
  "author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
5
5
  "contributors": [
6
6
  {
@@ -31,14 +31,14 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@typescript-eslint/utils": "^5.48.0",
34
+ "@typescript-eslint/utils": "^5.49.0",
35
35
  "@vue/reactivity": "^3.2.45",
36
- "eslint-define-config": "^1.13.0"
36
+ "eslint-define-config": "^1.14.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^18.11.18",
40
- "unbuild": "^1.0.2",
41
- "vitest": "^0.26.3"
40
+ "unbuild": "^1.1.1",
41
+ "vitest": "^0.28.3"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "rimraf dist && unbuild",