pasika 0.3.3 → 0.3.4

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 (188) hide show
  1. package/README.md +13 -17
  2. package/dist/cli/index.d.ts +0 -1
  3. package/dist/cli/index.js +4999 -103
  4. package/dist/eslint/pasika/index.d.ts +165 -53
  5. package/dist/eslint/pasika/index.js +4424 -89
  6. package/package.json +3 -3
  7. package/dist/cli/output.d.ts +0 -3
  8. package/dist/cli/output.js +0 -11
  9. package/dist/enforcement/coverage.d.ts +0 -55
  10. package/dist/enforcement/coverage.js +0 -239
  11. package/dist/enforcement/doctor.d.ts +0 -16
  12. package/dist/enforcement/doctor.js +0 -249
  13. package/dist/enforcement/normalize.d.ts +0 -11
  14. package/dist/enforcement/normalize.js +0 -21
  15. package/dist/enforcement/parse-docs.d.ts +0 -58
  16. package/dist/enforcement/parse-docs.js +0 -98
  17. package/dist/enforcement/types.d.ts +0 -54
  18. package/dist/enforcement/types.js +0 -50
  19. package/dist/eslint/pasika/ast-types.d.ts +0 -122
  20. package/dist/eslint/pasika/ast-types.js +0 -1
  21. package/dist/eslint/pasika/project/ccf.d.ts +0 -48
  22. package/dist/eslint/pasika/project/ccf.js +0 -119
  23. package/dist/eslint/pasika/project/index.d.ts +0 -21
  24. package/dist/eslint/pasika/project/index.js +0 -139
  25. package/dist/eslint/pasika/project/parse-module.d.ts +0 -27
  26. package/dist/eslint/pasika/project/parse-module.js +0 -128
  27. package/dist/eslint/pasika/rules/application-structure.d.ts +0 -2
  28. package/dist/eslint/pasika/rules/application-structure.js +0 -152
  29. package/dist/eslint/pasika/rules/component-conventions.d.ts +0 -16
  30. package/dist/eslint/pasika/rules/component-conventions.js +0 -145
  31. package/dist/eslint/pasika/rules/component-nesting.d.ts +0 -12
  32. package/dist/eslint/pasika/rules/component-nesting.js +0 -69
  33. package/dist/eslint/pasika/rules/component-placement.d.ts +0 -11
  34. package/dist/eslint/pasika/rules/component-placement.js +0 -75
  35. package/dist/eslint/pasika/rules/config-extraction.d.ts +0 -14
  36. package/dist/eslint/pasika/rules/config-extraction.js +0 -74
  37. package/dist/eslint/pasika/rules/cross-feature-import.d.ts +0 -2
  38. package/dist/eslint/pasika/rules/cross-feature-import.js +0 -75
  39. package/dist/eslint/pasika/rules/css/apply-usage.d.ts +0 -10
  40. package/dist/eslint/pasika/rules/css/apply-usage.js +0 -45
  41. package/dist/eslint/pasika/rules/css/base-layer-pair.d.ts +0 -10
  42. package/dist/eslint/pasika/rules/css/base-layer-pair.js +0 -49
  43. package/dist/eslint/pasika/rules/css/css-variable-naming.d.ts +0 -10
  44. package/dist/eslint/pasika/rules/css/css-variable-naming.js +0 -39
  45. package/dist/eslint/pasika/rules/css/custom-utility-apply.d.ts +0 -11
  46. package/dist/eslint/pasika/rules/css/custom-utility-apply.js +0 -52
  47. package/dist/eslint/pasika/rules/css/global-css-location.d.ts +0 -10
  48. package/dist/eslint/pasika/rules/css/global-css-location.js +0 -42
  49. package/dist/eslint/pasika/rules/css/helpers.d.ts +0 -29
  50. package/dist/eslint/pasika/rules/css/helpers.js +0 -93
  51. package/dist/eslint/pasika/rules/css/index.d.ts +0 -13
  52. package/dist/eslint/pasika/rules/css/index.js +0 -25
  53. package/dist/eslint/pasika/rules/css/root-variables.d.ts +0 -11
  54. package/dist/eslint/pasika/rules/css/root-variables.js +0 -53
  55. package/dist/eslint/pasika/rules/css/rule-tester.d.ts +0 -11
  56. package/dist/eslint/pasika/rules/css/rule-tester.js +0 -22
  57. package/dist/eslint/pasika/rules/css/stylesheet-ordering.d.ts +0 -11
  58. package/dist/eslint/pasika/rules/css/stylesheet-ordering.js +0 -76
  59. package/dist/eslint/pasika/rules/css/surface-utility.d.ts +0 -10
  60. package/dist/eslint/pasika/rules/css/surface-utility.js +0 -41
  61. package/dist/eslint/pasika/rules/css/theme-reset.d.ts +0 -9
  62. package/dist/eslint/pasika/rules/css/theme-reset.js +0 -36
  63. package/dist/eslint/pasika/rules/css/theme-variable-namespace.d.ts +0 -11
  64. package/dist/eslint/pasika/rules/css/theme-variable-namespace.js +0 -53
  65. package/dist/eslint/pasika/rules/cva-appearance-props.d.ts +0 -10
  66. package/dist/eslint/pasika/rules/cva-appearance-props.js +0 -77
  67. package/dist/eslint/pasika/rules/cva-boolean-variants.d.ts +0 -11
  68. package/dist/eslint/pasika/rules/cva-boolean-variants.js +0 -97
  69. package/dist/eslint/pasika/rules/data-testid-case.d.ts +0 -2
  70. package/dist/eslint/pasika/rules/data-testid-case.js +0 -76
  71. package/dist/eslint/pasika/rules/enforce-barrel-exports.d.ts +0 -9
  72. package/dist/eslint/pasika/rules/enforce-barrel-exports.js +0 -78
  73. package/dist/eslint/pasika/rules/enforce-cn-merge.d.ts +0 -21
  74. package/dist/eslint/pasika/rules/enforce-cn-merge.js +0 -86
  75. package/dist/eslint/pasika/rules/enforce-cva-variant-props.d.ts +0 -9
  76. package/dist/eslint/pasika/rules/enforce-cva-variant-props.js +0 -86
  77. package/dist/eslint/pasika/rules/filename-case.d.ts +0 -2
  78. package/dist/eslint/pasika/rules/filename-case.js +0 -123
  79. package/dist/eslint/pasika/rules/hook-complexity.d.ts +0 -12
  80. package/dist/eslint/pasika/rules/hook-complexity.js +0 -114
  81. package/dist/eslint/pasika/rules/hook-extraction.d.ts +0 -11
  82. package/dist/eslint/pasika/rules/hook-extraction.js +0 -55
  83. package/dist/eslint/pasika/rules/import-boundaries.d.ts +0 -2
  84. package/dist/eslint/pasika/rules/import-boundaries.js +0 -167
  85. package/dist/eslint/pasika/rules/import-through-index.d.ts +0 -2
  86. package/dist/eslint/pasika/rules/import-through-index.js +0 -52
  87. package/dist/eslint/pasika/rules/interactive-component.d.ts +0 -10
  88. package/dist/eslint/pasika/rules/interactive-component.js +0 -76
  89. package/dist/eslint/pasika/rules/json/index.d.ts +0 -5
  90. package/dist/eslint/pasika/rules/json/index.js +0 -9
  91. package/dist/eslint/pasika/rules/json/no-cache-flag.d.ts +0 -10
  92. package/dist/eslint/pasika/rules/json/no-cache-flag.js +0 -45
  93. package/dist/eslint/pasika/rules/json/no-vulyk-dependency.d.ts +0 -10
  94. package/dist/eslint/pasika/rules/json/no-vulyk-dependency.js +0 -41
  95. package/dist/eslint/pasika/rules/json/rule-tester.d.ts +0 -11
  96. package/dist/eslint/pasika/rules/json/rule-tester.js +0 -21
  97. package/dist/eslint/pasika/rules/jsx-hygiene.d.ts +0 -9
  98. package/dist/eslint/pasika/rules/jsx-hygiene.js +0 -108
  99. package/dist/eslint/pasika/rules/locale-dotted-path.d.ts +0 -10
  100. package/dist/eslint/pasika/rules/locale-dotted-path.js +0 -65
  101. package/dist/eslint/pasika/rules/locale-placement.d.ts +0 -13
  102. package/dist/eslint/pasika/rules/locale-placement.js +0 -163
  103. package/dist/eslint/pasika/rules/locales-location.d.ts +0 -11
  104. package/dist/eslint/pasika/rules/locales-location.js +0 -56
  105. package/dist/eslint/pasika/rules/md/doc-kind-suffix.d.ts +0 -5
  106. package/dist/eslint/pasika/rules/md/doc-kind-suffix.js +0 -29
  107. package/dist/eslint/pasika/rules/md/example-heading-description.d.ts +0 -5
  108. package/dist/eslint/pasika/rules/md/example-heading-description.js +0 -30
  109. package/dist/eslint/pasika/rules/md/glossary-term-linking.d.ts +0 -2
  110. package/dist/eslint/pasika/rules/md/glossary-term-linking.js +0 -99
  111. package/dist/eslint/pasika/rules/md/guide-folder-entry-point.d.ts +0 -2
  112. package/dist/eslint/pasika/rules/md/guide-folder-entry-point.js +0 -46
  113. package/dist/eslint/pasika/rules/md/guide-link-anchors.d.ts +0 -5
  114. package/dist/eslint/pasika/rules/md/guide-link-anchors.js +0 -50
  115. package/dist/eslint/pasika/rules/md/guide-overview-no-links.d.ts +0 -5
  116. package/dist/eslint/pasika/rules/md/guide-overview-no-links.js +0 -51
  117. package/dist/eslint/pasika/rules/md/guide-states-no-requirement.d.ts +0 -5
  118. package/dist/eslint/pasika/rules/md/guide-states-no-requirement.js +0 -26
  119. package/dist/eslint/pasika/rules/md/guide-step-single-link.d.ts +0 -5
  120. package/dist/eslint/pasika/rules/md/guide-step-single-link.js +0 -48
  121. package/dist/eslint/pasika/rules/md/guide-step-single-sentence.d.ts +0 -5
  122. package/dist/eslint/pasika/rules/md/guide-step-single-sentence.js +0 -42
  123. package/dist/eslint/pasika/rules/md/helpers.d.ts +0 -25
  124. package/dist/eslint/pasika/rules/md/helpers.js +0 -37
  125. package/dist/eslint/pasika/rules/md/index.d.ts +0 -27
  126. package/dist/eslint/pasika/rules/md/index.js +0 -53
  127. package/dist/eslint/pasika/rules/md/no-cross-document-link.d.ts +0 -5
  128. package/dist/eslint/pasika/rules/md/no-cross-document-link.js +0 -36
  129. package/dist/eslint/pasika/rules/md/no-nested-how-to.d.ts +0 -5
  130. package/dist/eslint/pasika/rules/md/no-nested-how-to.js +0 -39
  131. package/dist/eslint/pasika/rules/md/no-template-prompt.d.ts +0 -5
  132. package/dist/eslint/pasika/rules/md/no-template-prompt.js +0 -22
  133. package/dist/eslint/pasika/rules/md/overview-length.d.ts +0 -5
  134. package/dist/eslint/pasika/rules/md/overview-length.js +0 -47
  135. package/dist/eslint/pasika/rules/md/overview-present.d.ts +0 -5
  136. package/dist/eslint/pasika/rules/md/overview-present.js +0 -41
  137. package/dist/eslint/pasika/rules/md/policy-no-examples.d.ts +0 -5
  138. package/dist/eslint/pasika/rules/md/policy-no-examples.js +0 -28
  139. package/dist/eslint/pasika/rules/md/policy-single-document.d.ts +0 -5
  140. package/dist/eslint/pasika/rules/md/policy-single-document.js +0 -34
  141. package/dist/eslint/pasika/rules/md/policy-subject-headings.d.ts +0 -5
  142. package/dist/eslint/pasika/rules/md/policy-subject-headings.js +0 -58
  143. package/dist/eslint/pasika/rules/md/project-index.d.ts +0 -17
  144. package/dist/eslint/pasika/rules/md/project-index.js +0 -67
  145. package/dist/eslint/pasika/rules/md/reference-block-headings.d.ts +0 -6
  146. package/dist/eslint/pasika/rules/md/reference-block-headings.js +0 -31
  147. package/dist/eslint/pasika/rules/md/reference-no-rfc-vocabulary.d.ts +0 -6
  148. package/dist/eslint/pasika/rules/md/reference-no-rfc-vocabulary.js +0 -26
  149. package/dist/eslint/pasika/rules/md/requirement-present.d.ts +0 -5
  150. package/dist/eslint/pasika/rules/md/requirement-present.js +0 -41
  151. package/dist/eslint/pasika/rules/md/rfc-only-in-bullets.d.ts +0 -5
  152. package/dist/eslint/pasika/rules/md/rfc-only-in-bullets.js +0 -46
  153. package/dist/eslint/pasika/rules/md/rule-paired-examples.d.ts +0 -5
  154. package/dist/eslint/pasika/rules/md/rule-paired-examples.js +0 -36
  155. package/dist/eslint/pasika/rules/md/rule-tester.d.ts +0 -11
  156. package/dist/eslint/pasika/rules/md/rule-tester.js +0 -21
  157. package/dist/eslint/pasika/rules/md/support-document-placement.d.ts +0 -2
  158. package/dist/eslint/pasika/rules/md/support-document-placement.js +0 -36
  159. package/dist/eslint/pasika/rules/md/title-matches-file-name.d.ts +0 -2
  160. package/dist/eslint/pasika/rules/md/title-matches-file-name.js +0 -46
  161. package/dist/eslint/pasika/rules/named-exports.d.ts +0 -2
  162. package/dist/eslint/pasika/rules/named-exports.js +0 -49
  163. package/dist/eslint/pasika/rules/no-arbitrary-tailwind.d.ts +0 -9
  164. package/dist/eslint/pasika/rules/no-arbitrary-tailwind.js +0 -97
  165. package/dist/eslint/pasika/rules/no-eslint-disable.d.ts +0 -10
  166. package/dist/eslint/pasika/rules/no-eslint-disable.js +0 -33
  167. package/dist/eslint/pasika/rules/no-mixed-concerns.d.ts +0 -9
  168. package/dist/eslint/pasika/rules/no-mixed-concerns.js +0 -71
  169. package/dist/eslint/pasika/rules/no-util-barrel.d.ts +0 -2
  170. package/dist/eslint/pasika/rules/no-util-barrel.js +0 -48
  171. package/dist/eslint/pasika/rules/pure-function-extract.d.ts +0 -9
  172. package/dist/eslint/pasika/rules/pure-function-extract.js +0 -92
  173. package/dist/eslint/pasika/rules/shared-style-dedup.d.ts +0 -13
  174. package/dist/eslint/pasika/rules/shared-style-dedup.js +0 -91
  175. package/dist/eslint/pasika/rules/stay-flat.d.ts +0 -12
  176. package/dist/eslint/pasika/rules/stay-flat.js +0 -81
  177. package/dist/eslint/pasika/rules/support-file-placement.d.ts +0 -15
  178. package/dist/eslint/pasika/rules/support-file-placement.js +0 -70
  179. package/dist/eslint/pasika/rules/support-folder-shape.d.ts +0 -2
  180. package/dist/eslint/pasika/rules/support-folder-shape.js +0 -59
  181. package/dist/eslint/pasika/rules/type-extraction.d.ts +0 -13
  182. package/dist/eslint/pasika/rules/type-extraction.js +0 -85
  183. package/dist/eslint/pasika/rules/ui-state.d.ts +0 -9
  184. package/dist/eslint/pasika/rules/ui-state.js +0 -99
  185. package/dist/eslint/pasika/rules/util-file-name.d.ts +0 -2
  186. package/dist/eslint/pasika/rules/util-file-name.js +0 -48
  187. package/dist/eslint/pasika/rules/value-extraction.d.ts +0 -13
  188. package/dist/eslint/pasika/rules/value-extraction.js +0 -48
