@tai-kun/vp-lint-plugins 0.0.4 → 0.0.5
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/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/overload-signatures-adjacent.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/blank-line.ts +555 -97
- package/src/rules/overload-signatures-adjacent.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/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/index.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export { default as blankLineAfterDeclaration } from "./rules/blank-line-after-declaration.js";
|
|
3
|
-
export { default as blankLineAfterVariableDeclaration } from "./rules/blank-line-after-variable-declaration.js";
|
|
4
|
-
export { default as blankLineBeforeReturn } from "./rules/blank-line-before-return.js";
|
|
5
|
-
export { default as blankLineBetweenClassMembers } from "./rules/blank-line-between-class-members.js";
|
|
6
|
-
export { default as blankLineBetweenSwitchCases } from "./rules/blank-line-between-switch-cases.js";
|
|
1
|
+
export { default as blankLine } from "./rules/blank-line.js";
|
|
7
2
|
export { default as commentJapaneseSpacing } from "./rules/comment-japanese-spacing.js";
|
|
8
3
|
export { default as commentOneSentencePerLine } from "./rules/comment-one-sentence-per-line.js";
|
|
9
4
|
export { default as jsdocParamOrder } from "./rules/jsdoc-param-order.js";
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,0CAA0C,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC1F,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACjG,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,4BAA4B,EAAE,MAAM,4CAA4C,CAAC;AAErG,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export { default as blankLineAfterDeclaration } from "./rules/blank-line-after-declaration.js";
|
|
3
|
-
export { default as blankLineAfterVariableDeclaration } from "./rules/blank-line-after-variable-declaration.js";
|
|
4
|
-
export { default as blankLineBeforeReturn } from "./rules/blank-line-before-return.js";
|
|
5
|
-
export { default as blankLineBetweenClassMembers } from "./rules/blank-line-between-class-members.js";
|
|
6
|
-
export { default as blankLineBetweenSwitchCases } from "./rules/blank-line-between-switch-cases.js";
|
|
1
|
+
export { default as blankLine } from "./rules/blank-line.js";
|
|
7
2
|
export { default as commentJapaneseSpacing } from "./rules/comment-japanese-spacing.js";
|
|
8
3
|
export { default as commentOneSentencePerLine } from "./rules/comment-one-sentence-per-line.js";
|
|
9
4
|
export { default as jsdocParamOrder } from "./rules/jsdoc-param-order.js";
|
package/dist/src/plugin.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { definePlugin } from "vite-plus/lint/plugins";
|
|
2
|
-
import
|
|
3
|
-
import blankLineAfterDeclaration from "./rules/blank-line-after-declaration.js";
|
|
4
|
-
import blankLineAfterVariableDeclaration from "./rules/blank-line-after-variable-declaration.js";
|
|
5
|
-
import blankLineBeforeReturn from "./rules/blank-line-before-return.js";
|
|
6
|
-
import blankLineBetweenClassMembers from "./rules/blank-line-between-class-members.js";
|
|
7
|
-
import blankLineBetweenSwitchCases from "./rules/blank-line-between-switch-cases.js";
|
|
2
|
+
import blankLine from "./rules/blank-line.js";
|
|
8
3
|
import commentJapaneseSpacing from "./rules/comment-japanese-spacing.js";
|
|
9
4
|
import commentOneSentencePerLine from "./rules/comment-one-sentence-per-line.js";
|
|
10
5
|
import jsdocParamOrder from "./rules/jsdoc-param-order.js";
|
|
@@ -23,6 +18,7 @@ import typeLiteralPropertiesNewline from "./rules/type-literal-properties-newlin
|
|
|
23
18
|
export default definePlugin({
|
|
24
19
|
meta: { name: "tai-kun" },
|
|
25
20
|
rules: {
|
|
21
|
+
"blank-line": blankLine,
|
|
26
22
|
"merge-imports": mergeImports,
|
|
27
23
|
"sort-jsx-props": sortJsxProps,
|
|
28
24
|
"spaced-comment": spacedComment,
|
|
@@ -32,17 +28,11 @@ export default definePlugin({
|
|
|
32
28
|
"jsdoc-param-order": jsdocParamOrder,
|
|
33
29
|
"sort-type-members": sortTypeMembers,
|
|
34
30
|
"sort-object-properties": sortObjectProperties,
|
|
35
|
-
"blank-line-before-return": blankLineBeforeReturn,
|
|
36
31
|
"comment-japanese-spacing": commentJapaneseSpacing,
|
|
37
32
|
"object-properties-newline": objectPropertiesNewline,
|
|
38
|
-
"blank-line-after-declaration": blankLineAfterDeclaration,
|
|
39
33
|
"overload-signatures-adjacent": overloadSignaturesAdjacent,
|
|
40
34
|
"comment-one-sentence-per-line": commentOneSentencePerLine,
|
|
41
35
|
"sort-import-export-specifiers": sortImportExportSpecifiers,
|
|
42
|
-
"blank-line-after-control-block": blankLineAfterControlBlock,
|
|
43
|
-
"blank-line-between-switch-cases": blankLineBetweenSwitchCases,
|
|
44
36
|
"type-literal-properties-newline": typeLiteralPropertiesNewline,
|
|
45
|
-
"blank-line-between-class-members": blankLineBetweenClassMembers,
|
|
46
|
-
"blank-line-after-variable-declaration": blankLineAfterVariableDeclaration,
|
|
47
37
|
},
|
|
48
38
|
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Fix, Fixer, ESTree, Comment, SourceCode } from "vite-plus/lint/plugins";
|
|
2
|
+
declare function getNextStatement(node: ESTree.Node): ESTree.Node | null;
|
|
3
|
+
declare function getPreviousStatement(node: ESTree.Node): ESTree.Node | null;
|
|
4
|
+
/**
|
|
5
|
+
* 空行の挿入位置を返します。
|
|
6
|
+
*
|
|
7
|
+
* 次の文に付くコメントがある場合は、そのコメントの前を挿入位置にします。
|
|
8
|
+
* 同じ行の末尾コメントは対象外です。
|
|
9
|
+
*/
|
|
10
|
+
declare function getInsertionTarget(node: ESTree.Node, nextStatement: ESTree.Node, sourceCode: SourceCode): ESTree.Node | Comment;
|
|
11
|
+
declare function hasBlankLine(node: ESTree.Node, target: ESTree.Node | Comment): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* 挿入対象がコメントかどうかを返します。
|
|
14
|
+
*
|
|
15
|
+
* コメントを挟む場合、前後の空行は任意とします。
|
|
16
|
+
*/
|
|
17
|
+
declare function isComment(target: ESTree.Node | Comment): target is Comment;
|
|
18
|
+
/**
|
|
19
|
+
* JSDoc 形式のブロックコメント(`/**` で始まる)かどうかを返します。
|
|
20
|
+
*
|
|
21
|
+
* JSDoc 形式のブロックコメントの 1 行上は空行にします。
|
|
22
|
+
*/
|
|
23
|
+
declare function isDocComment(target: ESTree.Node | Comment): target is Comment;
|
|
24
|
+
declare function getBlankLineFix(fixer: Fixer, sourceCode: SourceCode, node: ESTree.Node, target: ESTree.Node | Comment): Fix | null;
|
|
25
|
+
/**
|
|
26
|
+
* 指定したノードと対象の間の空行を削除します。
|
|
27
|
+
*/
|
|
28
|
+
declare function getRemoveBlankLineFix(fixer: Fixer, sourceCode: SourceCode, node: ESTree.Node, target: ESTree.Node | Comment): Fix | null;
|
|
29
|
+
export { isComment, hasBlankLine, isDocComment, getBlankLineFix, getNextStatement, getInsertionTarget, getPreviousStatement, getRemoveBlankLineFix, };
|
|
30
|
+
//# sourceMappingURL=blank-line-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blank-line-utils.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AA4BtF,iBAAS,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,IAAI,CAc/D;AAED,iBAAS,oBAAoB,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,GAAG,IAAI,CAcnE;AAED;;;;;GAKG;AACH,iBAAS,kBAAkB,CACzB,IAAI,EAAE,MAAM,CAAC,IAAI,EACjB,aAAa,EAAE,MAAM,CAAC,IAAI,EAC1B,UAAU,EAAE,UAAU,GACrB,MAAM,CAAC,IAAI,GAAG,OAAO,CAWvB;AAED,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,OAAO,CAE/E;AAED;;;;GAIG;AACH,iBAAS,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,MAAM,IAAI,OAAO,CAInE;AAED;;;;GAIG;AACH,iBAAS,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,GAAG,MAAM,IAAI,OAAO,CAEtE;AAED,iBAAS,eAAe,CACtB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,CAAC,IAAI,EACjB,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,GAC5B,GAAG,GAAG,IAAI,CAYZ;AAED;;GAEG;AACH,iBAAS,qBAAqB,CAC5B,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,CAAC,IAAI,EACjB,MAAM,EAAE,MAAM,CAAC,IAAI,GAAG,OAAO,GAC5B,GAAG,GAAG,IAAI,CAmBZ;AAED,OAAO,EACL,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文の配列を持つ親から、その文が属する配列を取得します。
|
|
3
|
+
*/
|
|
4
|
+
function getStatementBody(node) {
|
|
5
|
+
const { parent } = node;
|
|
6
|
+
if (parent === null) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
if (parent.type === "Program" ||
|
|
10
|
+
parent.type === "BlockStatement" ||
|
|
11
|
+
parent.type === "StaticBlock" ||
|
|
12
|
+
parent.type === "TSModuleBlock") {
|
|
13
|
+
return parent.body;
|
|
14
|
+
}
|
|
15
|
+
if (parent.type === "SwitchCase") {
|
|
16
|
+
return parent.consequent;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
function getNextStatement(node) {
|
|
21
|
+
const body = getStatementBody(node);
|
|
22
|
+
if (body === null) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const index = body.indexOf(node);
|
|
26
|
+
if (index === -1 || index === body.length - 1) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return body[index + 1] ?? null;
|
|
30
|
+
}
|
|
31
|
+
function getPreviousStatement(node) {
|
|
32
|
+
const body = getStatementBody(node);
|
|
33
|
+
if (body === null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const index = body.indexOf(node);
|
|
37
|
+
if (index <= 0) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return body[index - 1] ?? null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 空行の挿入位置を返します。
|
|
44
|
+
*
|
|
45
|
+
* 次の文に付くコメントがある場合は、そのコメントの前を挿入位置にします。
|
|
46
|
+
* 同じ行の末尾コメントは対象外です。
|
|
47
|
+
*/
|
|
48
|
+
function getInsertionTarget(node, nextStatement, sourceCode) {
|
|
49
|
+
return (sourceCode
|
|
50
|
+
.getAllComments()
|
|
51
|
+
.find((comment) => comment.range[0] >= node.range[1] &&
|
|
52
|
+
comment.range[1] <= nextStatement.range[0] &&
|
|
53
|
+
comment.loc.start.line > node.loc.end.line) ?? nextStatement);
|
|
54
|
+
}
|
|
55
|
+
function hasBlankLine(node, target) {
|
|
56
|
+
return target.loc.start.line > node.loc.end.line + 1;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 挿入対象がコメントかどうかを返します。
|
|
60
|
+
*
|
|
61
|
+
* コメントを挟む場合、前後の空行は任意とします。
|
|
62
|
+
*/
|
|
63
|
+
function isComment(target) {
|
|
64
|
+
const { type } = target;
|
|
65
|
+
return type === "Line" || type === "Block" || type === "Shebang";
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* JSDoc 形式のブロックコメント(`/**` で始まる)かどうかを返します。
|
|
69
|
+
*
|
|
70
|
+
* JSDoc 形式のブロックコメントの 1 行上は空行にします。
|
|
71
|
+
*/
|
|
72
|
+
function isDocComment(target) {
|
|
73
|
+
return isComment(target) && target.type === "Block" && target.value.startsWith("*");
|
|
74
|
+
}
|
|
75
|
+
function getBlankLineFix(fixer, sourceCode, node, target) {
|
|
76
|
+
if (target.loc.start.line === node.loc.end.line) {
|
|
77
|
+
return fixer.insertTextAfterRange([node.range[1], node.range[1]], "\n\n");
|
|
78
|
+
}
|
|
79
|
+
const lineEnd = sourceCode.text.indexOf("\n", node.range[1]);
|
|
80
|
+
if (lineEnd === -1) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
return fixer.insertTextBeforeRange([lineEnd, lineEnd + 1], "\n");
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 指定したノードと対象の間の空行を削除します。
|
|
87
|
+
*/
|
|
88
|
+
function getRemoveBlankLineFix(fixer, sourceCode, node, target) {
|
|
89
|
+
if (target.loc.start.line <= node.loc.end.line + 1) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const fromLineEnd = sourceCode.text.indexOf("\n", node.range[1]);
|
|
93
|
+
if (fromLineEnd === -1) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const targetLineStart = sourceCode.text.lastIndexOf("\n", target.range[0]) + 1;
|
|
97
|
+
const indent = sourceCode.text.slice(targetLineStart, target.range[0]);
|
|
98
|
+
if (indent.trim() !== "") {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return fixer.replaceTextRange([fromLineEnd, target.range[0]], `\n${indent}`);
|
|
102
|
+
}
|
|
103
|
+
export { isComment, hasBlankLine, isDocComment, getBlankLineFix, getNextStatement, getInsertionTarget, getPreviousStatement, getRemoveBlankLineFix, };
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import type { Fix, Fixer, ESTree, Comment, SourceCode } from "vite-plus/lint/plugins";
|
|
2
|
-
declare function getNextStatement(node: ESTree.Node): ESTree.Node | null;
|
|
3
|
-
declare function getPreviousStatement(node: ESTree.Node): ESTree.Node | null;
|
|
4
1
|
/**
|
|
5
|
-
*
|
|
2
|
+
* 宣言・制御ブロック・変数宣言グループ・return・クラスや型のメンバー・switch の case における空行を、1 つのルールでまとめて扱います。
|
|
6
3
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* 文の境界ごとに該当する項目を 1 つだけ判定するため、複数の診断が同じ箇所で矛盾しません。
|
|
5
|
+
* 行コメントや通常のブロックコメントを挟む場合、前後の空行は任意とします。
|
|
9
6
|
*/
|
|
10
|
-
declare
|
|
11
|
-
|
|
12
|
-
declare function getBlankLineFix(fixer: Fixer, sourceCode: SourceCode, node: ESTree.Node, target: ESTree.Node | Comment): Fix | null;
|
|
13
|
-
/**
|
|
14
|
-
* 指定したノードと対象の間の空行を削除します。
|
|
15
|
-
*/
|
|
16
|
-
declare function getRemoveBlankLineFix(fixer: Fixer, sourceCode: SourceCode, node: ESTree.Node, target: ESTree.Node | Comment): Fix | null;
|
|
17
|
-
export { hasBlankLine, getBlankLineFix, getNextStatement, getInsertionTarget, getPreviousStatement, getRemoveBlankLineFix, };
|
|
7
|
+
declare const blankLine: import("vite-plus/lint/plugins").Rule;
|
|
8
|
+
export default blankLine;
|
|
18
9
|
//# sourceMappingURL=blank-line.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blank-line.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"blank-line.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line.ts"],"names":[],"mappings":"AAoPA;;;;;GAKG;AACH,QAAA,MAAM,SAAS,uCA4Vb,CAAC;eAEY,SAAS"}
|