@tai-kun/vp-lint-plugins 0.0.0-stage → 0.0.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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -2
  3. package/dist/src/index.d.ts +22 -0
  4. package/dist/src/index.d.ts.map +1 -0
  5. package/dist/src/index.js +21 -0
  6. package/dist/src/plugin.d.ts +3 -0
  7. package/dist/src/plugin.d.ts.map +1 -0
  8. package/dist/src/plugin.js +46 -0
  9. package/dist/src/rules/blank-line-after-control-block.d.ts +7 -0
  10. package/dist/src/rules/blank-line-after-control-block.d.ts.map +1 -0
  11. package/dist/src/rules/blank-line-after-control-block.js +54 -0
  12. package/dist/src/rules/blank-line-after-declaration.d.ts +7 -0
  13. package/dist/src/rules/blank-line-after-declaration.d.ts.map +1 -0
  14. package/dist/src/rules/blank-line-after-declaration.js +79 -0
  15. package/dist/src/rules/blank-line-after-variable-declaration.d.ts +8 -0
  16. package/dist/src/rules/blank-line-after-variable-declaration.d.ts.map +1 -0
  17. package/dist/src/rules/blank-line-after-variable-declaration.js +62 -0
  18. package/dist/src/rules/blank-line-before-return.d.ts +7 -0
  19. package/dist/src/rules/blank-line-before-return.d.ts.map +1 -0
  20. package/dist/src/rules/blank-line-before-return.js +81 -0
  21. package/dist/src/rules/blank-line-between-class-members.d.ts +8 -0
  22. package/dist/src/rules/blank-line-between-class-members.d.ts.map +1 -0
  23. package/dist/src/rules/blank-line-between-class-members.js +85 -0
  24. package/dist/src/rules/blank-line-between-switch-cases.d.ts +8 -0
  25. package/dist/src/rules/blank-line-between-switch-cases.d.ts.map +1 -0
  26. package/dist/src/rules/blank-line-between-switch-cases.js +45 -0
  27. package/dist/src/rules/blank-line.d.ts +14 -0
  28. package/dist/src/rules/blank-line.d.ts.map +1 -0
  29. package/dist/src/rules/blank-line.js +68 -0
  30. package/dist/src/rules/comment-japanese-spacing.d.ts +8 -0
  31. package/dist/src/rules/comment-japanese-spacing.d.ts.map +1 -0
  32. package/dist/src/rules/comment-japanese-spacing.js +195 -0
  33. package/dist/src/rules/comment-one-sentence-per-line.d.ts +9 -0
  34. package/dist/src/rules/comment-one-sentence-per-line.d.ts.map +1 -0
  35. package/dist/src/rules/comment-one-sentence-per-line.js +190 -0
  36. package/dist/src/rules/comment-utils.d.ts +30 -0
  37. package/dist/src/rules/comment-utils.d.ts.map +1 -0
  38. package/dist/src/rules/comment-utils.js +153 -0
  39. package/dist/src/rules/jsdoc-param-order.d.ts +6 -0
  40. package/dist/src/rules/jsdoc-param-order.d.ts.map +1 -0
  41. package/dist/src/rules/jsdoc-param-order.js +101 -0
  42. package/dist/src/rules/jsdoc-tag-lines.d.ts +6 -0
  43. package/dist/src/rules/jsdoc-tag-lines.d.ts.map +1 -0
  44. package/dist/src/rules/jsdoc-tag-lines.js +128 -0
  45. package/dist/src/rules/jsdoc-tag-order.d.ts +6 -0
  46. package/dist/src/rules/jsdoc-tag-order.d.ts.map +1 -0
  47. package/dist/src/rules/jsdoc-tag-order.js +62 -0
  48. package/dist/src/rules/jsdoc-utils.d.ts +26 -0
  49. package/dist/src/rules/jsdoc-utils.d.ts.map +1 -0
  50. package/dist/src/rules/jsdoc-utils.js +132 -0
  51. package/dist/src/rules/member-ordering.d.ts +6 -0
  52. package/dist/src/rules/member-ordering.d.ts.map +1 -0
  53. package/dist/src/rules/member-ordering.js +66 -0
  54. package/dist/src/rules/object-properties-newline.d.ts +9 -0
  55. package/dist/src/rules/object-properties-newline.d.ts.map +1 -0
  56. package/dist/src/rules/object-properties-newline.js +47 -0
  57. package/dist/src/rules/object-sort-utils.d.ts +32 -0
  58. package/dist/src/rules/object-sort-utils.d.ts.map +1 -0
  59. package/dist/src/rules/object-sort-utils.js +221 -0
  60. package/dist/src/rules/overload-signatures-adjacent.d.ts +6 -0
  61. package/dist/src/rules/overload-signatures-adjacent.d.ts.map +1 -0
  62. package/dist/src/rules/overload-signatures-adjacent.js +143 -0
  63. package/dist/src/rules/sort-import-export-specifiers.d.ts +8 -0
  64. package/dist/src/rules/sort-import-export-specifiers.d.ts.map +1 -0
  65. package/dist/src/rules/sort-import-export-specifiers.js +130 -0
  66. package/dist/src/rules/sort-jsx-props.d.ts +7 -0
  67. package/dist/src/rules/sort-jsx-props.d.ts.map +1 -0
  68. package/dist/src/rules/sort-jsx-props.js +102 -0
  69. package/dist/src/rules/sort-object-properties.d.ts +9 -0
  70. package/dist/src/rules/sort-object-properties.d.ts.map +1 -0
  71. package/dist/src/rules/sort-object-properties.js +54 -0
  72. package/dist/src/rules/sort-type-members.d.ts +8 -0
  73. package/dist/src/rules/sort-type-members.d.ts.map +1 -0
  74. package/dist/src/rules/sort-type-members.js +213 -0
  75. package/dist/src/rules/spaced-comment.d.ts +6 -0
  76. package/dist/src/rules/spaced-comment.d.ts.map +1 -0
  77. package/dist/src/rules/spaced-comment.js +105 -0
  78. package/dist/src/rules/type-literal-properties-newline.d.ts +8 -0
  79. package/dist/src/rules/type-literal-properties-newline.d.ts.map +1 -0
  80. package/dist/src/rules/type-literal-properties-newline.js +39 -0
  81. package/package.json +39 -3
  82. package/src/index.ts +22 -0
  83. package/src/plugin.ts +48 -0
  84. package/src/rules/blank-line-after-control-block.ts +82 -0
  85. package/src/rules/blank-line-after-declaration.ts +106 -0
  86. package/src/rules/blank-line-after-variable-declaration.ts +84 -0
  87. package/src/rules/blank-line-before-return.ts +101 -0
  88. package/src/rules/blank-line-between-class-members.ts +112 -0
  89. package/src/rules/blank-line-between-switch-cases.ts +53 -0
  90. package/src/rules/blank-line.ts +113 -0
  91. package/src/rules/comment-japanese-spacing.ts +271 -0
  92. package/src/rules/comment-one-sentence-per-line.ts +264 -0
  93. package/src/rules/comment-utils.ts +218 -0
  94. package/src/rules/jsdoc-param-order.ts +137 -0
  95. package/src/rules/jsdoc-tag-lines.ts +165 -0
  96. package/src/rules/jsdoc-tag-order.ts +75 -0
  97. package/src/rules/jsdoc-utils.ts +179 -0
  98. package/src/rules/member-ordering.ts +93 -0
  99. package/src/rules/object-properties-newline.ts +54 -0
  100. package/src/rules/object-sort-utils.ts +339 -0
  101. package/src/rules/overload-signatures-adjacent.ts +204 -0
  102. package/src/rules/sort-import-export-specifiers.ts +194 -0
  103. package/src/rules/sort-jsx-props.ts +149 -0
  104. package/src/rules/sort-object-properties.ts +62 -0
  105. package/src/rules/sort-type-members.ts +299 -0
  106. package/src/rules/spaced-comment.ts +129 -0
  107. package/src/rules/type-literal-properties-newline.ts +44 -0
