@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.
Files changed (41) hide show
  1. package/dist/src/index.d.ts +1 -6
  2. package/dist/src/index.d.ts.map +1 -1
  3. package/dist/src/index.js +1 -6
  4. package/dist/src/plugin.js +2 -12
  5. package/dist/src/rules/blank-line-utils.d.ts +30 -0
  6. package/dist/src/rules/blank-line-utils.d.ts.map +1 -0
  7. package/dist/src/rules/blank-line-utils.js +103 -0
  8. package/dist/src/rules/blank-line.d.ts +5 -14
  9. package/dist/src/rules/blank-line.d.ts.map +1 -1
  10. package/dist/src/rules/blank-line.js +426 -66
  11. package/dist/src/rules/overload-signatures-adjacent.js +1 -1
  12. package/package.json +1 -1
  13. package/src/index.ts +1 -6
  14. package/src/plugin.ts +2 -12
  15. package/src/rules/blank-line-utils.ts +165 -0
  16. package/src/rules/blank-line.ts +555 -97
  17. package/src/rules/overload-signatures-adjacent.ts +1 -1
  18. package/dist/src/rules/blank-line-after-control-block.d.ts +0 -7
  19. package/dist/src/rules/blank-line-after-control-block.d.ts.map +0 -1
  20. package/dist/src/rules/blank-line-after-control-block.js +0 -54
  21. package/dist/src/rules/blank-line-after-declaration.d.ts +0 -7
  22. package/dist/src/rules/blank-line-after-declaration.d.ts.map +0 -1
  23. package/dist/src/rules/blank-line-after-declaration.js +0 -79
  24. package/dist/src/rules/blank-line-after-variable-declaration.d.ts +0 -9
  25. package/dist/src/rules/blank-line-after-variable-declaration.d.ts.map +0 -1
  26. package/dist/src/rules/blank-line-after-variable-declaration.js +0 -118
  27. package/dist/src/rules/blank-line-before-return.d.ts +0 -7
  28. package/dist/src/rules/blank-line-before-return.d.ts.map +0 -1
  29. package/dist/src/rules/blank-line-before-return.js +0 -81
  30. package/dist/src/rules/blank-line-between-class-members.d.ts +0 -8
  31. package/dist/src/rules/blank-line-between-class-members.d.ts.map +0 -1
  32. package/dist/src/rules/blank-line-between-class-members.js +0 -85
  33. package/dist/src/rules/blank-line-between-switch-cases.d.ts +0 -8
  34. package/dist/src/rules/blank-line-between-switch-cases.d.ts.map +0 -1
  35. package/dist/src/rules/blank-line-between-switch-cases.js +0 -45
  36. package/src/rules/blank-line-after-control-block.ts +0 -82
  37. package/src/rules/blank-line-after-declaration.ts +0 -106
  38. package/src/rules/blank-line-after-variable-declaration.ts +0 -165
  39. package/src/rules/blank-line-before-return.ts +0 -101
  40. package/src/rules/blank-line-between-class-members.ts +0 -112
  41. package/src/rules/blank-line-between-switch-cases.ts +0 -53
