eslint-plugin-kirklin 0.1.9 → 0.2.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 +82 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +82 -1
- package/package.json +5 -4
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,86 @@ const createEslintRule = utils.ESLintUtils.RuleCreator(
|
|
|
6
6
|
(ruleName) => ruleName
|
|
7
7
|
);
|
|
8
8
|
|
|
9
|
+
const RULE_NAME$3 = "generic-spacing";
|
|
10
|
+
const genericSpacing = createEslintRule({
|
|
11
|
+
name: RULE_NAME$3,
|
|
12
|
+
meta: {
|
|
13
|
+
type: "suggestion",
|
|
14
|
+
docs: {
|
|
15
|
+
description: "Spaces around generic type parameters",
|
|
16
|
+
recommended: "error"
|
|
17
|
+
},
|
|
18
|
+
fixable: "code",
|
|
19
|
+
schema: [],
|
|
20
|
+
messages: {
|
|
21
|
+
genericSpacingMismatch: "Generic spaces mismatch"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
defaultOptions: [],
|
|
25
|
+
create: (context) => {
|
|
26
|
+
const sourceCode = context.getSourceCode();
|
|
27
|
+
return {
|
|
28
|
+
TSTypeParameterDeclaration: (node) => {
|
|
29
|
+
if (!["TSCallSignatureDeclaration", "ArrowFunctionExpression", "TSFunctionType"].includes(node.parent.type)) {
|
|
30
|
+
const pre = sourceCode.text.slice(0, node.range[0]);
|
|
31
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
32
|
+
if (preSpace && preSpace.length) {
|
|
33
|
+
context.report({
|
|
34
|
+
node,
|
|
35
|
+
messageId: "genericSpacingMismatch",
|
|
36
|
+
*fix(fixer) {
|
|
37
|
+
yield fixer.replaceTextRange([node.range[0] - preSpace.length, node.range[0]], "");
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const params = node.params;
|
|
43
|
+
for (let i = 1; i < params.length; i++) {
|
|
44
|
+
const prev = params[i - 1];
|
|
45
|
+
const current = params[i];
|
|
46
|
+
const from = prev.range[1];
|
|
47
|
+
const to = current.range[0];
|
|
48
|
+
const span = sourceCode.text.slice(from, to);
|
|
49
|
+
if (span !== ", " && !span.match(/,\n/)) {
|
|
50
|
+
context.report({
|
|
51
|
+
*fix(fixer) {
|
|
52
|
+
yield fixer.replaceTextRange([from, to], ", ");
|
|
53
|
+
},
|
|
54
|
+
loc: {
|
|
55
|
+
start: prev.loc.end,
|
|
56
|
+
end: current.loc.start
|
|
57
|
+
},
|
|
58
|
+
messageId: "genericSpacingMismatch",
|
|
59
|
+
node
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
TSTypeParameter: (node) => {
|
|
65
|
+
if (!node.default) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const endNode = node.constraint || node.name;
|
|
69
|
+
const from = endNode.range[1];
|
|
70
|
+
const to = node.default.range[0];
|
|
71
|
+
if (sourceCode.text.slice(from, to) !== " = ") {
|
|
72
|
+
context.report({
|
|
73
|
+
*fix(fixer) {
|
|
74
|
+
yield fixer.replaceTextRange([from, to], " = ");
|
|
75
|
+
},
|
|
76
|
+
loc: {
|
|
77
|
+
start: endNode.loc.end,
|
|
78
|
+
end: node.default.loc.start
|
|
79
|
+
},
|
|
80
|
+
messageId: "genericSpacingMismatch",
|
|
81
|
+
node
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
9
89
|
const RULE_NAME$2 = "if-newline";
|
|
10
90
|
const ifNewline = createEslintRule({
|
|
11
91
|
name: RULE_NAME$2,
|
|
@@ -155,7 +235,8 @@ const index = {
|
|
|
155
235
|
rules: {
|
|
156
236
|
"if-newline": ifNewline,
|
|
157
237
|
"import-dedupe": importDedupe,
|
|
158
|
-
"prefer-inline-type-import": preferInlineTypeImport
|
|
238
|
+
"prefer-inline-type-import": preferInlineTypeImport,
|
|
239
|
+
"generic-spacing": genericSpacing
|
|
159
240
|
}
|
|
160
241
|
};
|
|
161
242
|
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare const _default: {
|
|
|
5
5
|
"if-newline": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"missingIfNewline", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
6
6
|
"import-dedupe": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"importDedupe", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
7
7
|
"prefer-inline-type-import": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"preferInlineTypeImport", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
8
|
+
"generic-spacing": _typescript_eslint_utils_dist_ts_eslint_Rule.RuleModule<"genericSpacingMismatch", [], _typescript_eslint_utils_dist_ts_eslint_Rule.RuleListener>;
|
|
8
9
|
};
|
|
9
10
|
};
|
|
10
11
|
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,86 @@ const createEslintRule = ESLintUtils.RuleCreator(
|
|
|
4
4
|
(ruleName) => ruleName
|
|
5
5
|
);
|
|
6
6
|
|
|
7
|
+
const RULE_NAME$3 = "generic-spacing";
|
|
8
|
+
const genericSpacing = createEslintRule({
|
|
9
|
+
name: RULE_NAME$3,
|
|
10
|
+
meta: {
|
|
11
|
+
type: "suggestion",
|
|
12
|
+
docs: {
|
|
13
|
+
description: "Spaces around generic type parameters",
|
|
14
|
+
recommended: "error"
|
|
15
|
+
},
|
|
16
|
+
fixable: "code",
|
|
17
|
+
schema: [],
|
|
18
|
+
messages: {
|
|
19
|
+
genericSpacingMismatch: "Generic spaces mismatch"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
defaultOptions: [],
|
|
23
|
+
create: (context) => {
|
|
24
|
+
const sourceCode = context.getSourceCode();
|
|
25
|
+
return {
|
|
26
|
+
TSTypeParameterDeclaration: (node) => {
|
|
27
|
+
if (!["TSCallSignatureDeclaration", "ArrowFunctionExpression", "TSFunctionType"].includes(node.parent.type)) {
|
|
28
|
+
const pre = sourceCode.text.slice(0, node.range[0]);
|
|
29
|
+
const preSpace = pre.match(/(\s+)$/)?.[0];
|
|
30
|
+
if (preSpace && preSpace.length) {
|
|
31
|
+
context.report({
|
|
32
|
+
node,
|
|
33
|
+
messageId: "genericSpacingMismatch",
|
|
34
|
+
*fix(fixer) {
|
|
35
|
+
yield fixer.replaceTextRange([node.range[0] - preSpace.length, node.range[0]], "");
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const params = node.params;
|
|
41
|
+
for (let i = 1; i < params.length; i++) {
|
|
42
|
+
const prev = params[i - 1];
|
|
43
|
+
const current = params[i];
|
|
44
|
+
const from = prev.range[1];
|
|
45
|
+
const to = current.range[0];
|
|
46
|
+
const span = sourceCode.text.slice(from, to);
|
|
47
|
+
if (span !== ", " && !span.match(/,\n/)) {
|
|
48
|
+
context.report({
|
|
49
|
+
*fix(fixer) {
|
|
50
|
+
yield fixer.replaceTextRange([from, to], ", ");
|
|
51
|
+
},
|
|
52
|
+
loc: {
|
|
53
|
+
start: prev.loc.end,
|
|
54
|
+
end: current.loc.start
|
|
55
|
+
},
|
|
56
|
+
messageId: "genericSpacingMismatch",
|
|
57
|
+
node
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
TSTypeParameter: (node) => {
|
|
63
|
+
if (!node.default) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const endNode = node.constraint || node.name;
|
|
67
|
+
const from = endNode.range[1];
|
|
68
|
+
const to = node.default.range[0];
|
|
69
|
+
if (sourceCode.text.slice(from, to) !== " = ") {
|
|
70
|
+
context.report({
|
|
71
|
+
*fix(fixer) {
|
|
72
|
+
yield fixer.replaceTextRange([from, to], " = ");
|
|
73
|
+
},
|
|
74
|
+
loc: {
|
|
75
|
+
start: endNode.loc.end,
|
|
76
|
+
end: node.default.loc.start
|
|
77
|
+
},
|
|
78
|
+
messageId: "genericSpacingMismatch",
|
|
79
|
+
node
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
7
87
|
const RULE_NAME$2 = "if-newline";
|
|
8
88
|
const ifNewline = createEslintRule({
|
|
9
89
|
name: RULE_NAME$2,
|
|
@@ -153,7 +233,8 @@ const index = {
|
|
|
153
233
|
rules: {
|
|
154
234
|
"if-newline": ifNewline,
|
|
155
235
|
"import-dedupe": importDedupe,
|
|
156
|
-
"prefer-inline-type-import": preferInlineTypeImport
|
|
236
|
+
"prefer-inline-type-import": preferInlineTypeImport,
|
|
237
|
+
"generic-spacing": genericSpacing
|
|
157
238
|
}
|
|
158
239
|
};
|
|
159
240
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-kirklin",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/kirklin/eslint-config",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@typescript-eslint/utils": "^5.
|
|
13
|
+
"@typescript-eslint/utils": "^5.45.0"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"@types/node": "^18.11.9",
|
|
17
|
+
"unbuild": "^1.0.1",
|
|
18
|
+
"vitest": "^0.25.3"
|
|
18
19
|
},
|
|
19
20
|
"scripts": {
|
|
20
21
|
"build": "rimraf dist && unbuild",
|