@@ -0,0 +1,101 @@
1
+ import { defineRule } from "vite-plus/lint/plugins";
2
+ import { getNodeJSDoc, getParamName, getJSDocLines, hasExampleOrFence } from "./jsdoc-utils.js";
3
+ function getParamNameFromPattern(param) {
4
+ if (param.type === "Identifier") {
5
+ return param.name;
6
+ }
7
+ if (param.type === "AssignmentPattern") {
8
+ return param.left.type === "Identifier" ? param.left.name : null;
9
+ }
10
+ if (param.type === "RestElement") {
11
+ return param.argument.type === "Identifier" ? param.argument.name : null;
12
+ }
13
+ if (param.type === "TSParameterProperty") {
14
+ return getParamNameFromPattern(param.parameter);
15
+ }
16
+ return null;
17
+ }
18
+ function getExpectedParams(params) {
19
+ const names = [];
20
+ for (const param of params) {
21
+ const name = getParamNameFromPattern(param);
22
+ if (name === null) {
23
+ return null;
24
+ }
25
+ names.push(name);
26
+ }
27
+ return names;
28
+ }
29
+ function checkFunction(context, sourceCode, node, params) {
30
+ const comment = getNodeJSDoc(node, sourceCode);
31
+ if (comment === null) {
32
+ return;
33
+ }
34
+ const lines = getJSDocLines(comment, sourceCode);
35
+ if (lines === null || hasExampleOrFence(lines)) {
36
+ return;
37
+ }
38
+ const tagNames = lines
39
+ .filter((line) => line.tagName === "param")
40
+ .map((line) => getParamName(line.content));
41
+ if (tagNames.length === 0 || tagNames.some((name) => name === null)) {
42
+ return;
43
+ }
44
+ const expected = getExpectedParams(params);
45
+ if (expected === null || expected.length !== tagNames.length) {
46
+ return;
47
+ }
48
+ if (new Set(expected).size !== expected.length ||
49
+ new Set(tagNames).size !== tagNames.length ||
50
+ tagNames.some((name) => name?.includes(".") === true)) {
51
+ return;
52
+ }
53
+ for (const [index, name] of tagNames.entries()) {
54
+ if (name !== expected[index]) {
55
+ context.report({
56
+ loc: comment.loc,
57
+ messageId: "paramOrder",
58
+ });
59
+ return;
60
+ }
61
+ }
62
+ }
63
+ /**
64
+ * `@param` タグが関数の引数の順序に従っていることを要求します。
65
+ */
66
+ const jsdocParamOrder = defineRule({
67
+ meta: {
68
+ docs: {
69
+ description: "Require @param tags to follow the order of function parameters.",
70
+ },
71
+ type: "suggestion",
72
+ messages: {
73
+ paramOrder: "@param tags must follow the order of function parameters.",
74
+ },
75
+ },
76
+ create(context) {
77
+ const sourceCode = context.sourceCode;
78
+ return {
79
+ MethodDefinition(node) {
80
+ checkFunction(context, sourceCode, node, node.value.params);
81
+ },
82
+ TSDeclareFunction(node) {
83
+ checkFunction(context, sourceCode, node, node.params);
84
+ },
85
+ FunctionDeclaration(node) {
86
+ checkFunction(context, sourceCode, node, node.params);
87
+ },
88
+ ExportNamedDeclaration(node) {
89
+ const declaration = node.declaration;
90
+ if (declaration !== null &&
91
+ (declaration.type === "FunctionDeclaration" || declaration.type === "TSDeclareFunction")) {
92
+ checkFunction(context, sourceCode, node, declaration.params);
93
+ }
94
+ },
95
+ TSAbstractMethodDefinition(node) {
96
+ checkFunction(context, sourceCode, node, node.value.params);
97
+ },
98
+ };
99
+ },
100
+ });
101
+ export default jsdocParamOrder;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * description とタグ、タググループの間の空行を揃えます。
3
+ */
4
+ declare const jsdocTagLines: import("vite-plus/lint/plugins").Rule;
5
+ export default jsdocTagLines;
6
+ //# sourceMappingURL=jsdoc-tag-lines.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdoc-tag-lines.d.ts","sourceRoot":"","sources":["../../../src/rules/jsdoc-tag-lines.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,QAAA,MAAM,aAAa,uCAgJjB,CAAC;eAEY,aAAa"}
@@ -0,0 +1,128 @@
1
+ import { defineRule } from "vite-plus/lint/plugins";
2
+ import { getJSDocLines, hasExampleOrFence } from "./jsdoc-utils.js";
3
+ function getBlankPrefix(line) {
4
+ return line.prefix.trimEnd();
5
+ }
6
+ /**
7
+ * description とタグ、タググループの間の空行を揃えます。
8
+ */
9
+ const jsdocTagLines = defineRule({
10
+ meta: {
11
+ docs: {
12
+ description: "Require consistent blank lines between JSDoc tag groups.",
13
+ },
14
+ type: "layout",
15
+ fixable: "whitespace",
16
+ messages: {
17
+ missingBlankLine: "Expected a blank line between JSDoc tag groups.",
18
+ unexpectedBlankLine: "Unexpected blank line in a JSDoc tag group.",
19
+ },
20
+ },
21
+ create(context) {
22
+ const sourceCode = context.sourceCode;
23
+ return {
24
+ "Program:exit"() {
25
+ for (const comment of sourceCode.getAllComments()) {
26
+ if (comment.type !== "Block") {
27
+ continue;
28
+ }
29
+ const lines = getJSDocLines(comment, sourceCode);
30
+ if (lines === null || lines.length < 3 || hasExampleOrFence(lines)) {
31
+ continue;
32
+ }
33
+ const opening = lines[0];
34
+ const closing = lines.at(-1);
35
+ if (opening === undefined ||
36
+ closing === undefined ||
37
+ opening.content.trim() !== "" ||
38
+ closing.content.trim() !== "") {
39
+ continue;
40
+ }
41
+ const contentLines = lines.slice(1, -1);
42
+ const entries = [];
43
+ for (const [index, line] of contentLines.entries()) {
44
+ if (line.content.trim() !== "") {
45
+ entries.push({
46
+ line,
47
+ groupId: -1,
48
+ lineIndex: index,
49
+ });
50
+ }
51
+ }
52
+ if (entries.length === 0 || !entries.some((entry) => entry.line.tagName !== null)) {
53
+ continue;
54
+ }
55
+ let firstTagIndex = -1;
56
+ let currentGroup = -1;
57
+ let currentTag = null;
58
+ for (const [index, entry] of entries.entries()) {
59
+ if (entry.line.tagName === null) {
60
+ if (currentTag === null) {
61
+ continue;
62
+ }
63
+ entry.groupId = currentGroup;
64
+ continue;
65
+ }
66
+ if (firstTagIndex === -1) {
67
+ firstTagIndex = index;
68
+ }
69
+ if (currentTag === null || entry.line.tagName !== currentTag) {
70
+ currentGroup += 1;
71
+ currentTag = entry.line.tagName;
72
+ }
73
+ entry.groupId = currentGroup;
74
+ }
75
+ if (firstTagIndex === -1) {
76
+ continue;
77
+ }
78
+ const descriptionExists = firstTagIndex > 0;
79
+ const result = [opening.raw];
80
+ let previousEntry = null;
81
+ let missingBlankLine = false;
82
+ for (const entry of entries) {
83
+ let desiredBlankLines;
84
+ let originalBlankLines;
85
+ if (previousEntry === null) {
86
+ originalBlankLines = entry.lineIndex;
87
+ desiredBlankLines = 0;
88
+ }
89
+ else {
90
+ originalBlankLines = entry.lineIndex - previousEntry.lineIndex - 1;
91
+ if (previousEntry.groupId === -1 && entry.groupId === -1) {
92
+ desiredBlankLines = originalBlankLines;
93
+ }
94
+ else if (previousEntry.groupId === -1) {
95
+ desiredBlankLines = descriptionExists ? 1 : 0;
96
+ }
97
+ else {
98
+ desiredBlankLines = previousEntry.groupId === entry.groupId ? 0 : 1;
99
+ }
100
+ }
101
+ if (desiredBlankLines > originalBlankLines) {
102
+ missingBlankLine = true;
103
+ }
104
+ const blankPrefix = getBlankPrefix(entry.line);
105
+ for (let count = 0; count < desiredBlankLines; count += 1) {
106
+ result.push(blankPrefix);
107
+ }
108
+ result.push(entry.line.raw);
109
+ previousEntry = entry;
110
+ }
111
+ result.push(closing.raw);
112
+ const replacement = result.join("\n");
113
+ if (replacement === sourceCode.getText(comment)) {
114
+ continue;
115
+ }
116
+ context.report({
117
+ fix(fixer) {
118
+ return fixer.replaceText(comment, replacement);
119
+ },
120
+ loc: comment.loc,
121
+ messageId: missingBlankLine ? "missingBlankLine" : "unexpectedBlankLine",
122
+ });
123
+ }
124
+ },
125
+ };
126
+ },
127
+ });
128
+ export default jsdocTagLines;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * JSDoc のタグの順序を統一します。
3
+ */
4
+ declare const jsdocTagOrder: import("vite-plus/lint/plugins").Rule;
5
+ export default jsdocTagOrder;
6
+ //# sourceMappingURL=jsdoc-tag-order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdoc-tag-order.d.ts","sourceRoot":"","sources":["../../../src/rules/jsdoc-tag-order.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,QAAA,MAAM,aAAa,uCAkDjB,CAAC;eAEY,aAAa"}
@@ -0,0 +1,62 @@
1
+ import { defineRule } from "vite-plus/lint/plugins";
2
+ import { getJSDocLines, hasExampleOrFence } from "./jsdoc-utils.js";
3
+ const TAG_ORDER = {
4
+ see: 70,
5
+ beta: 65,
6
+ note: 50,
7
+ param: 10,
8
+ throws: 40,
9
+ default: 20,
10
+ returns: 30,
11
+ internal: 65,
12
+ template: 5,
13
+ typeParam: 5,
14
+ deprecated: 60,
15
+ };
16
+ const UNKNOWN_TAG_ORDER = 100;
17
+ /**
18
+ * JSDoc のタグの順序を統一します。
19
+ */
20
+ const jsdocTagOrder = defineRule({
21
+ meta: {
22
+ docs: {
23
+ description: "Enforce a consistent order of JSDoc tags.",
24
+ },
25
+ type: "suggestion",
26
+ messages: {
27
+ order: "JSDoc tags must be ordered as follows: @param, @default, @returns, @throws, @note, @deprecated, @see.",
28
+ },
29
+ },
30
+ create(context) {
31
+ const sourceCode = context.sourceCode;
32
+ return {
33
+ "Program:exit"() {
34
+ for (const comment of sourceCode.getAllComments()) {
35
+ if (comment.type !== "Block") {
36
+ continue;
37
+ }
38
+ const lines = getJSDocLines(comment, sourceCode);
39
+ if (lines === null || hasExampleOrFence(lines)) {
40
+ continue;
41
+ }
42
+ let previousOrder = null;
43
+ for (const line of lines) {
44
+ if (line.tagName === null) {
45
+ continue;
46
+ }
47
+ const order = TAG_ORDER[line.tagName] ?? UNKNOWN_TAG_ORDER;
48
+ if (previousOrder !== null && order < previousOrder) {
49
+ context.report({
50
+ loc: comment.loc,
51
+ messageId: "order",
52
+ });
53
+ break;
54
+ }
55
+ previousOrder = order;
56
+ }
57
+ }
58
+ },
59
+ };
60
+ },
61
+ });
62
+ export default jsdocTagOrder;
@@ -0,0 +1,26 @@
1
+ import type { ESTree, Comment, SourceCode } from "vite-plus/lint/plugins";
2
+ interface JSDocLine {
3
+ content: string;
4
+ prefix: string;
5
+ raw: string;
6
+ tagName: string | null;
7
+ }
8
+ declare function getTagName(text: string): string | null;
9
+ /**
10
+ * `@param` 行からパラメーター名を取得します。
11
+ */
12
+ declare function getParamName(content: string): string | null;
13
+ /**
14
+ * JSDoc コメントの各行を返します。
15
+ *
16
+ * JSDoc でない場合や、`*` の付かない行がある場合は null を返します。
17
+ */
18
+ declare function getJSDocLines(comment: Comment, sourceCode: SourceCode): JSDocLine[] | null;
19
+ declare function hasExampleOrFence(lines: readonly JSDocLine[]): boolean;
20
+ /**
21
+ * ノードに付いている JSDoc コメントを返します。
22
+ */
23
+ declare function getNodeJSDoc(node: ESTree.Node, sourceCode: SourceCode): Comment | null;
24
+ export type { JSDocLine };
25
+ export { getTagName, getNodeJSDoc, getParamName, getJSDocLines, hasExampleOrFence };
26
+ //# sourceMappingURL=jsdoc-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdoc-utils.d.ts","sourceRoot":"","sources":["../../../src/rules/jsdoc-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAI1E,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI/C;AAyBD;;GAEG;AACH,iBAAS,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAqBpD;AAED;;;;GAIG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,GAAG,SAAS,EAAE,GAAG,IAAI,CA+DnF;AAED,iBAAS,iBAAiB,CAAC,KAAK,EAAE,SAAS,SAAS,EAAE,GAAG,OAAO,CAE/D;AAcD;;GAEG;AACH,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,GAAG,IAAI,CAmB/E;AAED,YAAY,EAAE,SAAS,EAAE,CAAC;AAE1B,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAC"}
@@ -0,0 +1,132 @@
1
+ import { isFence } from "./comment-utils.js";
2
+ function getTagName(text) {
3
+ const match = /^@(?<tag>[A-Za-z][\w-]*)/u.exec(text.trimStart());
4
+ return match?.groups?.["tag"] ?? null;
5
+ }
6
+ function stripType(value) {
7
+ if (!value.startsWith("{")) {
8
+ return value;
9
+ }
10
+ let depth = 0;
11
+ for (let index = 0; index < value.length; index += 1) {
12
+ const character = value[index];
13
+ if (character === "{") {
14
+ depth += 1;
15
+ }
16
+ else if (character === "}") {
17
+ depth -= 1;
18
+ if (depth === 0) {
19
+ return value.slice(index + 1).trimStart();
20
+ }
21
+ }
22
+ }
23
+ return value;
24
+ }
25
+ /**
26
+ * `@param` 行からパラメーター名を取得します。
27
+ */
28
+ function getParamName(content) {
29
+ let value = content.trimStart();
30
+ if (getTagName(value) !== "param") {
31
+ return null;
32
+ }
33
+ value = stripType(value.slice("@param".length).trimStart());
34
+ const match = /^(?<name>\S+)/u.exec(value);
35
+ const name = match?.groups?.["name"] ?? null;
36
+ if (name === null) {
37
+ return null;
38
+ }
39
+ return name
40
+ .replace(/^\[/u, "")
41
+ .replace(/\]$/u, "")
42
+ .replace(/^\.\.\./u, "")
43
+ .replace(/=.*$/u, "");
44
+ }
45
+ /**
46
+ * JSDoc コメントの各行を返します。
47
+ *
48
+ * JSDoc でない場合や、`*` の付かない行がある場合は null を返します。
49
+ */
50
+ function getJSDocLines(comment, sourceCode) {
51
+ const raw = sourceCode.getText(comment);
52
+ if (!raw.startsWith("/**") || comment.type !== "Block") {
53
+ return null;
54
+ }
55
+ const rawLines = raw.split("\n");
56
+ if (rawLines.length === 1) {
57
+ const contentStart = 3;
58
+ const contentEnd = raw.lastIndexOf("*/");
59
+ const content = raw.slice(contentStart, contentEnd);
60
+ return [
61
+ {
62
+ raw,
63
+ prefix: raw.slice(0, contentStart),
64
+ content,
65
+ tagName: getTagName(content),
66
+ },
67
+ ];
68
+ }
69
+ const lines = [];
70
+ for (const [index, line] of rawLines.entries()) {
71
+ if (index === 0) {
72
+ const contentStart = 3;
73
+ const closeIndex = line.lastIndexOf("*/");
74
+ const contentEnd = closeIndex === -1 ? line.length : Math.max(contentStart, closeIndex);
75
+ const content = line.slice(contentStart, contentEnd);
76
+ lines.push({
77
+ raw: line,
78
+ prefix: line.slice(0, contentStart),
79
+ content,
80
+ tagName: getTagName(content),
81
+ });
82
+ continue;
83
+ }
84
+ const match = /^(?<prefix>\s*\*[ \t]?).*$/u.exec(line);
85
+ if (match === null) {
86
+ return null;
87
+ }
88
+ const prefix = match.groups?.["prefix"] ?? "";
89
+ const contentStart = prefix.length;
90
+ const closeIndex = line.lastIndexOf("*/");
91
+ const contentEnd = closeIndex === -1 ? line.length : Math.max(contentStart, closeIndex);
92
+ const content = line.slice(contentStart, contentEnd);
93
+ lines.push({
94
+ raw: line,
95
+ prefix,
96
+ content,
97
+ tagName: getTagName(content),
98
+ });
99
+ }
100
+ return lines;
101
+ }
102
+ function hasExampleOrFence(lines) {
103
+ return lines.some((line) => line.tagName === "example" || isFence(line.content));
104
+ }
105
+ function getNodeStart(node) {
106
+ if ("decorators" in node) {
107
+ const decorator = node.decorators?.[0];
108
+ if (decorator !== undefined) {
109
+ return decorator.range[0];
110
+ }
111
+ }
112
+ return node.range[0];
113
+ }
114
+ /**
115
+ * ノードに付いている JSDoc コメントを返します。
116
+ */
117
+ function getNodeJSDoc(node, sourceCode) {
118
+ const start = getNodeStart(node);
119
+ const comment = sourceCode.getAllComments().findLast((candidate) => candidate.range[1] <= start);
120
+ if (comment === null || comment === undefined || comment.type !== "Block") {
121
+ return null;
122
+ }
123
+ if (!sourceCode.getText(comment).startsWith("/**")) {
124
+ return null;
125
+ }
126
+ if (sourceCode.text.slice(comment.range[1], start).trim() !== "") {
127
+ return null;
128
+ }
129
+ const startLine = sourceCode.getLocFromIndex(start).line;
130
+ return comment.loc.end.line === startLine - 1 ? comment : null;
131
+ }
132
+ export { getTagName, getNodeJSDoc, getParamName, getJSDocLines, hasExampleOrFence };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * クラスメンバーを「static フィールド → static ブロック → インスタンスフィールド → constructor → static メソッド → インスタンスメソッド」の順に要求します。
3
+ */
4
+ declare const memberOrdering: import("vite-plus/lint/plugins").Rule;
5
+ export default memberOrdering;
6
+ //# sourceMappingURL=member-ordering.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"member-ordering.d.ts","sourceRoot":"","sources":["../../../src/rules/member-ordering.ts"],"names":[],"mappings":"AAiDA;;GAEG;AACH,QAAA,MAAM,cAAc,uCAsClB,CAAC;eAEY,cAAc"}
@@ -0,0 +1,66 @@
1
+ import { defineRule } from "vite-plus/lint/plugins";
2
+ const MEMBER_GROUP_ORDER = {
3
+ constructor: 3,
4
+ "static-block": 1,
5
+ "static-field": 0,
6
+ "static-method": 4,
7
+ "instance-field": 2,
8
+ "instance-method": 5,
9
+ };
10
+ function getMemberGroup(member) {
11
+ if (member.type === "StaticBlock") {
12
+ return "static-block";
13
+ }
14
+ if (member.type === "TSIndexSignature") {
15
+ return null;
16
+ }
17
+ if (member.type === "PropertyDefinition" ||
18
+ member.type === "TSAbstractPropertyDefinition" ||
19
+ member.type === "AccessorProperty" ||
20
+ member.type === "TSAbstractAccessorProperty") {
21
+ return member.static ? "static-field" : "instance-field";
22
+ }
23
+ if (member.type === "MethodDefinition" || member.type === "TSAbstractMethodDefinition") {
24
+ if (member.kind === "constructor") {
25
+ return "constructor";
26
+ }
27
+ return member.static ? "static-method" : "instance-method";
28
+ }
29
+ return null;
30
+ }
31
+ /**
32
+ * クラスメンバーを「static フィールド → static ブロック → インスタンスフィールド → constructor → static メソッド → インスタンスメソッド」の順に要求します。
33
+ */
34
+ const memberOrdering = defineRule({
35
+ meta: {
36
+ docs: {
37
+ description: "Require class members to be ordered as static fields, static blocks, instance fields, constructor, static methods, and instance methods.",
38
+ },
39
+ type: "suggestion",
40
+ messages: {
41
+ order: "Class members must be ordered as static fields, static blocks, instance fields, constructor, static methods, and instance methods.",
42
+ },
43
+ },
44
+ create(context) {
45
+ return {
46
+ ClassBody(node) {
47
+ let previousRank = null;
48
+ for (const member of node.body) {
49
+ const group = getMemberGroup(member);
50
+ if (group === null) {
51
+ continue;
52
+ }
53
+ const rank = MEMBER_GROUP_ORDER[group];
54
+ if (previousRank !== null && rank < previousRank) {
55
+ context.report({
56
+ node: member,
57
+ messageId: "order",
58
+ });
59
+ }
60
+ previousRank = rank;
61
+ }
62
+ },
63
+ };
64
+ },
65
+ });
66
+ export default memberOrdering;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * プロパティーが 2 つ以上あるオブジェクトリテラルを複数行にします。
3
+ *
4
+ * Oxfmt の `objectWrap` には「プロパティー数で改行を強制する」オプションがないため、改行を挿入する最小限の fix を提供します。
5
+ * `objectWrap: "preserve"` と組み合わせることで、後続の Oxfmt がプロパティーごとの改行とインデントを整えます。
6
+ */
7
+ declare const objectPropertiesNewline: import("vite-plus/lint/plugins").Rule;
8
+ export default objectPropertiesNewline;
9
+ //# sourceMappingURL=object-properties-newline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-properties-newline.d.ts","sourceRoot":"","sources":["../../../src/rules/object-properties-newline.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,QAAA,MAAM,uBAAuB,uCAyC3B,CAAC;eAEY,uBAAuB"}
@@ -0,0 +1,47 @@
1
+ import { defineRule } from "vite-plus/lint/plugins";
2
+ import { getSortPlan } from "./object-sort-utils.js";
3
+ /**
4
+ * プロパティーが 2 つ以上あるオブジェクトリテラルを複数行にします。
5
+ *
6
+ * Oxfmt の `objectWrap` には「プロパティー数で改行を強制する」オプションがないため、改行を挿入する最小限の fix を提供します。
7
+ * `objectWrap: "preserve"` と組み合わせることで、後続の Oxfmt がプロパティーごとの改行とインデントを整えます。
8
+ */
9
+ const objectPropertiesNewline = defineRule({
10
+ meta: {
11
+ docs: {
12
+ description: "Enforce multiline object literals when they have two or more properties.",
13
+ },
14
+ type: "layout",
15
+ fixable: "whitespace",
16
+ messages: {
17
+ multiline: "Objects with 2 or more properties must be multiline.",
18
+ },
19
+ },
20
+ create(context) {
21
+ return {
22
+ ObjectExpression(node) {
23
+ if (node.properties.length < 2) {
24
+ return;
25
+ }
26
+ // 並び替え可能なオブジェクトは sort-object-properties が複数行化も担当します。
27
+ if (getSortPlan(node, context.sourceCode) !== null) {
28
+ return;
29
+ }
30
+ // Oxfmt は `{` の直後に改行があるかどうかで複数行を維持するため、最初のプロパティーが `{` と同じ行にある場合だけを対象にします。
31
+ const firstProperty = node.properties[0];
32
+ if (firstProperty === undefined || firstProperty.loc.start.line !== node.loc.start.line) {
33
+ return;
34
+ }
35
+ context.report({
36
+ fix(fixer) {
37
+ // Oxfmt は `{` の直後の改行を複数行オブジェクトの目印にするため、ここでは改行を 1 つ挿入するだけで十分です。
38
+ return fixer.insertTextAfterRange([node.range[0], node.range[0] + 1], "\n");
39
+ },
40
+ node,
41
+ messageId: "multiline",
42
+ });
43
+ },
44
+ };
45
+ },
46
+ });
47
+ export default objectPropertiesNewline;
@@ -0,0 +1,32 @@
1
+ import type { ESTree, SourceCode } from "vite-plus/lint/plugins";
2
+ type SortableObject = ESTree.ObjectExpression | ESTree.ObjectPattern;
3
+ interface SortPlanOptions {
4
+ /**
5
+ * 末尾の RestElement を許可するかどうかです。
6
+ */
7
+ allowRest?: boolean;
8
+ /**
9
+ * 1 行のオブジェクトを複数行に整形するかどうかです。
10
+ */
11
+ forceMultiline?: boolean;
12
+ }
13
+ type SortPlan = {
14
+ needsFix: false;
15
+ replacement: null;
16
+ } | {
17
+ needsFix: true;
18
+ replacement: string;
19
+ };
20
+ declare function compareNames(left: string, right: string): number;
21
+ /**
22
+ * オブジェクトリテラル/オブジェクトパターンの並び替え計画を返します。
23
+ *
24
+ * - プロパティー名の長さが短い順、同じ長さなら名前順
25
+ * - 空行で区切られたグループ内だけで並び替え
26
+ * - プロパティー直上のコメントはプロパティーと一緒に移動
27
+ *
28
+ * 並び替えが安全でない場合は null を返します。
29
+ */
30
+ declare function getSortPlan(node: SortableObject, sourceCode: SourceCode, options?: SortPlanOptions): SortPlan | null;
31
+ export { getSortPlan, compareNames };
32
+ //# sourceMappingURL=object-sort-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object-sort-utils.d.ts","sourceRoot":"","sources":["../../../src/rules/object-sort-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAW,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE1E,KAAK,cAAc,GAAG,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,aAAa,CAAC;AAIrE,UAAU,eAAe;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAYD,KAAK,QAAQ,GACT;IACE,QAAQ,EAAE,KAAK,CAAC;IAChB,WAAW,EAAE,IAAI,CAAC;CACnB,GACD;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAuEN,iBAAS,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBzD;AAeD;;;;;;;;GAQG;AACH,iBAAS,WAAW,CAClB,IAAI,EAAE,cAAc,EACpB,UAAU,EAAE,UAAU,EACtB,OAAO,GAAE,eAAoB,GAC5B,QAAQ,GAAG,IAAI,CAwLjB;AAED,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC"}