@@ -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 "./blank-line.js";
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 +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,7 +0,0 @@
1
- /**
2
- * return の直前に処理がある場合、空行を 1 行以上確保します。
3
- * 余分な空行は Oxfmt が 1 行に畳みます。
4
- */
5
- declare const blankLineBeforeReturn: import("vite-plus/lint/plugins").Rule;
6
- export default blankLineBeforeReturn;
7
- //# sourceMappingURL=blank-line-before-return.d.ts.map
@@ -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"}
@@ -1,85 +0,0 @@
1
- import { defineRule } from "vite-plus/lint/plugins";
2
- import { hasBlankLine, getBlankLineFix, getInsertionTarget } from "./blank-line.js";
3
- function getKeyName(member) {
4
- if (member.type === "TSIndexSignature" || member.type === "StaticBlock") {
5
- return null;
6
- }
7
- if (member.computed) {
8
- return null;
9
- }
10
- const key = member.key;
11
- if (key.type === "Identifier") {
12
- return key.name;
13
- }
14
- if (key.type === "Literal" && (typeof key.value === "string" || typeof key.value === "number")) {
15
- return String(key.value);
16
- }
17
- return null;
18
- }
19
- function isOverload(member) {
20
- return member.type === "MethodDefinition" && member.value.body === null;
21
- }
22
- function isGetterSetterPair(previous, next) {
23
- if (previous.type !== "MethodDefinition" || next.type !== "MethodDefinition") {
24
- return false;
25
- }
26
- if (!((previous.kind === "get" && next.kind === "set") ||
27
- (previous.kind === "set" && next.kind === "get"))) {
28
- return false;
29
- }
30
- const previousName = getKeyName(previous);
31
- const nextName = getKeyName(next);
32
- return previousName !== null && previousName === nextName;
33
- }
34
- function getMemberStart(member) {
35
- if (member.type === "TSIndexSignature" || member.type === "StaticBlock") {
36
- return member;
37
- }
38
- return member.decorators[0] ?? member;
39
- }
40
- /**
41
- * クラスメンバーの間に空行を 1 行以上確保します。
42
- *
43
- * オーバーロード署名と getter/setter のペアは連続させます。
44
- */
45
- const blankLineBetweenClassMembers = defineRule({
46
- meta: {
47
- docs: {
48
- description: "Require a blank line between class members.",
49
- },
50
- type: "layout",
51
- fixable: "whitespace",
52
- messages: {
53
- blankLine: "Expected a blank line between class members.",
54
- },
55
- },
56
- create(context) {
57
- const sourceCode = context.sourceCode;
58
- return {
59
- ClassBody(node) {
60
- for (let index = 1; index < node.body.length; index += 1) {
61
- const previous = node.body[index - 1];
62
- const next = node.body[index];
63
- if (previous === undefined || next === undefined) {
64
- continue;
65
- }
66
- if (isOverload(previous) || isGetterSetterPair(previous, next)) {
67
- continue;
68
- }
69
- const target = getInsertionTarget(previous, getMemberStart(next), sourceCode);
70
- if (hasBlankLine(previous, target)) {
71
- continue;
72
- }
73
- context.report({
74
- fix(fixer) {
75
- return getBlankLineFix(fixer, sourceCode, previous, target);
76
- },
77
- node: next,
78
- messageId: "blankLine",
79
- });
80
- }
81
- },
82
- };
83
- },
84
- });
85
- export default blankLineBetweenClassMembers;
@@ -1,8 +0,0 @@
1
- /**
2
- * 空でない switch の case の間に空行を 1 行以上確保します。
3
- *
4
- * 連続する case はフォールスルーとみなし、対象外にします。
5
- */
6
- declare const blankLineBetweenSwitchCases: import("vite-plus/lint/plugins").Rule;
7
- export default blankLineBetweenSwitchCases;
8
- //# sourceMappingURL=blank-line-between-switch-cases.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"blank-line-between-switch-cases.d.ts","sourceRoot":"","sources":["../../../src/rules/blank-line-between-switch-cases.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,QAAA,MAAM,2BAA2B,uCAyC/B,CAAC;eAEY,2BAA2B"}
@@ -1,45 +0,0 @@
1
- import { defineRule } from "vite-plus/lint/plugins";
2
- import { hasBlankLine, getBlankLineFix, getInsertionTarget } from "./blank-line.js";
3
- /**
4
- * 空でない switch の case の間に空行を 1 行以上確保します。
5
- *
6
- * 連続する case はフォールスルーとみなし、対象外にします。
7
- */
8
- const blankLineBetweenSwitchCases = defineRule({
9
- meta: {
10
- docs: {
11
- description: "Require a blank line between non-empty switch cases.",
12
- },
13
- type: "layout",
14
- fixable: "whitespace",
15
- messages: {
16
- blankLine: "Expected a blank line between switch cases.",
17
- },
18
- },
19
- create(context) {
20
- const sourceCode = context.sourceCode;
21
- return {
22
- SwitchStatement(node) {
23
- for (let index = 1; index < node.cases.length; index += 1) {
24
- const previous = node.cases[index - 1];
25
- const next = node.cases[index];
26
- if (previous === undefined || next === undefined || previous.consequent.length === 0) {
27
- continue;
28
- }
29
- const target = getInsertionTarget(previous, next, sourceCode);
30
- if (hasBlankLine(previous, target)) {
31
- continue;
32
- }
33
- context.report({
34
- fix(fixer) {
35
- return getBlankLineFix(fixer, sourceCode, previous, target);
36
- },
37
- node: next,
38
- messageId: "blankLine",
39
- });
40
- }
41
- },
42
- };
43
- },
44
- });
45
- export default blankLineBetweenSwitchCases;
@@ -1,82 +0,0 @@
1
- import { defineRule } from "vite-plus/lint/plugins";
2
- import type { ESTree, Visitor } from "vite-plus/lint/plugins";
3
-
4
- import {
5
- hasBlankLine,
6
- getBlankLineFix,
7
- getNextStatement,
8
- getInsertionTarget,
9
- } from "./blank-line.js";
10
-
11
- type ControlStatement =
12
- | ESTree.DoWhileStatement
13
- | ESTree.ForInStatement
14
- | ESTree.ForOfStatement
15
- | ESTree.ForStatement
16
- | ESTree.IfStatement
17
- | ESTree.SwitchStatement
18
- | ESTree.TryStatement
19
- | ESTree.WhileStatement;
20
-
21
- const CONTROL_STATEMENT_TYPES: ReadonlySet<ControlStatement["type"]> = new Set([
22
- "DoWhileStatement",
23
- "ForInStatement",
24
- "ForOfStatement",
25
- "ForStatement",
26
- "IfStatement",
27
- "SwitchStatement",
28
- "TryStatement",
29
- "WhileStatement",
30
- ]);
31
-
32
- /**
33
- * 制御ブロックの直後に次の処理がある場合、空行を 1 行以上確保します。
34
- * 余分な空行は Oxfmt が 1 行に畳みます。
35
- */
36
- const blankLineAfterControlBlock = defineRule({
37
- meta: {
38
- docs: {
39
- description: "Require a blank line after a control block when another statement follows.",
40
- },
41
- type: "layout",
42
- fixable: "whitespace",
43
- messages: {
44
- blankLine: "Expected a blank line after a control block when another statement follows.",
45
- },
46
- },
47
- create(context) {
48
- const sourceCode = context.sourceCode;
49
-
50
- function checkNode(node: ESTree.Node): void {
51
- const nextStatement = getNextStatement(node);
52
-
53
- if (nextStatement === null || nextStatement.type === "EmptyStatement") {
54
- return;
55
- }
56
-
57
- const target = getInsertionTarget(node, nextStatement, sourceCode);
58
-
59
- if (hasBlankLine(node, target)) {
60
- return;
61
- }
62
-
63
- context.report({
64
- fix(fixer) {
65
- return getBlankLineFix(fixer, sourceCode, node, target);
66
- },
67
- node,
68
- messageId: "blankLine",
69
- });
70
- }
71
-
72
- const visitors: Visitor = {};
73
-
74
- for (const type of CONTROL_STATEMENT_TYPES) {
75
- visitors[type] = checkNode;
76
- }
77
-
78
- return visitors;
79
- },
80
- });
81
-
82
- export default blankLineAfterControlBlock;