eslint-plugin-kirklin 2.0.0 → 3.1.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.
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +47 -18
- package/package.json +23 -33
package/dist/index.d.mts
CHANGED
|
@@ -20,6 +20,7 @@ type Options$1 = [
|
|
|
20
20
|
ExportNamedDeclaration?: boolean;
|
|
21
21
|
FunctionDeclaration?: boolean;
|
|
22
22
|
FunctionExpression?: boolean;
|
|
23
|
+
IfStatement?: boolean;
|
|
23
24
|
ImportDeclaration?: boolean;
|
|
24
25
|
JSONArrayExpression?: boolean;
|
|
25
26
|
JSONObjectExpression?: boolean;
|
|
@@ -69,4 +70,5 @@ type Rules = {
|
|
|
69
70
|
[K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]>;
|
|
70
71
|
};
|
|
71
72
|
|
|
72
|
-
export {
|
|
73
|
+
export { plugin as default };
|
|
74
|
+
export type { RuleOptions, Rules };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ type Options$1 = [
|
|
|
20
20
|
ExportNamedDeclaration?: boolean;
|
|
21
21
|
FunctionDeclaration?: boolean;
|
|
22
22
|
FunctionExpression?: boolean;
|
|
23
|
+
IfStatement?: boolean;
|
|
23
24
|
ImportDeclaration?: boolean;
|
|
24
25
|
JSONArrayExpression?: boolean;
|
|
25
26
|
JSONObjectExpression?: boolean;
|
|
@@ -69,4 +70,5 @@ type Rules = {
|
|
|
69
70
|
[K in keyof RuleOptions]: Linter.RuleEntry<RuleOptions[K]>;
|
|
70
71
|
};
|
|
71
72
|
|
|
72
|
-
export {
|
|
73
|
+
export { plugin as default };
|
|
74
|
+
export type { RuleOptions, Rules };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { isCommaToken } from '@typescript-eslint/utils/ast-utils';
|
|
2
|
+
|
|
3
|
+
const version = "3.1.0";
|
|
2
4
|
|
|
3
5
|
const hasDocs = [
|
|
4
6
|
"consistent-chaining",
|
|
@@ -34,7 +36,7 @@ function createRule({
|
|
|
34
36
|
meta
|
|
35
37
|
}) {
|
|
36
38
|
return {
|
|
37
|
-
create: (context) => {
|
|
39
|
+
create: ((context) => {
|
|
38
40
|
const optionsWithDefault = context.options.map((options, index) => {
|
|
39
41
|
return {
|
|
40
42
|
...defaultOptions[index] || {},
|
|
@@ -42,7 +44,7 @@ function createRule({
|
|
|
42
44
|
};
|
|
43
45
|
});
|
|
44
46
|
return create(context, optionsWithDefault);
|
|
45
|
-
},
|
|
47
|
+
}),
|
|
46
48
|
defaultOptions,
|
|
47
49
|
meta
|
|
48
50
|
};
|
|
@@ -59,7 +61,7 @@ function unindent(str) {
|
|
|
59
61
|
return min;
|
|
60
62
|
}
|
|
61
63
|
const indent = line.match(/^\s*/)?.[0].length;
|
|
62
|
-
return indent ===
|
|
64
|
+
return indent === void 0 ? min : Math.min(min, indent);
|
|
63
65
|
}, Number.POSITIVE_INFINITY);
|
|
64
66
|
let emptyLinesHead = 0;
|
|
65
67
|
while (emptyLinesHead < lines.length && whitespaceLines[emptyLinesHead]) {
|
|
@@ -134,8 +136,12 @@ const consistentChaining = createEslintRule({
|
|
|
134
136
|
current = current.callee;
|
|
135
137
|
break;
|
|
136
138
|
}
|
|
139
|
+
case "TSNonNullExpression": {
|
|
140
|
+
current = current.expression;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
137
143
|
default: {
|
|
138
|
-
current =
|
|
144
|
+
current = void 0;
|
|
139
145
|
break;
|
|
140
146
|
}
|
|
141
147
|
}
|
|
@@ -146,7 +152,8 @@ const consistentChaining = createEslintRule({
|
|
|
146
152
|
const token = context.sourceCode.getTokenBefore(m.property);
|
|
147
153
|
const tokenBefore = context.sourceCode.getTokenBefore(token);
|
|
148
154
|
const currentMode = token.loc.start.line === tokenBefore.loc.end.line ? "single" : "multi";
|
|
149
|
-
|
|
155
|
+
const object = m.object.type === "TSNonNullExpression" ? m.object.expression : m.object;
|
|
156
|
+
if (leadingPropertyAcccess && (object.type === "ThisExpression" || object.type === "Identifier" || object.type === "MemberExpression" || object.type === "Literal") && currentMode === "single") {
|
|
150
157
|
return;
|
|
151
158
|
}
|
|
152
159
|
leadingPropertyAcccess = false;
|
|
@@ -195,6 +202,7 @@ const consistentListNewline = createEslintRule({
|
|
|
195
202
|
ExportNamedDeclaration: { type: "boolean" },
|
|
196
203
|
FunctionDeclaration: { type: "boolean" },
|
|
197
204
|
FunctionExpression: { type: "boolean" },
|
|
205
|
+
IfStatement: { type: "boolean" },
|
|
198
206
|
ImportDeclaration: { type: "boolean" },
|
|
199
207
|
JSONArrayExpression: { type: "boolean" },
|
|
200
208
|
JSONObjectExpression: { type: "boolean" },
|
|
@@ -218,6 +226,16 @@ const consistentListNewline = createEslintRule({
|
|
|
218
226
|
},
|
|
219
227
|
defaultOptions: [{}],
|
|
220
228
|
create: (context, [options = {}] = [{}]) => {
|
|
229
|
+
const multilineNodes = /* @__PURE__ */ new Set([
|
|
230
|
+
"ArrayExpression",
|
|
231
|
+
"FunctionDeclaration",
|
|
232
|
+
"IfStatement",
|
|
233
|
+
"ObjectExpression",
|
|
234
|
+
"ObjectPattern",
|
|
235
|
+
"TSTypeLiteral",
|
|
236
|
+
"TSTupleType",
|
|
237
|
+
"TSInterfaceDeclaration"
|
|
238
|
+
]);
|
|
221
239
|
function removeLines(fixer, start, end, delimiter) {
|
|
222
240
|
const range = [start, end];
|
|
223
241
|
const code = context.sourceCode.text.slice(...range);
|
|
@@ -228,7 +246,7 @@ const consistentListNewline = createEslintRule({
|
|
|
228
246
|
return;
|
|
229
247
|
}
|
|
230
248
|
const currentContent = context.sourceCode.text.slice(current.range[0], current.range[1]);
|
|
231
|
-
return currentContent.match(/(?:,|;)$/) ?
|
|
249
|
+
return currentContent.match(/(?:,|;)$/) ? void 0 : ",";
|
|
232
250
|
}
|
|
233
251
|
function hasComments(current) {
|
|
234
252
|
let program = current;
|
|
@@ -246,7 +264,7 @@ const consistentListNewline = createEslintRule({
|
|
|
246
264
|
if (items.length === 0) {
|
|
247
265
|
return;
|
|
248
266
|
}
|
|
249
|
-
let startToken = ["CallExpression", "NewExpression"].includes(node.type) ?
|
|
267
|
+
let startToken = ["CallExpression", "NewExpression"].includes(node.type) ? void 0 : context.sourceCode.getFirstToken(node);
|
|
250
268
|
if (node.type === "CallExpression") {
|
|
251
269
|
startToken = context.sourceCode.getTokenAfter(
|
|
252
270
|
node.typeArguments ? node.typeArguments : node.callee.type === "MemberExpression" ? node.callee.property : node.callee
|
|
@@ -319,10 +337,17 @@ const consistentListNewline = createEslintRule({
|
|
|
319
337
|
}
|
|
320
338
|
});
|
|
321
339
|
} else if (mode === "inline" && endLoc.line !== lastLine) {
|
|
322
|
-
if (items.length === 1
|
|
323
|
-
|
|
340
|
+
if (items.length === 1) {
|
|
341
|
+
const firstItem = items[0];
|
|
342
|
+
if (!multilineNodes.has(node.type)) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (firstItem.loc.start.line !== firstItem.loc.end.line) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
324
348
|
}
|
|
325
|
-
|
|
349
|
+
const nextToken = context.sourceCode.getTokenAfter(lastItem);
|
|
350
|
+
if (context.sourceCode.getCommentsAfter(nextToken && isCommaToken(nextToken) ? nextToken : lastItem).length > 0) {
|
|
326
351
|
return;
|
|
327
352
|
}
|
|
328
353
|
const content = context.sourceCode.text.slice(lastItem.range[1], endRange);
|
|
@@ -334,7 +359,8 @@ const consistentListNewline = createEslintRule({
|
|
|
334
359
|
name: node.type
|
|
335
360
|
},
|
|
336
361
|
*fix(fixer) {
|
|
337
|
-
|
|
362
|
+
const delimiter = items.length === 1 ? "" : getDelimiter(node, lastItem);
|
|
363
|
+
yield removeLines(fixer, lastItem.range[1], endRange, delimiter);
|
|
338
364
|
}
|
|
339
365
|
});
|
|
340
366
|
}
|
|
@@ -370,6 +396,9 @@ const consistentListNewline = createEslintRule({
|
|
|
370
396
|
node.returnType || node.body
|
|
371
397
|
);
|
|
372
398
|
},
|
|
399
|
+
IfStatement: (node) => {
|
|
400
|
+
check(node, [node.test], node.consequent);
|
|
401
|
+
},
|
|
373
402
|
ArrowFunctionExpression: (node) => {
|
|
374
403
|
if (node.params.length <= 1) {
|
|
375
404
|
return;
|
|
@@ -771,7 +800,7 @@ const topLevelFunction = createEslintRule({
|
|
|
771
800
|
return;
|
|
772
801
|
}
|
|
773
802
|
const declaration = node.declarations[0];
|
|
774
|
-
if (declaration.init?.type !== "ArrowFunctionExpression") {
|
|
803
|
+
if (declaration.init?.type !== "ArrowFunctionExpression" && declaration.init?.type !== "FunctionExpression") {
|
|
775
804
|
return;
|
|
776
805
|
}
|
|
777
806
|
if (declaration.id?.type !== "Identifier") {
|
|
@@ -783,7 +812,7 @@ const topLevelFunction = createEslintRule({
|
|
|
783
812
|
if (declaration.init.body.type !== "BlockStatement" && declaration.id?.loc.start.line === declaration.init?.body.loc.end.line) {
|
|
784
813
|
return;
|
|
785
814
|
}
|
|
786
|
-
const
|
|
815
|
+
const fnExpression = declaration.init;
|
|
787
816
|
const body = declaration.init.body;
|
|
788
817
|
const id = declaration.id;
|
|
789
818
|
context.report({
|
|
@@ -796,13 +825,13 @@ const topLevelFunction = createEslintRule({
|
|
|
796
825
|
fix(fixer) {
|
|
797
826
|
const code = context.getSourceCode().text;
|
|
798
827
|
const textName = code.slice(id.range[0], id.range[1]);
|
|
799
|
-
const textArgs =
|
|
828
|
+
const textArgs = fnExpression.params.length ? code.slice(fnExpression.params[0].range[0], fnExpression.params[fnExpression.params.length - 1].range[1]) : "";
|
|
800
829
|
const textBody = body.type === "BlockStatement" ? code.slice(body.range[0], body.range[1]) : `{
|
|
801
830
|
return ${code.slice(body.range[0], body.range[1])}
|
|
802
831
|
}`;
|
|
803
|
-
const textGeneric =
|
|
804
|
-
const textTypeReturn =
|
|
805
|
-
const textAsync =
|
|
832
|
+
const textGeneric = fnExpression.typeParameters ? code.slice(fnExpression.typeParameters.range[0], fnExpression.typeParameters.range[1]) : "";
|
|
833
|
+
const textTypeReturn = fnExpression.returnType ? code.slice(fnExpression.returnType.range[0], fnExpression.returnType.range[1]) : "";
|
|
834
|
+
const textAsync = fnExpression.async ? "async " : "";
|
|
806
835
|
const final = `${textAsync}function ${textName} ${textGeneric}(${textArgs})${textTypeReturn} ${textBody}`;
|
|
807
836
|
return fixer.replaceTextRange([node.range[0], node.range[1]], final);
|
|
808
837
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-kirklin",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
5
|
-
"packageManager": "pnpm@10.
|
|
4
|
+
"version": "3.1.0",
|
|
5
|
+
"packageManager": "pnpm@10.28.1",
|
|
6
6
|
"description": "Kirk Lin extended ESLint rules",
|
|
7
7
|
"author": "Kirk Lin (https://github.com/kirklin)",
|
|
8
8
|
"license": "MIT",
|
|
@@ -18,10 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"sideEffects": false,
|
|
20
20
|
"exports": {
|
|
21
|
-
".":
|
|
22
|
-
"types": "./dist/index.d.mts",
|
|
23
|
-
"default": "./dist/index.mjs"
|
|
24
|
-
}
|
|
21
|
+
".": "./dist/index.mjs"
|
|
25
22
|
},
|
|
26
23
|
"main": "./dist/index.mjs",
|
|
27
24
|
"module": "./dist/index.mjs",
|
|
@@ -35,8 +32,8 @@
|
|
|
35
32
|
"lint": "pnpm run dev && eslint .",
|
|
36
33
|
"lint:fix": "pnpm run dev && eslint . --fix",
|
|
37
34
|
"prepublishOnly": "nr build",
|
|
38
|
-
"release": "bumpp
|
|
39
|
-
"start": "
|
|
35
|
+
"release": "bumpp",
|
|
36
|
+
"start": "tsx src/index.ts",
|
|
40
37
|
"test": "vitest",
|
|
41
38
|
"typecheck": "tsc --noEmit",
|
|
42
39
|
"prepare": "simple-git-hooks"
|
|
@@ -45,32 +42,25 @@
|
|
|
45
42
|
"eslint": "*"
|
|
46
43
|
},
|
|
47
44
|
"devDependencies": {
|
|
48
|
-
"@antfu/ni": "^
|
|
49
|
-
"@antfu/utils": "^
|
|
50
|
-
"@kirklin/eslint-config": "^
|
|
45
|
+
"@antfu/ni": "^28.2.0",
|
|
46
|
+
"@antfu/utils": "^9.3.0",
|
|
47
|
+
"@kirklin/eslint-config": "^6.1.0",
|
|
51
48
|
"@types/eslint": "^9.6.1",
|
|
52
|
-
"@types/
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"eslint": "^
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"simple-git-hooks": "^2.11.1",
|
|
68
|
-
"tsup": "^8.3.6",
|
|
69
|
-
"tsx": "^4.19.2",
|
|
70
|
-
"typescript": "^5.7.3",
|
|
71
|
-
"unbuild": "^3.3.1",
|
|
72
|
-
"vite": "^6.1.0",
|
|
73
|
-
"vitest": "^3.0.5"
|
|
49
|
+
"@types/node": "^25.0.10",
|
|
50
|
+
"@typescript-eslint/typescript-estree": "^8.53.1",
|
|
51
|
+
"@typescript-eslint/utils": "^8.53.1",
|
|
52
|
+
"bumpp": "^10.4.0",
|
|
53
|
+
"eslint": "^9.39.2",
|
|
54
|
+
"eslint-vitest-rule-tester": "^3.0.1",
|
|
55
|
+
"jsonc-eslint-parser": "^2.4.2",
|
|
56
|
+
"lint-staged": "^16.2.7",
|
|
57
|
+
"simple-git-hooks": "^2.13.1",
|
|
58
|
+
"tsup": "^8.5.1",
|
|
59
|
+
"tsx": "^4.21.0",
|
|
60
|
+
"typescript": "^5.9.3",
|
|
61
|
+
"unbuild": "^3.6.1",
|
|
62
|
+
"vite": "^7.3.1",
|
|
63
|
+
"vitest": "^4.0.18"
|
|
74
64
|
},
|
|
75
65
|
"resolutions": {
|
|
76
66
|
"eslint-plugin-kirklin": "workspace:*"
|