@@ -1,108 +0,0 @@
1
- /**
2
- * ESLint rule: pasika/jsx-hygiene
3
- *
4
- * Keeps calculations and complex conditions out of JSX children and attributes.
5
- *
6
- * @see docs/code-organization-guide/rules/jsx-hygiene-rule.md
7
- */
8
- import ts from "typescript";
9
- const ARITHMETIC_OPERATORS = new Set(["+", "-", "*", "/", "%"]);
10
- function isCallExpression(node) {
11
- return node.type === "CallExpression";
12
- }
13
- function isMemberExpression(node) {
14
- return ["MemberExpression", "OptionalMemberExpression"].includes(node.type);
15
- }
16
- function logicalOperatorCount(node) {
17
- if (node.type !== "LogicalExpression")
18
- return 0;
19
- return 1 + logicalOperatorCount(node.left) + logicalOperatorCount(node.right);
20
- }
21
- /**
22
- * Whether the parsed text of a node's subtree contains a conditional expression
23
- * anywhere. Re-parses just the node's source slice with the TypeScript compiler
24
- * so the walk stays fully typed, including inside JSX children.
25
- */
26
- function containsConditionalIn(node, sourceText) {
27
- const start = node.range?.[0] ?? 0;
28
- const end = node.range?.[1] ?? sourceText.length;
29
- const sourceFile = ts.createSourceFile("fragment.tsx", sourceText.slice(start, end), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
30
- let found = false;
31
- const visit = (child) => {
32
- if (found)
33
- return;
34
- if (ts.isConditionalExpression(child)) {
35
- found = true;
36
- return;
37
- }
38
- ts.forEachChild(child, visit);
39
- };
40
- visit(sourceFile);
41
- return found;
42
- }
43
- function hasNestedTernary(node, sourceText) {
44
- if (node.type !== "ConditionalExpression")
45
- return false;
46
- return containsConditionalIn(node.consequent, sourceText) || containsConditionalIn(node.alternate, sourceText);
47
- }
48
- function hasChainedCall(node) {
49
- if (!isCallExpression(node) || !isMemberExpression(node.callee))
50
- return false;
51
- return isCallExpression(node.callee.object) || isMemberExpression(node.callee.object);
52
- }
53
- function hasExternalCall(node) {
54
- if (!isCallExpression(node))
55
- return false;
56
- const callee = node.callee;
57
- if (callee.type === "Identifier" && callee.name === "cn")
58
- return false;
59
- if (isMemberExpression(callee))
60
- return false;
61
- return callee.type === "Identifier";
62
- }
63
- function findViolation(node, sourceText) {
64
- if (node.type === "BinaryExpression" && ARITHMETIC_OPERATORS.has(node.operator)) {
65
- return "arithmetic";
66
- }
67
- if (hasChainedCall(node))
68
- return "chained built-in method calls";
69
- if (hasExternalCall(node))
70
- return "calls to functions declared outside the component";
71
- if (hasNestedTernary(node, sourceText))
72
- return "nested ternaries";
73
- if (logicalOperatorCount(node) >= 2)
74
- return "conditions containing two or more logical operators";
75
- return undefined;
76
- }
77
- export const jsxHygieneRule = {
78
- meta: {
79
- schema: [],
80
- type: "problem",
81
- docs: {
82
- description: "Require complex JSX expressions to be extracted before return.",
83
- },
84
- },
85
- create(context) {
86
- if (!context.filename.endsWith(".tsx") && !context.filename.endsWith(".jsx"))
87
- return {};
88
- const sourceText = context.sourceCode.text;
89
- function checkExpression(node) {
90
- const violation = findViolation(node, sourceText);
91
- if (!violation)
92
- return;
93
- context.report({
94
- node,
95
- message: `Extract ${violation} from JSX before return. ` +
96
- "See docs/code-organization-guide/rules/jsx-hygiene-rule.md",
97
- });
98
- }
99
- return {
100
- JSXExpressionContainer(node) {
101
- const expression = node.expression;
102
- if (!expression || expression.type === "JSXEmptyExpression")
103
- return;
104
- checkExpression(expression);
105
- },
106
- };
107
- },
108
- };
@@ -1,10 +0,0 @@
1
- /**
2
- * ESLint rule: pasika/locale-dotted-path
3
- *
4
- * A namespaced locale MUST be read through its full dotted path
5
- * (locales.stream.watchLiveStream) rather than destructured.
6
- *
7
- * @see docs/code-organization-guide/rules/locales-rule.md
8
- */
9
- import type { Rule } from "eslint";
10
- export declare const localeDottedPathRule: Rule.RuleModule;
@@ -1,65 +0,0 @@
1
- /**
2
- * ESLint rule: pasika/locale-dotted-path
3
- *
4
- * A namespaced locale MUST be read through its full dotted path
5
- * (locales.stream.watchLiveStream) rather than destructured.
6
- *
7
- * @see docs/code-organization-guide/rules/locales-rule.md
8
- */
9
- import path from "node:path";
10
- function isInLocalesDir(filename) {
11
- const segments = path.resolve(filename).split(path.sep);
12
- const srcIdx = segments.lastIndexOf("src");
13
- return srcIdx !== -1 && segments[srcIdx + 1] === "locales";
14
- }
15
- function isLocalesAccess(node) {
16
- if (node.type === "Identifier" && node.name === "locales") {
17
- return true;
18
- }
19
- if (node.type === "MemberExpression" &&
20
- node.object.type === "Identifier" &&
21
- node.object.name === "locales" &&
22
- node.property.type === "Identifier") {
23
- return true;
24
- }
25
- return false;
26
- }
27
- export const localeDottedPathRule = {
28
- meta: {
29
- schema: [],
30
- type: "problem",
31
- docs: {
32
- description: "Require reading namespaced locales through their full dotted path.",
33
- },
34
- },
35
- create(context) {
36
- if (isInLocalesDir(context.filename))
37
- return {};
38
- return {
39
- VariableDeclarator(node) {
40
- if (node.id.type !== "ObjectPattern")
41
- return;
42
- const init = node.init;
43
- if (!init || !isLocalesAccess(init))
44
- return;
45
- for (const prop of node.id.properties) {
46
- if (prop.type !== "Property")
47
- continue;
48
- let valueName;
49
- if (prop.value.type === "Identifier") {
50
- valueName = prop.value.name;
51
- }
52
- else if (prop.key.type === "Identifier") {
53
- valueName = prop.key.name;
54
- }
55
- if (valueName) {
56
- context.report({
57
- node,
58
- message: `Destructuring locales.${valueName} loses the namespace; read through the full dotted path instead.`,
59
- });
60
- }
61
- }
62
- },
63
- };
64
- },
65
- };
@@ -1,13 +0,0 @@
1
- /**
2
- * ESLint rule: pasika/locale-placement
3
- *
4
- * Locales read by files in more than one feature folder or by src/shared/,
5
- * src/compositions/, src/app/, or root support folders MUST live at the top
6
- * level of locales. Locales read only by files in one feature folder MUST live
7
- * in an object with the camelCase form of its feature folder name. The rule
8
- * reads which keys the tree uses, because a single file cannot see them.
9
- *
10
- * @see docs/code-organization-guide/rules/locales-rule.md
11
- */
12
- import type { Rule } from "eslint";
13
- export declare const localePlacementRule: Rule.RuleModule;
@@ -1,163 +0,0 @@
1
- /**
2
- * ESLint rule: pasika/locale-placement
3
- *
4
- * Locales read by files in more than one feature folder or by src/shared/,
5
- * src/compositions/, src/app/, or root support folders MUST live at the top
6
- * level of locales. Locales read only by files in one feature folder MUST live
7
- * in an object with the camelCase form of its feature folder name. The rule
8
- * reads which keys the tree uses, because a single file cannot see them.
9
- *
10
- * @see docs/code-organization-guide/rules/locales-rule.md
11
- */
12
- import path from "node:path";
13
- import { readFileSync } from "node:fs";
14
- import ts from "typescript";
15
- import { getProjectIndex, resolveSpecifier } from "../project/index.js";
16
- import { describeConsumers, segmentsOf, SUPPORT_FOLDERS } from "../project/ccf.js";
17
- /** The first segment of a `locales.<key>` read. */
18
- const LOCALE_ACCESS = /\blocales\.(?<key>[A-Za-z_$][\w$]*)/g;
19
- const camelCase = (name) => name.replace(/-[a-z]/g, (match) => match.slice(1).toUpperCase());
20
- const FORCED_TOP_LEVEL = new Set(["app", "shared", "compositions", "config"]);
21
- /** A file whose own folder decides the locale scope: app/shared/compositions/config or a root support folder. */
22
- function forcesTopLevel(segments) {
23
- return FORCED_TOP_LEVEL.has(segments[0] ?? "") || SUPPORT_FOLDERS.has(segments[0] ?? "");
24
- }
25
- /**
26
- * Where each top-level key of the exported `locales` object lives: directly on
27
- * the object ("top") or as a namespaced object ("nested").
28
- */
29
- function localePlacement(text) {
30
- const sourceFile = ts.createSourceFile("locales.ts", text, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
31
- for (const statement of sourceFile.statements) {
32
- if (!ts.isVariableStatement(statement))
33
- continue;
34
- const isExported = (ts.getModifiers(statement) ?? []).some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword);
35
- if (!isExported)
36
- continue;
37
- for (const declaration of statement.declarationList.declarations) {
38
- if (!ts.isIdentifier(declaration.name) || declaration.name.text !== "locales")
39
- continue;
40
- if (!declaration.initializer || !ts.isObjectLiteralExpression(declaration.initializer))
41
- continue;
42
- const placement = new Map();
43
- for (const property of declaration.initializer.properties) {
44
- if (!ts.isPropertyAssignment(property))
45
- continue;
46
- let name;
47
- if (ts.isIdentifier(property.name))
48
- name = property.name.text;
49
- else if (ts.isStringLiteral(property.name))
50
- name = property.name.text;
51
- if (name === undefined)
52
- continue;
53
- const line = sourceFile.getLineAndCharacterOfPosition(property.getStart(sourceFile)).line + 1;
54
- placement.set(name, {
55
- kind: ts.isObjectLiteralExpression(property.initializer) ? "nested" : "top",
56
- line,
57
- });
58
- }
59
- return placement;
60
- }
61
- }
62
- return undefined;
63
- }
64
- export const localePlacementRule = {
65
- meta: {
66
- schema: [],
67
- type: "problem",
68
- docs: {
69
- description: "Require shared locales at the top level and single-feature locales in a namespaced object.",
70
- },
71
- },
72
- create(context) {
73
- const sourceRoot = path.resolve("src");
74
- const file = path.resolve(context.filename);
75
- const segments = segmentsOf(file, sourceRoot);
76
- if (segments.length === 0)
77
- return {};
78
- const index = getProjectIndex(sourceRoot);
79
- if (!index)
80
- return {};
81
- // The named locales object lives in src/locales/index.ts; the rule reports
82
- // on that file, because the fix is in the definition.
83
- const localesFile = [...index.modules.keys()].find((candidate) => {
84
- const candidateSegments = segmentsOf(candidate, sourceRoot);
85
- return candidateSegments.length === 2 && candidateSegments[0] === "locales" && candidateSegments[1]?.startsWith("index.");
86
- });
87
- if (!localesFile || file !== localesFile)
88
- return {};
89
- const placement = localePlacement(readFileSync(localesFile, "utf8"));
90
- if (!placement)
91
- return {};
92
- const keyReaders = new Map();
93
- const keyFeatures = new Map();
94
- const keyForcedTopLevel = new Set();
95
- for (const [candidateFile, module] of index.modules) {
96
- if (candidateFile === localesFile)
97
- continue;
98
- const importsLocales = module.imports.some((moduleImport) => resolveSpecifier(candidateFile, moduleImport.specifier, sourceRoot) === localesFile);
99
- if (!importsLocales)
100
- continue;
101
- const candidateSegments = segmentsOf(candidateFile, sourceRoot);
102
- for (const match of readFileSync(candidateFile, "utf8").matchAll(LOCALE_ACCESS)) {
103
- const key = match.groups?.key;
104
- if (key === undefined)
105
- continue;
106
- const readers = keyReaders.get(key) ?? new Set();
107
- readers.add(candidateFile);
108
- keyReaders.set(key, readers);
109
- if (candidateSegments[0] === "features" && candidateSegments.length >= 2) {
110
- const features = keyFeatures.get(key) ?? new Set();
111
- features.add(candidateSegments[1] ?? "");
112
- keyFeatures.set(key, features);
113
- }
114
- else if (forcesTopLevel(candidateSegments)) {
115
- keyForcedTopLevel.add(key);
116
- }
117
- }
118
- }
119
- const findings = [];
120
- for (const [key, readers] of keyReaders) {
121
- const features = keyFeatures.get(key) ?? new Set();
122
- const shared = features.size > 1 || keyForcedTopLevel.has(key);
123
- const current = placement.get(key);
124
- if (shared) {
125
- if (current?.kind === "nested") {
126
- findings.push({
127
- line: current.line,
128
- message: `Locale "${key}" is read by ${describeConsumers([...readers], sourceRoot)} and must live ` +
129
- "at the top level of locales. See docs/code-organization-guide/rules/locales-rule.md",
130
- });
131
- }
132
- continue;
133
- }
134
- if (features.size !== 1)
135
- continue;
136
- const featureName = [...features][0] ?? "";
137
- const expected = camelCase(featureName);
138
- if (current?.kind === "top") {
139
- findings.push({
140
- line: current.line,
141
- message: `Locale "${key}" is read only by the ${featureName} feature; it must live in an object ` +
142
- `named "${expected}". See docs/code-organization-guide/rules/locales-rule.md`,
143
- });
144
- }
145
- else if (current?.kind === "nested" && key !== expected) {
146
- findings.push({
147
- line: current.line,
148
- message: `Locale "${key}" is read only by the ${featureName} feature; it must live in an object ` +
149
- `named "${expected}", not "${key}". See docs/code-organization-guide/rules/locales-rule.md`,
150
- });
151
- }
152
- }
153
- if (findings.length === 0)
154
- return {};
155
- return {
156
- Program(node) {
157
- for (const finding of findings) {
158
- context.report({ node, loc: { line: finding.line, column: 0 }, message: finding.message });
159
- }
160
- },
161
- };
162
- },
163
- };
@@ -1,11 +0,0 @@
1
- /**
2
- * ESLint rule: pasika/locales-location
3
- *
4
- * All locales MUST live in the named locales object exported from
5
- * src/locales/index.ts. User-facing strings defined outside the locales
6
- * directory are reported.
7
- *
8
- * @see docs/code-organization-guide/rules/locales-rule.md
9
- */
10
- import type { Rule } from "eslint";
11
- export declare const localesLocationRule: Rule.RuleModule;
@@ -1,56 +0,0 @@
1
- /**
2
- * ESLint rule: pasika/locales-location
3
- *
4
- * All locales MUST live in the named locales object exported from
5
- * src/locales/index.ts. User-facing strings defined outside the locales
6
- * directory are reported.
7
- *
8
- * @see docs/code-organization-guide/rules/locales-rule.md
9
- */
10
- import path from "node:path";
11
- function isLocalesFile(filename) {
12
- const segments = path.resolve(filename).split(path.sep);
13
- const srcIdx = segments.lastIndexOf("src");
14
- return srcIdx !== -1 && segments[srcIdx + 1] === "locales";
15
- }
16
- const LOCALE_NAME_RE = /^[a-z][a-zA-Z0-9]*$/;
17
- function looksLikeLocaleKey(name) {
18
- return LOCALE_NAME_RE.test(name);
19
- }
20
- export const localesLocationRule = {
21
- meta: {
22
- schema: [],
23
- type: "problem",
24
- docs: {
25
- description: "Require all locales to live in the named locales object.",
26
- },
27
- },
28
- create(context) {
29
- if (isLocalesFile(context.filename))
30
- return {};
31
- const filename = context.filename;
32
- const segments = path.resolve(filename).split(path.sep);
33
- const srcIdx = segments.lastIndexOf("src");
34
- if (srcIdx === -1)
35
- return {};
36
- const folder = segments[srcIdx + 1];
37
- if (folder === "app" || folder === "config")
38
- return {};
39
- return {
40
- VariableDeclarator(node) {
41
- if (node.id.type === "Identifier" &&
42
- node.init?.type === "ObjectExpression" &&
43
- node.init.properties.length > 0 &&
44
- looksLikeLocaleKey(node.id.name)) {
45
- const hasStringValues = node.init.properties.some((p) => p.type === "Property" && p.value.type === "Literal");
46
- if (hasStringValues) {
47
- context.report({
48
- node,
49
- message: "User-facing strings must live in src/locales/, not inline in component files.",
50
- });
51
- }
52
- }
53
- },
54
- };
55
- },
56
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * @fileoverview Documentation files must have a kind suffix in their filename.
3
- */
4
- import type { MarkdownRuleDefinition } from "@eslint/markdown";
5
- export declare const docKindSuffixRule: MarkdownRuleDefinition;
@@ -1,29 +0,0 @@
1
- import { getFilename } from "./helpers.js";
2
- export const docKindSuffixRule = {
3
- meta: {
4
- type: "problem",
5
- docs: {
6
- description: "Documentation files must have a -guide, -rule, -reference, or -policy suffix.",
7
- recommended: true,
8
- },
9
- },
10
- create(context) {
11
- return {
12
- root(node) {
13
- const filename = getFilename(context);
14
- if (!filename.endsWith(".md"))
15
- return;
16
- if (filename.endsWith("-guide.md") ||
17
- filename.endsWith("-rule.md") ||
18
- filename.endsWith("-reference.md") ||
19
- filename.endsWith("-policy.md")) {
20
- return;
21
- }
22
- context.report({
23
- node,
24
- message: "file name carries no -guide, -rule, -reference, or -policy suffix",
25
- });
26
- },
27
- };
28
- },
29
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * @fileoverview Example headings must have an em-dash description.
3
- */
4
- import type { MarkdownRuleDefinition } from "@eslint/markdown";
5
- export declare const exampleHeadingDescriptionRule: MarkdownRuleDefinition;
@@ -1,30 +0,0 @@
1
- import { getFilename, getTextContent } from "./helpers.js";
2
- export const exampleHeadingDescriptionRule = {
3
- meta: {
4
- type: "problem",
5
- docs: {
6
- description: "Example headings must have an em-dash description.",
7
- recommended: true,
8
- },
9
- },
10
- create(context) {
11
- return {
12
- heading(node) {
13
- const filename = getFilename(context);
14
- if (!filename.endsWith("-rule.md"))
15
- return;
16
- if (node.depth !== 2)
17
- return;
18
- const text = getTextContent(node).trim();
19
- if (!/^(?:Incorrect|Correct)\b/.test(text))
20
- return;
21
- if (!/^(?:Incorrect|Correct) — .+/.test(text)) {
22
- context.report({
23
- node,
24
- message: `example heading has no em-dash description: ${text}`,
25
- });
26
- }
27
- },
28
- };
29
- },
30
- };
@@ -1,2 +0,0 @@
1
- import type { MarkdownRuleDefinition } from "@eslint/markdown";
2
- export declare const glossaryTermLinkingRule: MarkdownRuleDefinition;
@@ -1,99 +0,0 @@
1
- /**
2
- * @fileoverview A Guide whose steps use terms that a glossary Reference defines
3
- * must link that Reference from its first step.
4
- */
5
- import { readFileSync } from "node:fs";
6
- import path from "node:path";
7
- import { getFilename, getTextContent } from "./helpers.js";
8
- import { findDocsRoot, getProjectDocs } from "./project-index.js";
9
- /** Extract glossary terms from a reference document. */
10
- function extractGlossaryTerms(filePath) {
11
- const content = readFileSync(filePath, "utf8");
12
- const terms = [];
13
- // Look for definition-style patterns: "## Term" headings
14
- const headingPattern = /^## (?<term>.+)$/gm;
15
- let match;
16
- while ((match = headingPattern.exec(content)) !== null) {
17
- const term = match.groups?.term?.trim();
18
- if (term)
19
- terms.push(term);
20
- }
21
- return terms;
22
- }
23
- /** Collect the text of every step, and the doc links of the first step. */
24
- function collectSteps(node) {
25
- const texts = [];
26
- const firstStepLinks = [];
27
- if (node.type === "list" && node.ordered) {
28
- for (const item of node.children) {
29
- texts.push(getTextContent(item));
30
- if (firstStepLinks.length === 0) {
31
- collectDocLinks(item, firstStepLinks);
32
- }
33
- }
34
- }
35
- if ("children" in node) {
36
- for (const child of node.children) {
37
- const nested = collectSteps(child);
38
- texts.push(...nested.texts);
39
- if (firstStepLinks.length === 0)
40
- firstStepLinks.push(...nested.firstStepLinks);
41
- }
42
- }
43
- return { texts, firstStepLinks };
44
- }
45
- function collectDocLinks(node, out) {
46
- if (node.type === "link" && node.url.endsWith(".md"))
47
- out.push(node.url);
48
- if ("children" in node) {
49
- for (const child of node.children)
50
- collectDocLinks(child, out);
51
- }
52
- }
53
- export const glossaryTermLinkingRule = {
54
- meta: {
55
- type: "problem",
56
- docs: {
57
- description: "A Guide whose steps use glossary terms must link that Reference from its first step.",
58
- recommended: true,
59
- },
60
- },
61
- create(context) {
62
- return {
63
- root(node) {
64
- const filename = getFilename(context);
65
- if (!filename.endsWith("-guide.md"))
66
- return;
67
- const docsRoot = findDocsRoot(filename);
68
- if (!docsRoot)
69
- return;
70
- const docs = getProjectDocs(docsRoot);
71
- const guideDir = path.dirname(filename);
72
- // Find reference documents owned by this guide
73
- const guideReferences = docs.filter((doc) => doc.kind === "reference" && path.dirname(doc.filePath) === guideDir);
74
- if (guideReferences.length === 0)
75
- return;
76
- // Collect glossary terms from owned references
77
- const glossaryTerms = [];
78
- for (const ref of guideReferences) {
79
- glossaryTerms.push(...extractGlossaryTerms(ref.filePath));
80
- }
81
- if (glossaryTerms.length === 0)
82
- return;
83
- const { texts: stepTexts, firstStepLinks } = collectSteps(node);
84
- // Check if any step uses glossary terms
85
- const usedTerms = glossaryTerms.filter((term) => stepTexts.some((text) => text.includes(term)));
86
- if (usedTerms.length === 0)
87
- return;
88
- // Check if the first step links to any owned reference
89
- const hasRefLink = firstStepLinks.some((link) => guideReferences.some((ref) => link.includes(ref.fileName)));
90
- if (!hasRefLink) {
91
- context.report({
92
- node,
93
- message: `guide uses glossary terms (${usedTerms.join(", ")}) but first step does not link the reference`,
94
- });
95
- }
96
- },
97
- };
98
- },
99
- };
@@ -1,2 +0,0 @@
1
- import type { MarkdownRuleDefinition } from "@eslint/markdown";
2
- export declare const guideFolderEntryPointRule: MarkdownRuleDefinition;
@@ -1,46 +0,0 @@
1
- /**
2
- * @fileoverview Guide folders must have an entry point.
3
- */
4
- import path from "node:path";
5
- import { getFilename } from "./helpers.js";
6
- import { findDocsRoot, getProjectDocs } from "./project-index.js";
7
- export const guideFolderEntryPointRule = {
8
- meta: {
9
- type: "problem",
10
- docs: {
11
- description: "Guide folders must have an entry point.",
12
- recommended: true,
13
- },
14
- },
15
- create(context) {
16
- return {
17
- root(node) {
18
- const filename = getFilename(context);
19
- if (!filename.endsWith(".md"))
20
- return;
21
- const docsRoot = findDocsRoot(filename);
22
- if (!docsRoot)
23
- return;
24
- const docs = getProjectDocs(docsRoot);
25
- // Find guide folders: folders that hold rules/ or references/
26
- const guideFolders = new Set(docs
27
- .filter((doc) => ["rules", "references"].includes(path.basename(path.dirname(doc.filePath))))
28
- .map((doc) => path.dirname(path.dirname(doc.filePath)))
29
- // A rules/ or references/ folder directly under docs root belongs to no guide
30
- .filter((folder) => path.resolve(folder) !== path.resolve(docsRoot)));
31
- // Check if current file is in a guide folder that needs an entry point
32
- const currentDir = path.dirname(filename);
33
- if (guideFolders.has(currentDir)) {
34
- const expectedEntryPoint = `${path.basename(currentDir)}.md`;
35
- const hasEntryPoint = docs.some((doc) => doc.kind === "guide" && path.dirname(doc.filePath) === currentDir && doc.fileName === expectedEntryPoint);
36
- if (!hasEntryPoint) {
37
- context.report({
38
- node,
39
- message: `folder holds support documents but has no ${expectedEntryPoint} entry point`,
40
- });
41
- }
42
- }
43
- },
44
- };
45
- },
46
- };
@@ -1,5 +0,0 @@
1
- /**
2
- * @fileoverview A step that links another Guide must link directly to a How To section.
3
- */
4
- import type { MarkdownRuleDefinition } from "@eslint/markdown";
5
- export declare const guideLinkAnchorsRule: MarkdownRuleDefinition;