@tai-kun/vp-lint-plugins 0.0.4 → 0.0.6
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/src/index.d.ts +1 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -6
- package/dist/src/plugin.js +2 -12
- package/dist/src/rules/_blank-line-utils.d.ts +30 -0
- package/dist/src/rules/_blank-line-utils.d.ts.map +1 -0
- package/dist/src/rules/_blank-line-utils.js +103 -0
- package/dist/src/rules/{comment-utils.d.ts → _comment-utils.d.ts} +1 -1
- package/dist/src/rules/_comment-utils.d.ts.map +1 -0
- package/dist/src/rules/{comment-utils.js → _comment-utils.js} +2 -1
- package/dist/src/rules/{jsdoc-utils.d.ts → _jsdoc-utils.d.ts} +1 -1
- package/dist/src/rules/_jsdoc-utils.d.ts.map +1 -0
- package/dist/src/rules/{jsdoc-utils.js → _jsdoc-utils.js} +1 -1
- package/dist/src/rules/{object-sort-utils.d.ts → _object-sort-utils.d.ts} +1 -1
- package/dist/src/rules/_object-sort-utils.d.ts.map +1 -0
- package/dist/src/rules/blank-line.d.ts +5 -14
- package/dist/src/rules/blank-line.d.ts.map +1 -1
- package/dist/src/rules/blank-line.js +426 -66
- package/dist/src/rules/comment-japanese-spacing.js +1 -1
- package/dist/src/rules/comment-one-sentence-per-line.d.ts +1 -1
- package/dist/src/rules/comment-one-sentence-per-line.js +2 -2
- package/dist/src/rules/jsdoc-param-order.js +1 -1
- package/dist/src/rules/jsdoc-tag-lines.js +1 -1
- package/dist/src/rules/jsdoc-tag-order.js +1 -1
- package/dist/src/rules/object-properties-newline.d.ts +2 -1
- package/dist/src/rules/object-properties-newline.d.ts.map +1 -1
- package/dist/src/rules/object-properties-newline.js +39 -8
- package/dist/src/rules/overload-signatures-adjacent.js +1 -1
- package/dist/src/rules/sort-import-export-specifiers.js +1 -1
- package/dist/src/rules/sort-jsx-props.js +1 -1
- package/dist/src/rules/sort-object-properties.js +1 -1
- package/dist/src/rules/sort-type-members.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -6
- package/src/plugin.ts +2 -12
- package/src/rules/_blank-line-utils.ts +165 -0
- package/src/rules/{comment-utils.ts → _comment-utils.ts} +2 -1
- package/src/rules/{jsdoc-utils.ts → _jsdoc-utils.ts} +1 -1
- package/src/rules/blank-line.ts +555 -97
- package/src/rules/comment-japanese-spacing.ts +2 -2
- package/src/rules/comment-one-sentence-per-line.ts +3 -3
- package/src/rules/jsdoc-param-order.ts +1 -1
- package/src/rules/jsdoc-tag-lines.ts +2 -2
- package/src/rules/jsdoc-tag-order.ts +1 -1
- package/src/rules/object-properties-newline.ts +93 -10
- package/src/rules/overload-signatures-adjacent.ts +1 -1
- package/src/rules/sort-import-export-specifiers.ts +1 -1
- package/src/rules/sort-jsx-props.ts +1 -1
- package/src/rules/sort-object-properties.ts +1 -1
- package/src/rules/sort-type-members.ts +1 -1
- package/dist/src/rules/blank-line-after-control-block.d.ts +0 -7
- package/dist/src/rules/blank-line-after-control-block.d.ts.map +0 -1
- package/dist/src/rules/blank-line-after-control-block.js +0 -54
- package/dist/src/rules/blank-line-after-declaration.d.ts +0 -7
- package/dist/src/rules/blank-line-after-declaration.d.ts.map +0 -1
- package/dist/src/rules/blank-line-after-declaration.js +0 -79
- package/dist/src/rules/blank-line-after-variable-declaration.d.ts +0 -9
- package/dist/src/rules/blank-line-after-variable-declaration.d.ts.map +0 -1
- package/dist/src/rules/blank-line-after-variable-declaration.js +0 -118
- package/dist/src/rules/blank-line-before-return.d.ts +0 -7
- package/dist/src/rules/blank-line-before-return.d.ts.map +0 -1
- package/dist/src/rules/blank-line-before-return.js +0 -81
- package/dist/src/rules/blank-line-between-class-members.d.ts +0 -8
- package/dist/src/rules/blank-line-between-class-members.d.ts.map +0 -1
- package/dist/src/rules/blank-line-between-class-members.js +0 -85
- package/dist/src/rules/blank-line-between-switch-cases.d.ts +0 -8
- package/dist/src/rules/blank-line-between-switch-cases.d.ts.map +0 -1
- package/dist/src/rules/blank-line-between-switch-cases.js +0 -45
- package/dist/src/rules/comment-utils.d.ts.map +0 -1
- package/dist/src/rules/jsdoc-utils.d.ts.map +0 -1
- package/dist/src/rules/object-sort-utils.d.ts.map +0 -1
- package/src/rules/blank-line-after-control-block.ts +0 -82
- package/src/rules/blank-line-after-declaration.ts +0 -106
- package/src/rules/blank-line-after-variable-declaration.ts +0 -165
- package/src/rules/blank-line-before-return.ts +0 -101
- package/src/rules/blank-line-between-class-members.ts +0 -112
- package/src/rules/blank-line-between-switch-cases.ts +0 -53
- /package/dist/src/rules/{object-sort-utils.js → _object-sort-utils.js} +0 -0
- /package/src/rules/{object-sort-utils.ts → _object-sort-utils.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
2
|
import type { Comment, Context } from "vite-plus/lint/plugins";
|
|
3
3
|
|
|
4
|
-
import type { CommentLine } from "./
|
|
4
|
+
import type { CommentLine } from "./_comment-utils.js";
|
|
5
5
|
import {
|
|
6
6
|
isBlank,
|
|
7
7
|
isFence,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
isDirective,
|
|
10
10
|
getLineGroupInfos,
|
|
11
11
|
getCommentLineInfos,
|
|
12
|
-
} from "./
|
|
12
|
+
} from "./_comment-utils.js";
|
|
13
13
|
|
|
14
14
|
interface SpacingEdit {
|
|
15
15
|
end: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
2
|
import type { Comment, Location } from "vite-plus/lint/plugins";
|
|
3
3
|
|
|
4
|
-
import type { CommentLine } from "./
|
|
4
|
+
import type { CommentLine } from "./_comment-utils.js";
|
|
5
5
|
import {
|
|
6
6
|
isTag,
|
|
7
7
|
isBlank,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
getLineGroupInfos,
|
|
15
15
|
getCommentLineInfos,
|
|
16
16
|
isSkippableProseLine,
|
|
17
|
-
} from "./
|
|
17
|
+
} from "./_comment-utils.js";
|
|
18
18
|
|
|
19
19
|
interface SentenceFix {
|
|
20
20
|
end: number;
|
|
@@ -162,7 +162,7 @@ function collectDiagnostics(
|
|
|
162
162
|
/**
|
|
163
163
|
* コメントを 1 行 1 文にします。
|
|
164
164
|
*
|
|
165
|
-
*
|
|
165
|
+
* 複数行のコメントで、文の途中(「、」など)で改行している箇所を検出し、次の行と結合します。文末は「。」「.」「.」「!」「?」「:」「:」などを判定します。
|
|
166
166
|
* `requireEndPunctuation` を有効にすると、文末の句読点がない散文行も報告します。
|
|
167
167
|
*/
|
|
168
168
|
const commentOneSentencePerLine = defineRule({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
2
|
import type { ESTree, Context, SourceCode } from "vite-plus/lint/plugins";
|
|
3
3
|
|
|
4
|
-
import { getNodeJSDoc, getParamName, getJSDocLines, hasExampleOrFence } from "./
|
|
4
|
+
import { getNodeJSDoc, getParamName, getJSDocLines, hasExampleOrFence } from "./_jsdoc-utils.js";
|
|
5
5
|
|
|
6
6
|
function getParamNameFromPattern(param: ESTree.ParamPattern): string | null {
|
|
7
7
|
if (param.type === "Identifier") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
2
|
|
|
3
|
-
import type { JSDocLine } from "./
|
|
4
|
-
import { getJSDocLines, hasExampleOrFence } from "./
|
|
3
|
+
import type { JSDocLine } from "./_jsdoc-utils.js";
|
|
4
|
+
import { getJSDocLines, hasExampleOrFence } from "./_jsdoc-utils.js";
|
|
5
5
|
|
|
6
6
|
interface Entry {
|
|
7
7
|
groupId: number;
|
|
@@ -1,17 +1,89 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
+
import type { ESTree } from "vite-plus/lint/plugins";
|
|
2
3
|
|
|
3
|
-
import { getSortPlan } from "./
|
|
4
|
+
import { getSortPlan } from "./_object-sort-utils.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* 改行判定に必要な最小限のオブジェクト形状です。
|
|
8
|
+
*
|
|
9
|
+
* `ObjectExpression` と JSON パーサーの `JSONObjectExpression` の両方を受け付けます。
|
|
10
|
+
*/
|
|
11
|
+
interface MultilineTarget {
|
|
12
|
+
/**
|
|
13
|
+
* オブジェクトの位置情報です。
|
|
14
|
+
*/
|
|
15
|
+
loc: {
|
|
16
|
+
/**
|
|
17
|
+
* 開始位置です。
|
|
18
|
+
*/
|
|
19
|
+
start: {
|
|
20
|
+
/**
|
|
21
|
+
* 1 始まりの行番号です。
|
|
22
|
+
*/
|
|
23
|
+
line: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* プロパティーの一覧です。
|
|
29
|
+
*/
|
|
30
|
+
properties: readonly {
|
|
31
|
+
/**
|
|
32
|
+
* プロパティーの位置情報です。
|
|
33
|
+
*/
|
|
34
|
+
loc: {
|
|
35
|
+
/**
|
|
36
|
+
* 開始位置です。
|
|
37
|
+
*/
|
|
38
|
+
start: {
|
|
39
|
+
/**
|
|
40
|
+
* 1 始まりの行番号です。
|
|
41
|
+
*/
|
|
42
|
+
line: number;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}[];
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* オブジェクトの範囲です。
|
|
49
|
+
*/
|
|
50
|
+
range: readonly [number, number];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 複数行にすべき 1 行オブジェクトかどうかを判定します。
|
|
55
|
+
*
|
|
56
|
+
* プロパティーが 2 つ以上あり、最初のプロパティーが `{` と同じ行にある場合に `true` を返します。
|
|
57
|
+
*
|
|
58
|
+
* @param node 判定対象のオブジェクトです。
|
|
59
|
+
*
|
|
60
|
+
* @returns 複数行にすべき場合に `true` です。
|
|
61
|
+
*/
|
|
62
|
+
function needsMultiline(node: MultilineTarget): boolean {
|
|
63
|
+
if (node.properties.length < 2) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const firstProperty = node.properties[0];
|
|
68
|
+
|
|
69
|
+
if (firstProperty === undefined) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return firstProperty.loc.start.line === node.loc.start.line;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* プロパティーが 2 つ以上あるオブジェクトリテラルと JSON オブジェクトを複数行にします。
|
|
7
78
|
*
|
|
8
79
|
* Oxfmt の `objectWrap` には「プロパティー数で改行を強制する」オプションがないため、改行を挿入する最小限の fix を提供します。
|
|
9
80
|
* `objectWrap: "preserve"` と組み合わせることで、後続の Oxfmt がプロパティーごとの改行とインデントを整えます。
|
|
81
|
+
* JSON (`JSONObjectExpression`) も同じ fix で複数行化します。
|
|
10
82
|
*/
|
|
11
83
|
const objectPropertiesNewline = defineRule({
|
|
12
84
|
meta: {
|
|
13
85
|
docs: {
|
|
14
|
-
description: "Enforce multiline
|
|
86
|
+
description: "Enforce multiline objects when they have two or more properties.",
|
|
15
87
|
},
|
|
16
88
|
type: "layout",
|
|
17
89
|
fixable: "whitespace",
|
|
@@ -22,19 +94,13 @@ const objectPropertiesNewline = defineRule({
|
|
|
22
94
|
create(context) {
|
|
23
95
|
return {
|
|
24
96
|
ObjectExpression(node): void {
|
|
25
|
-
if (node.properties.length < 2) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
97
|
// 並び替え可能なオブジェクトは sort-object-properties が複数行化も担当します。
|
|
30
98
|
if (getSortPlan(node, context.sourceCode) !== null) {
|
|
31
99
|
return;
|
|
32
100
|
}
|
|
33
101
|
|
|
34
102
|
// Oxfmt は `{` の直後に改行があるかどうかで複数行を維持するため、最初のプロパティーが `{` と同じ行にある場合だけを対象にします。
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (firstProperty === undefined || firstProperty.loc.start.line !== node.loc.start.line) {
|
|
103
|
+
if (!needsMultiline(node)) {
|
|
38
104
|
return;
|
|
39
105
|
}
|
|
40
106
|
|
|
@@ -47,6 +113,23 @@ const objectPropertiesNewline = defineRule({
|
|
|
47
113
|
messageId: "multiline",
|
|
48
114
|
});
|
|
49
115
|
},
|
|
116
|
+
JSONObjectExpression(node): void {
|
|
117
|
+
const target = node as unknown as MultilineTarget;
|
|
118
|
+
|
|
119
|
+
if (!needsMultiline(target)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
context.report({
|
|
124
|
+
fix(fixer) {
|
|
125
|
+
// JSON も `objectWrap: "preserve"` で整形されるため、JS と同じく `{` の直後に改行を 1 つ挿入するだけで十分です。
|
|
126
|
+
return fixer.insertTextAfterRange([target.range[0], target.range[0] + 1], "\n");
|
|
127
|
+
},
|
|
128
|
+
// `JSONObjectExpression` は `VisitorObject` の既定の型に含まれないため、報告時は `node` をそのまま渡します。
|
|
129
|
+
node: node as unknown as ESTree.ObjectExpression,
|
|
130
|
+
messageId: "multiline",
|
|
131
|
+
});
|
|
132
|
+
},
|
|
50
133
|
};
|
|
51
134
|
},
|
|
52
135
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
2
|
import type { ESTree, Context, SourceCode } from "vite-plus/lint/plugins";
|
|
3
3
|
|
|
4
|
-
import { getNextStatement, getRemoveBlankLineFix } from "./
|
|
4
|
+
import { getNextStatement, getRemoveBlankLineFix } from "./_blank-line-utils.js";
|
|
5
5
|
|
|
6
6
|
function getFunction(node: ESTree.Node): ESTree.Function | null {
|
|
7
7
|
if (node.type === "FunctionDeclaration" || node.type === "TSDeclareFunction") {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
2
|
import type { ESTree, SourceCode } from "vite-plus/lint/plugins";
|
|
3
3
|
|
|
4
|
-
import { compareNames } from "./
|
|
4
|
+
import { compareNames } from "./_object-sort-utils.js";
|
|
5
5
|
|
|
6
6
|
interface SpecifierUnit {
|
|
7
7
|
group: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
2
|
import type { ESTree, SourceCode } from "vite-plus/lint/plugins";
|
|
3
3
|
|
|
4
|
-
import { compareNames } from "./
|
|
4
|
+
import { compareNames } from "./_object-sort-utils.js";
|
|
5
5
|
|
|
6
6
|
interface AttributeUnit {
|
|
7
7
|
name: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
2
|
import type { Fix, ESTree, Comment, SourceCode } from "vite-plus/lint/plugins";
|
|
3
3
|
|
|
4
|
-
import { compareNames } from "./
|
|
4
|
+
import { compareNames } from "./_object-sort-utils.js";
|
|
5
5
|
|
|
6
6
|
interface MemberUnit {
|
|
7
7
|
endLine: number;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 制御ブロックの直後に次の処理がある場合、空行を 1 行以上確保します。
|
|
3
|
-
* 余分な空行は Oxfmt が 1 行に畳みます。
|
|
4
|
-
*/
|
|
5
|
-
declare const blankLineAfterControlBlock: import("vite-plus/lint/plugins").Rule;
|
|
6
|
-
export default blankLineAfterControlBlock;
|
|
7
|
-
//# sourceMappingURL=blank-line-after-control-block.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blank-line-after-control-block.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line-after-control-block.ts"],"names":[],"mappings":"AA+BA;;;GAGG;AACH,QAAA,MAAM,0BAA0B,uCA4C9B,CAAC;eAEY,0BAA0B"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
-
import { hasBlankLine, getBlankLineFix, getNextStatement, getInsertionTarget, } from "./blank-line.js";
|
|
3
|
-
const CONTROL_STATEMENT_TYPES = new Set([
|
|
4
|
-
"DoWhileStatement",
|
|
5
|
-
"ForInStatement",
|
|
6
|
-
"ForOfStatement",
|
|
7
|
-
"ForStatement",
|
|
8
|
-
"IfStatement",
|
|
9
|
-
"SwitchStatement",
|
|
10
|
-
"TryStatement",
|
|
11
|
-
"WhileStatement",
|
|
12
|
-
]);
|
|
13
|
-
/**
|
|
14
|
-
* 制御ブロックの直後に次の処理がある場合、空行を 1 行以上確保します。
|
|
15
|
-
* 余分な空行は Oxfmt が 1 行に畳みます。
|
|
16
|
-
*/
|
|
17
|
-
const blankLineAfterControlBlock = defineRule({
|
|
18
|
-
meta: {
|
|
19
|
-
docs: {
|
|
20
|
-
description: "Require a blank line after a control block when another statement follows.",
|
|
21
|
-
},
|
|
22
|
-
type: "layout",
|
|
23
|
-
fixable: "whitespace",
|
|
24
|
-
messages: {
|
|
25
|
-
blankLine: "Expected a blank line after a control block when another statement follows.",
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
create(context) {
|
|
29
|
-
const sourceCode = context.sourceCode;
|
|
30
|
-
function checkNode(node) {
|
|
31
|
-
const nextStatement = getNextStatement(node);
|
|
32
|
-
if (nextStatement === null || nextStatement.type === "EmptyStatement") {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const target = getInsertionTarget(node, nextStatement, sourceCode);
|
|
36
|
-
if (hasBlankLine(node, target)) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
context.report({
|
|
40
|
-
fix(fixer) {
|
|
41
|
-
return getBlankLineFix(fixer, sourceCode, node, target);
|
|
42
|
-
},
|
|
43
|
-
node,
|
|
44
|
-
messageId: "blankLine",
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
const visitors = {};
|
|
48
|
-
for (const type of CONTROL_STATEMENT_TYPES) {
|
|
49
|
-
visitors[type] = checkNode;
|
|
50
|
-
}
|
|
51
|
-
return visitors;
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
export default blankLineAfterControlBlock;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 関数・クラス・型などの宣言の後に次の文がある場合、空行を 1 行以上確保します。
|
|
3
|
-
* 余分な空行は Oxfmt が 1 行に畳みます。
|
|
4
|
-
*/
|
|
5
|
-
declare const blankLineAfterDeclaration: import("vite-plus/lint/plugins").Rule;
|
|
6
|
-
export default blankLineAfterDeclaration;
|
|
7
|
-
//# sourceMappingURL=blank-line-after-declaration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blank-line-after-declaration.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line-after-declaration.ts"],"names":[],"mappings":"AA2CA;;;GAGG;AACH,QAAA,MAAM,yBAAyB,uCAwD7B,CAAC;eAEY,yBAAyB"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
-
import { hasBlankLine, getBlankLineFix, getNextStatement, getInsertionTarget, } from "./blank-line.js";
|
|
3
|
-
const DECLARATION_TYPES = new Set([
|
|
4
|
-
"ClassDeclaration",
|
|
5
|
-
"FunctionDeclaration",
|
|
6
|
-
"TSDeclareFunction",
|
|
7
|
-
"TSEnumDeclaration",
|
|
8
|
-
"TSInterfaceDeclaration",
|
|
9
|
-
"TSModuleDeclaration",
|
|
10
|
-
"TSTypeAliasDeclaration",
|
|
11
|
-
]);
|
|
12
|
-
function getDeclaration(node) {
|
|
13
|
-
if (DECLARATION_TYPES.has(node.type)) {
|
|
14
|
-
return node;
|
|
15
|
-
}
|
|
16
|
-
if ((node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration") &&
|
|
17
|
-
node.declaration !== null &&
|
|
18
|
-
DECLARATION_TYPES.has(node.declaration.type)) {
|
|
19
|
-
return node.declaration;
|
|
20
|
-
}
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
function isOverload(declaration) {
|
|
24
|
-
return ((declaration.type === "FunctionDeclaration" || declaration.type === "TSDeclareFunction") &&
|
|
25
|
-
declaration.body === null);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 関数・クラス・型などの宣言の後に次の文がある場合、空行を 1 行以上確保します。
|
|
29
|
-
* 余分な空行は Oxfmt が 1 行に畳みます。
|
|
30
|
-
*/
|
|
31
|
-
const blankLineAfterDeclaration = defineRule({
|
|
32
|
-
meta: {
|
|
33
|
-
docs: {
|
|
34
|
-
description: "Require a blank line after a declaration when another statement follows.",
|
|
35
|
-
},
|
|
36
|
-
type: "layout",
|
|
37
|
-
fixable: "whitespace",
|
|
38
|
-
messages: {
|
|
39
|
-
blankLine: "Expected a blank line after a declaration when another statement follows.",
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
create(context) {
|
|
43
|
-
const sourceCode = context.sourceCode;
|
|
44
|
-
function checkNode(node) {
|
|
45
|
-
const declaration = getDeclaration(node);
|
|
46
|
-
if (declaration === null || isOverload(declaration)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
const nextStatement = getNextStatement(node);
|
|
50
|
-
if (nextStatement === null || nextStatement.type === "EmptyStatement") {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const target = getInsertionTarget(node, nextStatement, sourceCode);
|
|
54
|
-
if (hasBlankLine(node, target)) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
context.report({
|
|
58
|
-
fix(fixer) {
|
|
59
|
-
return getBlankLineFix(fixer, sourceCode, node, target);
|
|
60
|
-
},
|
|
61
|
-
node,
|
|
62
|
-
messageId: "blankLine",
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
const visitors = {
|
|
66
|
-
ClassDeclaration: checkNode,
|
|
67
|
-
TSDeclareFunction: checkNode,
|
|
68
|
-
TSEnumDeclaration: checkNode,
|
|
69
|
-
FunctionDeclaration: checkNode,
|
|
70
|
-
TSModuleDeclaration: checkNode,
|
|
71
|
-
ExportNamedDeclaration: checkNode,
|
|
72
|
-
TSInterfaceDeclaration: checkNode,
|
|
73
|
-
TSTypeAliasDeclaration: checkNode,
|
|
74
|
-
ExportDefaultDeclaration: checkNode,
|
|
75
|
-
};
|
|
76
|
-
return visitors;
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
export default blankLineAfterDeclaration;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 連続する変数宣言の後に別の種類の文が続く場合、空行を 1 行以上確保します。
|
|
3
|
-
*
|
|
4
|
-
* 宣言した変数を使う式文は同じ宣言グループとして扱い、グループ内の空行は削除します。
|
|
5
|
-
* return の直前は blank-line-before-return が担当するため対象外にします。
|
|
6
|
-
*/
|
|
7
|
-
declare const blankLineAfterVariableDeclaration: import("vite-plus/lint/plugins").Rule;
|
|
8
|
-
export default blankLineAfterVariableDeclaration;
|
|
9
|
-
//# sourceMappingURL=blank-line-after-variable-declaration.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blank-line-after-variable-declaration.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line-after-variable-declaration.ts"],"names":[],"mappings":"AA8CA;;;;;GAKG;AACH,QAAA,MAAM,iCAAiC,uCA8GrC,CAAC;eAEY,iCAAiC"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
-
import { hasBlankLine, getBlankLineFix, getNextStatement, getInsertionTarget, getPreviousStatement, getRemoveBlankLineFix, } from "./blank-line.js";
|
|
3
|
-
function getVariableDeclaration(node) {
|
|
4
|
-
if (node.type === "VariableDeclaration") {
|
|
5
|
-
return node;
|
|
6
|
-
}
|
|
7
|
-
if (node.type === "ExportNamedDeclaration" && node.declaration?.type === "VariableDeclaration") {
|
|
8
|
-
return node.declaration;
|
|
9
|
-
}
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
function isRelatedExpression(statement, variables) {
|
|
13
|
-
if (statement.type !== "ExpressionStatement") {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
for (const variable of variables) {
|
|
17
|
-
for (const reference of variable.references) {
|
|
18
|
-
if (reference.identifier.range[0] >= statement.range[0] &&
|
|
19
|
-
reference.identifier.range[1] <= statement.range[1]) {
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 連続する変数宣言の後に別の種類の文が続く場合、空行を 1 行以上確保します。
|
|
28
|
-
*
|
|
29
|
-
* 宣言した変数を使う式文は同じ宣言グループとして扱い、グループ内の空行は削除します。
|
|
30
|
-
* return の直前は blank-line-before-return が担当するため対象外にします。
|
|
31
|
-
*/
|
|
32
|
-
const blankLineAfterVariableDeclaration = defineRule({
|
|
33
|
-
meta: {
|
|
34
|
-
docs: {
|
|
35
|
-
description: "Require a blank line after a variable declaration group and remove blank lines before related statements.",
|
|
36
|
-
},
|
|
37
|
-
type: "layout",
|
|
38
|
-
fixable: "whitespace",
|
|
39
|
-
messages: {
|
|
40
|
-
blankLine: "Expected a blank line after a variable declaration group when another statement follows.",
|
|
41
|
-
unexpectedBlankLine: "Expected no blank line between a variable declaration and its related statement.",
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
create(context) {
|
|
45
|
-
const sourceCode = context.sourceCode;
|
|
46
|
-
function checkStatement(node) {
|
|
47
|
-
const variableDeclaration = getVariableDeclaration(node);
|
|
48
|
-
if (variableDeclaration === null) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (node.type === "VariableDeclaration" && node.parent.type === "ExportNamedDeclaration") {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
const previousStatement = getPreviousStatement(node);
|
|
55
|
-
if (previousStatement !== null && getVariableDeclaration(previousStatement) !== null) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const variables = new Set(sourceCode.getDeclaredVariables(variableDeclaration));
|
|
59
|
-
let last = node;
|
|
60
|
-
let nextStatement = getNextStatement(last);
|
|
61
|
-
while (nextStatement !== null) {
|
|
62
|
-
const nextVariableDeclaration = getVariableDeclaration(nextStatement);
|
|
63
|
-
if (nextVariableDeclaration !== null && getVariableDeclaration(last) !== null) {
|
|
64
|
-
for (const variable of sourceCode.getDeclaredVariables(nextVariableDeclaration)) {
|
|
65
|
-
variables.add(variable);
|
|
66
|
-
}
|
|
67
|
-
last = nextStatement;
|
|
68
|
-
nextStatement = getNextStatement(last);
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (nextStatement.type === "ExpressionStatement" &&
|
|
72
|
-
isRelatedExpression(nextStatement, variables)) {
|
|
73
|
-
const target = getInsertionTarget(last, nextStatement, sourceCode);
|
|
74
|
-
if (hasBlankLine(last, target)) {
|
|
75
|
-
context.report({
|
|
76
|
-
fix(fixer) {
|
|
77
|
-
return getRemoveBlankLineFix(fixer, sourceCode, last, target);
|
|
78
|
-
},
|
|
79
|
-
node: nextStatement,
|
|
80
|
-
messageId: "unexpectedBlankLine",
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
last = nextStatement;
|
|
84
|
-
nextStatement = getNextStatement(last);
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
if (nextStatement === null ||
|
|
90
|
-
nextStatement.type === "EmptyStatement" ||
|
|
91
|
-
nextStatement.type === "ReturnStatement") {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const target = getInsertionTarget(last, nextStatement, sourceCode);
|
|
95
|
-
if (hasBlankLine(last, target)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
context.report({
|
|
99
|
-
fix(fixer) {
|
|
100
|
-
return getBlankLineFix(fixer, sourceCode, last, target);
|
|
101
|
-
},
|
|
102
|
-
node: nextStatement,
|
|
103
|
-
messageId: "blankLine",
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
VariableDeclaration(node) {
|
|
108
|
-
checkStatement(node);
|
|
109
|
-
},
|
|
110
|
-
ExportNamedDeclaration(node) {
|
|
111
|
-
if (node.declaration?.type === "VariableDeclaration") {
|
|
112
|
-
checkStatement(node);
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
export default blankLineAfterVariableDeclaration;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blank-line-before-return.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line-before-return.ts"],"names":[],"mappings":"AA2CA;;;GAGG;AACH,QAAA,MAAM,qBAAqB,uCAmDzB,CAAC;eAEY,qBAAqB"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { defineRule } from "vite-plus/lint/plugins";
|
|
2
|
-
import { hasBlankLine, getBlankLineFix, getInsertionTarget, getPreviousStatement, } from "./blank-line.js";
|
|
3
|
-
const SKIP_PREVIOUS_TYPES = new Set([
|
|
4
|
-
// 制御ブロックは blank-line-after-control-block が担当します。
|
|
5
|
-
"DoWhileStatement",
|
|
6
|
-
"ForInStatement",
|
|
7
|
-
"ForOfStatement",
|
|
8
|
-
"ForStatement",
|
|
9
|
-
"IfStatement",
|
|
10
|
-
"SwitchStatement",
|
|
11
|
-
"TryStatement",
|
|
12
|
-
"WhileStatement",
|
|
13
|
-
// 宣言は blank-line-after-declaration が担当します。
|
|
14
|
-
"ClassDeclaration",
|
|
15
|
-
"ExportAllDeclaration",
|
|
16
|
-
"ExportDefaultDeclaration",
|
|
17
|
-
"ExportNamedDeclaration",
|
|
18
|
-
"FunctionDeclaration",
|
|
19
|
-
"ImportDeclaration",
|
|
20
|
-
"TSDeclareFunction",
|
|
21
|
-
"TSEnumDeclaration",
|
|
22
|
-
"TSInterfaceDeclaration",
|
|
23
|
-
"TSModuleDeclaration",
|
|
24
|
-
"TSTypeAliasDeclaration",
|
|
25
|
-
// 途中で終わる文や空文の後は対象外にします。
|
|
26
|
-
"BlockStatement",
|
|
27
|
-
"BreakStatement",
|
|
28
|
-
"ContinueStatement",
|
|
29
|
-
"DebuggerStatement",
|
|
30
|
-
"EmptyStatement",
|
|
31
|
-
"LabeledStatement",
|
|
32
|
-
"ReturnStatement",
|
|
33
|
-
"ThrowStatement",
|
|
34
|
-
"WithStatement",
|
|
35
|
-
]);
|
|
36
|
-
/**
|
|
37
|
-
* return の直前に処理がある場合、空行を 1 行以上確保します。
|
|
38
|
-
* 余分な空行は Oxfmt が 1 行に畳みます。
|
|
39
|
-
*/
|
|
40
|
-
const blankLineBeforeReturn = defineRule({
|
|
41
|
-
meta: {
|
|
42
|
-
docs: {
|
|
43
|
-
description: "Require a blank line before a return statement when another statement precedes it.",
|
|
44
|
-
},
|
|
45
|
-
type: "layout",
|
|
46
|
-
fixable: "whitespace",
|
|
47
|
-
messages: {
|
|
48
|
-
blankLine: "Expected a blank line before a return statement when another statement precedes it.",
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
create(context) {
|
|
52
|
-
const sourceCode = context.sourceCode;
|
|
53
|
-
return {
|
|
54
|
-
ReturnStatement(node) {
|
|
55
|
-
const previousStatement = getPreviousStatement(node);
|
|
56
|
-
if (previousStatement === null) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (SKIP_PREVIOUS_TYPES.has(previousStatement.type)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (previousStatement.type === "ExpressionStatement" &&
|
|
63
|
-
typeof previousStatement.directive === "string") {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const target = getInsertionTarget(previousStatement, node, sourceCode);
|
|
67
|
-
if (hasBlankLine(previousStatement, target)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
context.report({
|
|
71
|
-
fix(fixer) {
|
|
72
|
-
return getBlankLineFix(fixer, sourceCode, previousStatement, target);
|
|
73
|
-
},
|
|
74
|
-
node,
|
|
75
|
-
messageId: "blankLine",
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
export default blankLineBeforeReturn;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* クラスメンバーの間に空行を 1 行以上確保します。
|
|
3
|
-
*
|
|
4
|
-
* オーバーロード署名と getter/setter のペアは連続させます。
|
|
5
|
-
*/
|
|
6
|
-
declare const blankLineBetweenClassMembers: import("vite-plus/lint/plugins").Rule;
|
|
7
|
-
export default blankLineBetweenClassMembers;
|
|
8
|
-
//# sourceMappingURL=blank-line-between-class-members.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blank-line-between-class-members.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line-between-class-members.ts"],"names":[],"mappings":"AA2DA;;;;GAIG;AACH,QAAA,MAAM,4BAA4B,uCA6ChC,CAAC;eAEY,4BAA4B"}
|