pasika 0.3.2 → 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.
- package/README.md +72 -20
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +4999 -103
- package/dist/eslint/pasika/index.d.ts +165 -53
- package/dist/eslint/pasika/index.js +4424 -89
- package/package.json +5 -6
- package/dist/cli/output.d.ts +0 -3
- package/dist/cli/output.js +0 -11
- package/dist/enforcement/coverage.d.ts +0 -51
- package/dist/enforcement/coverage.js +0 -206
- package/dist/enforcement/doctor.d.ts +0 -16
- package/dist/enforcement/doctor.js +0 -249
- package/dist/enforcement/normalize.d.ts +0 -11
- package/dist/enforcement/normalize.js +0 -21
- package/dist/enforcement/parse-docs.d.ts +0 -58
- package/dist/enforcement/parse-docs.js +0 -94
- package/dist/enforcement/types.d.ts +0 -54
- package/dist/enforcement/types.js +0 -50
- package/dist/eslint/pasika/ast-types.d.ts +0 -122
- package/dist/eslint/pasika/ast-types.js +0 -1
- package/dist/eslint/pasika/project/ccf.d.ts +0 -48
- package/dist/eslint/pasika/project/ccf.js +0 -119
- package/dist/eslint/pasika/project/index.d.ts +0 -21
- package/dist/eslint/pasika/project/index.js +0 -139
- package/dist/eslint/pasika/project/parse-module.d.ts +0 -27
- package/dist/eslint/pasika/project/parse-module.js +0 -128
- package/dist/eslint/pasika/rules/application-structure.d.ts +0 -2
- package/dist/eslint/pasika/rules/application-structure.js +0 -152
- package/dist/eslint/pasika/rules/component-conventions.d.ts +0 -16
- package/dist/eslint/pasika/rules/component-conventions.js +0 -145
- package/dist/eslint/pasika/rules/component-nesting.d.ts +0 -12
- package/dist/eslint/pasika/rules/component-nesting.js +0 -69
- package/dist/eslint/pasika/rules/component-placement.d.ts +0 -11
- package/dist/eslint/pasika/rules/component-placement.js +0 -75
- package/dist/eslint/pasika/rules/config-extraction.d.ts +0 -14
- package/dist/eslint/pasika/rules/config-extraction.js +0 -74
- package/dist/eslint/pasika/rules/cross-feature-import.d.ts +0 -2
- package/dist/eslint/pasika/rules/cross-feature-import.js +0 -75
- package/dist/eslint/pasika/rules/css/apply-usage.d.ts +0 -10
- package/dist/eslint/pasika/rules/css/apply-usage.js +0 -45
- package/dist/eslint/pasika/rules/css/base-layer-pair.d.ts +0 -10
- package/dist/eslint/pasika/rules/css/base-layer-pair.js +0 -49
- package/dist/eslint/pasika/rules/css/css-variable-naming.d.ts +0 -10
- package/dist/eslint/pasika/rules/css/css-variable-naming.js +0 -39
- package/dist/eslint/pasika/rules/css/custom-utility-apply.d.ts +0 -11
- package/dist/eslint/pasika/rules/css/custom-utility-apply.js +0 -52
- package/dist/eslint/pasika/rules/css/global-css-location.d.ts +0 -10
- package/dist/eslint/pasika/rules/css/global-css-location.js +0 -42
- package/dist/eslint/pasika/rules/css/helpers.d.ts +0 -29
- package/dist/eslint/pasika/rules/css/helpers.js +0 -93
- package/dist/eslint/pasika/rules/css/index.d.ts +0 -13
- package/dist/eslint/pasika/rules/css/index.js +0 -25
- package/dist/eslint/pasika/rules/css/root-variables.d.ts +0 -11
- package/dist/eslint/pasika/rules/css/root-variables.js +0 -53
- package/dist/eslint/pasika/rules/css/rule-tester.d.ts +0 -11
- package/dist/eslint/pasika/rules/css/rule-tester.js +0 -22
- package/dist/eslint/pasika/rules/css/stylesheet-ordering.d.ts +0 -11
- package/dist/eslint/pasika/rules/css/stylesheet-ordering.js +0 -76
- package/dist/eslint/pasika/rules/css/surface-utility.d.ts +0 -10
- package/dist/eslint/pasika/rules/css/surface-utility.js +0 -41
- package/dist/eslint/pasika/rules/css/theme-reset.d.ts +0 -9
- package/dist/eslint/pasika/rules/css/theme-reset.js +0 -36
- package/dist/eslint/pasika/rules/css/theme-variable-namespace.d.ts +0 -11
- package/dist/eslint/pasika/rules/css/theme-variable-namespace.js +0 -53
- package/dist/eslint/pasika/rules/cva-appearance-props.d.ts +0 -10
- package/dist/eslint/pasika/rules/cva-appearance-props.js +0 -77
- package/dist/eslint/pasika/rules/cva-boolean-variants.d.ts +0 -11
- package/dist/eslint/pasika/rules/cva-boolean-variants.js +0 -97
- package/dist/eslint/pasika/rules/data-testid-case.d.ts +0 -2
- package/dist/eslint/pasika/rules/data-testid-case.js +0 -76
- package/dist/eslint/pasika/rules/enforce-barrel-exports.d.ts +0 -9
- package/dist/eslint/pasika/rules/enforce-barrel-exports.js +0 -78
- package/dist/eslint/pasika/rules/enforce-cn-merge.d.ts +0 -21
- package/dist/eslint/pasika/rules/enforce-cn-merge.js +0 -86
- package/dist/eslint/pasika/rules/enforce-cva-variant-props.d.ts +0 -9
- package/dist/eslint/pasika/rules/enforce-cva-variant-props.js +0 -86
- package/dist/eslint/pasika/rules/filename-case.d.ts +0 -2
- package/dist/eslint/pasika/rules/filename-case.js +0 -123
- package/dist/eslint/pasika/rules/hook-complexity.d.ts +0 -12
- package/dist/eslint/pasika/rules/hook-complexity.js +0 -114
- package/dist/eslint/pasika/rules/hook-extraction.d.ts +0 -11
- package/dist/eslint/pasika/rules/hook-extraction.js +0 -55
- package/dist/eslint/pasika/rules/import-boundaries.d.ts +0 -2
- package/dist/eslint/pasika/rules/import-boundaries.js +0 -167
- package/dist/eslint/pasika/rules/import-through-index.d.ts +0 -2
- package/dist/eslint/pasika/rules/import-through-index.js +0 -52
- package/dist/eslint/pasika/rules/interactive-component.d.ts +0 -10
- package/dist/eslint/pasika/rules/interactive-component.js +0 -76
- package/dist/eslint/pasika/rules/json/index.d.ts +0 -5
- package/dist/eslint/pasika/rules/json/index.js +0 -9
- package/dist/eslint/pasika/rules/json/no-cache-flag.d.ts +0 -10
- package/dist/eslint/pasika/rules/json/no-cache-flag.js +0 -45
- package/dist/eslint/pasika/rules/json/no-vulyk-dependency.d.ts +0 -10
- package/dist/eslint/pasika/rules/json/no-vulyk-dependency.js +0 -41
- package/dist/eslint/pasika/rules/json/rule-tester.d.ts +0 -11
- package/dist/eslint/pasika/rules/json/rule-tester.js +0 -21
- package/dist/eslint/pasika/rules/jsx-hygiene.d.ts +0 -9
- package/dist/eslint/pasika/rules/jsx-hygiene.js +0 -108
- package/dist/eslint/pasika/rules/locale-dotted-path.d.ts +0 -10
- package/dist/eslint/pasika/rules/locale-dotted-path.js +0 -65
- package/dist/eslint/pasika/rules/locale-placement.d.ts +0 -13
- package/dist/eslint/pasika/rules/locale-placement.js +0 -163
- package/dist/eslint/pasika/rules/locales-location.d.ts +0 -11
- package/dist/eslint/pasika/rules/locales-location.js +0 -56
- package/dist/eslint/pasika/rules/md/doc-kind-suffix.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/doc-kind-suffix.js +0 -29
- package/dist/eslint/pasika/rules/md/example-heading-description.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/example-heading-description.js +0 -30
- package/dist/eslint/pasika/rules/md/glossary-term-linking.d.ts +0 -2
- package/dist/eslint/pasika/rules/md/glossary-term-linking.js +0 -99
- package/dist/eslint/pasika/rules/md/guide-folder-entry-point.d.ts +0 -2
- package/dist/eslint/pasika/rules/md/guide-folder-entry-point.js +0 -46
- package/dist/eslint/pasika/rules/md/guide-link-anchors.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/guide-link-anchors.js +0 -50
- package/dist/eslint/pasika/rules/md/guide-overview-no-links.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/guide-overview-no-links.js +0 -51
- package/dist/eslint/pasika/rules/md/guide-states-no-requirement.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/guide-states-no-requirement.js +0 -26
- package/dist/eslint/pasika/rules/md/guide-step-single-link.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/guide-step-single-link.js +0 -48
- package/dist/eslint/pasika/rules/md/guide-step-single-sentence.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/guide-step-single-sentence.js +0 -42
- package/dist/eslint/pasika/rules/md/helpers.d.ts +0 -25
- package/dist/eslint/pasika/rules/md/helpers.js +0 -37
- package/dist/eslint/pasika/rules/md/index.d.ts +0 -27
- package/dist/eslint/pasika/rules/md/index.js +0 -53
- package/dist/eslint/pasika/rules/md/no-cross-document-link.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/no-cross-document-link.js +0 -36
- package/dist/eslint/pasika/rules/md/no-nested-how-to.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/no-nested-how-to.js +0 -39
- package/dist/eslint/pasika/rules/md/no-template-prompt.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/no-template-prompt.js +0 -22
- package/dist/eslint/pasika/rules/md/overview-length.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/overview-length.js +0 -47
- package/dist/eslint/pasika/rules/md/overview-present.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/overview-present.js +0 -41
- package/dist/eslint/pasika/rules/md/policy-no-examples.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/policy-no-examples.js +0 -28
- package/dist/eslint/pasika/rules/md/policy-single-document.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/policy-single-document.js +0 -34
- package/dist/eslint/pasika/rules/md/policy-subject-headings.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/policy-subject-headings.js +0 -58
- package/dist/eslint/pasika/rules/md/project-index.d.ts +0 -17
- package/dist/eslint/pasika/rules/md/project-index.js +0 -67
- package/dist/eslint/pasika/rules/md/reference-block-headings.d.ts +0 -6
- package/dist/eslint/pasika/rules/md/reference-block-headings.js +0 -31
- package/dist/eslint/pasika/rules/md/reference-no-rfc-vocabulary.d.ts +0 -6
- package/dist/eslint/pasika/rules/md/reference-no-rfc-vocabulary.js +0 -26
- package/dist/eslint/pasika/rules/md/requirement-present.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/requirement-present.js +0 -41
- package/dist/eslint/pasika/rules/md/rfc-only-in-bullets.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/rfc-only-in-bullets.js +0 -46
- package/dist/eslint/pasika/rules/md/rule-paired-examples.d.ts +0 -5
- package/dist/eslint/pasika/rules/md/rule-paired-examples.js +0 -36
- package/dist/eslint/pasika/rules/md/rule-tester.d.ts +0 -11
- package/dist/eslint/pasika/rules/md/rule-tester.js +0 -21
- package/dist/eslint/pasika/rules/md/support-document-placement.d.ts +0 -2
- package/dist/eslint/pasika/rules/md/support-document-placement.js +0 -36
- package/dist/eslint/pasika/rules/md/title-matches-file-name.d.ts +0 -2
- package/dist/eslint/pasika/rules/md/title-matches-file-name.js +0 -46
- package/dist/eslint/pasika/rules/named-exports.d.ts +0 -2
- package/dist/eslint/pasika/rules/named-exports.js +0 -49
- package/dist/eslint/pasika/rules/no-arbitrary-tailwind.d.ts +0 -9
- package/dist/eslint/pasika/rules/no-arbitrary-tailwind.js +0 -97
- package/dist/eslint/pasika/rules/no-eslint-disable.d.ts +0 -10
- package/dist/eslint/pasika/rules/no-eslint-disable.js +0 -33
- package/dist/eslint/pasika/rules/no-mixed-concerns.d.ts +0 -9
- package/dist/eslint/pasika/rules/no-mixed-concerns.js +0 -71
- package/dist/eslint/pasika/rules/no-util-barrel.d.ts +0 -2
- package/dist/eslint/pasika/rules/no-util-barrel.js +0 -48
- package/dist/eslint/pasika/rules/pure-function-extract.d.ts +0 -9
- package/dist/eslint/pasika/rules/pure-function-extract.js +0 -92
- package/dist/eslint/pasika/rules/shared-style-dedup.d.ts +0 -13
- package/dist/eslint/pasika/rules/shared-style-dedup.js +0 -91
- package/dist/eslint/pasika/rules/stay-flat.d.ts +0 -12
- package/dist/eslint/pasika/rules/stay-flat.js +0 -81
- package/dist/eslint/pasika/rules/support-file-placement.d.ts +0 -15
- package/dist/eslint/pasika/rules/support-file-placement.js +0 -70
- package/dist/eslint/pasika/rules/support-folder-shape.d.ts +0 -2
- package/dist/eslint/pasika/rules/support-folder-shape.js +0 -59
- package/dist/eslint/pasika/rules/type-extraction.d.ts +0 -13
- package/dist/eslint/pasika/rules/type-extraction.js +0 -85
- package/dist/eslint/pasika/rules/ui-state.d.ts +0 -9
- package/dist/eslint/pasika/rules/ui-state.js +0 -99
- package/dist/eslint/pasika/rules/util-file-name.d.ts +0 -2
- package/dist/eslint/pasika/rules/util-file-name.js +0 -48
- package/dist/eslint/pasika/rules/value-extraction.d.ts +0 -13
- package/dist/eslint/pasika/rules/value-extraction.js +0 -48
- package/enforcement/registry.json +0 -1145
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: pasika/import-boundaries
|
|
3
|
-
*
|
|
4
|
-
* Enforces the import conventions from the "Exports and Imports Rule":
|
|
5
|
-
* - Whichever of the relative path and the @/* alias has fewer segments, with
|
|
6
|
-
* a tie going to the relative path.
|
|
7
|
-
* - Layer boundary enforcement (app → compositions → features → shared → root).
|
|
8
|
-
*
|
|
9
|
-
* @see docs/code-organization-guide/rules/exports-and-imports-rule.md
|
|
10
|
-
*/
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
const sourceRoot = path.resolve("src");
|
|
13
|
-
const rootSupportFolders = new Set(["config", "constants", "hooks", "locales", "schemas", "types", "utils"]);
|
|
14
|
-
const moduleExtensions = new Set([".cjs", ".cts", ".js", ".jsx", ".mjs", ".mts", ".ts", ".tsx"]);
|
|
15
|
-
const styleExtensions = new Set([".css", ".less", ".sass", ".scss"]);
|
|
16
|
-
function resolveSourceImport(filename, importPath) {
|
|
17
|
-
if (importPath.startsWith("@/")) {
|
|
18
|
-
return path.resolve(sourceRoot, importPath.slice(2));
|
|
19
|
-
}
|
|
20
|
-
if (importPath.startsWith(".")) {
|
|
21
|
-
return path.resolve(path.dirname(filename), importPath);
|
|
22
|
-
}
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
function sourceSegments(absolutePath) {
|
|
26
|
-
const relativePath = path.relative(sourceRoot, absolutePath);
|
|
27
|
-
if (relativePath.startsWith("..") || path.isAbsolute(relativePath)) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
return relativePath.split(path.sep);
|
|
31
|
-
}
|
|
32
|
-
/** The relative form of an import, always prefixed so it reads as a path. */
|
|
33
|
-
function relativeSpecifier(filename, resolvedPath) {
|
|
34
|
-
const relativePath = path.relative(path.dirname(filename), resolvedPath).split(path.sep).join("/");
|
|
35
|
-
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
36
|
-
}
|
|
37
|
-
/** The `@/*` form of an import. */
|
|
38
|
-
function aliasSpecifier(resolvedPath) {
|
|
39
|
-
return `@/${(sourceSegments(resolvedPath) ?? []).join("/")}`;
|
|
40
|
-
}
|
|
41
|
-
/** Segments in a specifier: one per `../` step and one per name, ignoring a leading `./`. */
|
|
42
|
-
function segmentCount(specifier) {
|
|
43
|
-
return specifier
|
|
44
|
-
.replace(/^@\//, "")
|
|
45
|
-
.split("/")
|
|
46
|
-
.filter((segment) => segment !== "." && segment !== "").length;
|
|
47
|
-
}
|
|
48
|
-
function describeSegments(count) {
|
|
49
|
-
return `${String(count)} segment${count === 1 ? "" : "s"}`;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Whether the relative form is the one to use. Shorter wins, and a tie goes to
|
|
53
|
-
* the relative form. Because crossing a layer always costs at least one `../`
|
|
54
|
-
* while the alias spells the same tail, the alias always wins for a
|
|
55
|
-
* cross-layer import without this needing to know what a layer is.
|
|
56
|
-
*/
|
|
57
|
-
function prefersRelative(filename, resolvedPath) {
|
|
58
|
-
return segmentCount(relativeSpecifier(filename, resolvedPath)) <= segmentCount(aliasSpecifier(resolvedPath));
|
|
59
|
-
}
|
|
60
|
-
export const importBoundariesRule = {
|
|
61
|
-
meta: {
|
|
62
|
-
schema: [],
|
|
63
|
-
type: "problem",
|
|
64
|
-
},
|
|
65
|
-
create(context) {
|
|
66
|
-
const filename = context.filename;
|
|
67
|
-
if (!filename) {
|
|
68
|
-
return {};
|
|
69
|
-
}
|
|
70
|
-
function reportImport(source) {
|
|
71
|
-
if (typeof source.value !== "string") {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const importPath = source.value;
|
|
75
|
-
const resolvedPath = resolveSourceImport(filename, importPath);
|
|
76
|
-
if (!resolvedPath) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const importer = sourceSegments(filename);
|
|
80
|
-
const imported = sourceSegments(resolvedPath);
|
|
81
|
-
if (!importer || !imported || importer.length === 0 || imported.length === 0) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const [importerLayer = "", importerFeature] = importer;
|
|
85
|
-
const [importedLayer = "", importedFeature] = imported;
|
|
86
|
-
const extension = path.extname(importPath);
|
|
87
|
-
const isCodeModule = !extension || moduleExtensions.has(extension);
|
|
88
|
-
const isAppLocalStyleImport = importerLayer === "app" && importedLayer === "app" && styleExtensions.has(extension);
|
|
89
|
-
const importedIsRootSupport = rootSupportFolders.has(importedLayer);
|
|
90
|
-
const importedIsSameConfig = importerLayer === "config" && importedLayer === "config" && importer[1] === imported[1];
|
|
91
|
-
const isAllowed = (!isCodeModule && importerLayer === "app" && isAppLocalStyleImport) ||
|
|
92
|
-
(isCodeModule &&
|
|
93
|
-
importerLayer === "app" &&
|
|
94
|
-
(importedLayer === "compositions" ||
|
|
95
|
-
importedLayer === "features" ||
|
|
96
|
-
importedLayer === "shared" ||
|
|
97
|
-
importedIsRootSupport)) ||
|
|
98
|
-
(isCodeModule &&
|
|
99
|
-
importerLayer === "compositions" &&
|
|
100
|
-
(importedLayer === "compositions" ||
|
|
101
|
-
importedLayer === "features" ||
|
|
102
|
-
importedLayer === "shared" ||
|
|
103
|
-
importedIsRootSupport)) ||
|
|
104
|
-
(isCodeModule &&
|
|
105
|
-
importerLayer === "features" &&
|
|
106
|
-
((importedLayer === "features" && importerFeature === importedFeature) ||
|
|
107
|
-
importedLayer === "shared" ||
|
|
108
|
-
importedIsRootSupport)) ||
|
|
109
|
-
(isCodeModule && importerLayer === "shared" && (importedLayer === "shared" || importedIsRootSupport)) ||
|
|
110
|
-
(isCodeModule &&
|
|
111
|
-
rootSupportFolders.has(importerLayer) &&
|
|
112
|
-
importedIsRootSupport &&
|
|
113
|
-
(importerLayer !== "config" || importedLayer !== "config" || importedIsSameConfig));
|
|
114
|
-
if (!isAllowed) {
|
|
115
|
-
context.report({
|
|
116
|
-
node: source,
|
|
117
|
-
message: "This import violates the src layer boundary.",
|
|
118
|
-
});
|
|
119
|
-
// The fix is to move the file, so how the specifier is spelled does not matter yet.
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
const relativeForm = relativeSpecifier(filename, resolvedPath);
|
|
123
|
-
const aliasForm = aliasSpecifier(resolvedPath);
|
|
124
|
-
const relativeSegments = segmentCount(relativeForm);
|
|
125
|
-
const aliasSegments = segmentCount(aliasForm);
|
|
126
|
-
function describeChoice(preferred, preferredSegments, other, otherSegments) {
|
|
127
|
-
const tie = preferredSegments === otherSegments ? ", and a tie goes to the relative path" : "";
|
|
128
|
-
return (`Use "${preferred}" (${describeSegments(preferredSegments)}) ` +
|
|
129
|
-
`instead of "${other}" (${describeSegments(otherSegments)})${tie}.`);
|
|
130
|
-
}
|
|
131
|
-
if (prefersRelative(filename, resolvedPath) && importPath.startsWith("@/")) {
|
|
132
|
-
context.report({
|
|
133
|
-
node: source,
|
|
134
|
-
message: describeChoice(relativeForm, relativeSegments, aliasForm, aliasSegments),
|
|
135
|
-
});
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (!prefersRelative(filename, resolvedPath) && importPath.startsWith(".")) {
|
|
139
|
-
context.report({
|
|
140
|
-
node: source,
|
|
141
|
-
message: describeChoice(aliasForm, aliasSegments, relativeForm, relativeSegments),
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
ImportDeclaration(node) {
|
|
147
|
-
reportImport(node.source);
|
|
148
|
-
},
|
|
149
|
-
ExportAllDeclaration(node) {
|
|
150
|
-
reportImport(node.source);
|
|
151
|
-
},
|
|
152
|
-
ExportNamedDeclaration(node) {
|
|
153
|
-
if (node.source) {
|
|
154
|
-
reportImport(node.source);
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
ImportExpression(node) {
|
|
158
|
-
reportImport(node.source);
|
|
159
|
-
},
|
|
160
|
-
CallExpression(node) {
|
|
161
|
-
if (node.callee.type === "Identifier" && node.callee.name === "require" && node.arguments[0]) {
|
|
162
|
-
reportImport(node.arguments[0]);
|
|
163
|
-
}
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { resolveSpecifier } from "../project/index.js";
|
|
3
|
-
import { segmentsOf } from "../project/ccf.js";
|
|
4
|
-
export const importThroughIndexRule = {
|
|
5
|
-
meta: {
|
|
6
|
-
schema: [],
|
|
7
|
-
type: "problem",
|
|
8
|
-
docs: {
|
|
9
|
-
description: "Require imports of support files to use their support-folder index.",
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
create(context) {
|
|
13
|
-
const filename = path.resolve(context.filename);
|
|
14
|
-
const sourceRoot = sourceRootOf(filename);
|
|
15
|
-
return {
|
|
16
|
-
Program(node) {
|
|
17
|
-
for (const specifier of importSpecifiers(context.sourceCode.text)) {
|
|
18
|
-
const target = resolveSpecifier(filename, specifier, sourceRoot);
|
|
19
|
-
if (!target)
|
|
20
|
-
continue;
|
|
21
|
-
const targetSegments = segmentsOf(target, sourceRoot);
|
|
22
|
-
const supportFolderIndex = targetSegments.findIndex((segment) => ["constants", "types", "schemas"].includes(segment));
|
|
23
|
-
const supportFolder = supportFolderIndex >= 0 ? targetSegments[supportFolderIndex] : undefined;
|
|
24
|
-
if (!supportFolder || path.basename(target).startsWith("index."))
|
|
25
|
-
continue;
|
|
26
|
-
const folderIndex = targetSegments.slice(0, supportFolderIndex + 1);
|
|
27
|
-
const expected = `@/${folderIndex.join("/")}`;
|
|
28
|
-
context.report({
|
|
29
|
-
node,
|
|
30
|
-
message: `Import support files through ${expected} instead of "${specifier}". ` +
|
|
31
|
-
"See the code-organization-guide exports and imports rules.",
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
function importSpecifiers(source) {
|
|
39
|
-
const specifiers = [];
|
|
40
|
-
const pattern = /\bimport\s+(?:(?:type\s+)?[\s\S]*?\sfrom\s+)?["'](?<specifier>[^"']+)["']/g;
|
|
41
|
-
for (const match of source.matchAll(pattern)) {
|
|
42
|
-
const specifier = match.groups?.specifier;
|
|
43
|
-
if (specifier)
|
|
44
|
-
specifiers.push(specifier);
|
|
45
|
-
}
|
|
46
|
-
return specifiers;
|
|
47
|
-
}
|
|
48
|
-
function sourceRootOf(filename) {
|
|
49
|
-
const marker = `${path.sep}src${path.sep}`;
|
|
50
|
-
const srcIndex = filename.lastIndexOf(marker);
|
|
51
|
-
return srcIndex >= 0 ? filename.slice(0, srcIndex + marker.length - 1) : path.resolve("src");
|
|
52
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: pasika/interactive-component
|
|
3
|
-
*
|
|
4
|
-
* Interactive elements are component boundaries when they are mixed with other
|
|
5
|
-
* content in the same component. Standalone interactive components are valid.
|
|
6
|
-
*
|
|
7
|
-
* @see docs/code-organization-guide/rules/interactive-component-rule.md
|
|
8
|
-
*/
|
|
9
|
-
import type { Rule } from "eslint";
|
|
10
|
-
export declare const interactiveComponentRule: Rule.RuleModule;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: pasika/interactive-component
|
|
3
|
-
*
|
|
4
|
-
* Interactive elements are component boundaries when they are mixed with other
|
|
5
|
-
* content in the same component. Standalone interactive components are valid.
|
|
6
|
-
*
|
|
7
|
-
* @see docs/code-organization-guide/rules/interactive-component-rule.md
|
|
8
|
-
*/
|
|
9
|
-
const INTERACTIVE_TAGS = new Set([
|
|
10
|
-
"a",
|
|
11
|
-
"button",
|
|
12
|
-
"details",
|
|
13
|
-
"embed",
|
|
14
|
-
"iframe",
|
|
15
|
-
"input",
|
|
16
|
-
"label",
|
|
17
|
-
"select",
|
|
18
|
-
"textarea",
|
|
19
|
-
"video",
|
|
20
|
-
]);
|
|
21
|
-
function tagName(node) {
|
|
22
|
-
const name = node.openingElement?.name;
|
|
23
|
-
if (name?.type !== "JSXIdentifier")
|
|
24
|
-
return undefined;
|
|
25
|
-
return name.name;
|
|
26
|
-
}
|
|
27
|
-
function isInteractive(node) {
|
|
28
|
-
const name = tagName(node);
|
|
29
|
-
return name !== undefined && INTERACTIVE_TAGS.has(name);
|
|
30
|
-
}
|
|
31
|
-
function isComponentElement(node) {
|
|
32
|
-
const name = tagName(node);
|
|
33
|
-
return name !== undefined && /^[A-Z]/.test(name);
|
|
34
|
-
}
|
|
35
|
-
function isComponentReturn(node) {
|
|
36
|
-
const parent = node.parent;
|
|
37
|
-
if (parent.type === "ReturnStatement")
|
|
38
|
-
return true;
|
|
39
|
-
return parent.type === "ArrowFunctionExpression" && parent.body === node;
|
|
40
|
-
}
|
|
41
|
-
export const interactiveComponentRule = {
|
|
42
|
-
meta: {
|
|
43
|
-
schema: [],
|
|
44
|
-
type: "problem",
|
|
45
|
-
docs: {
|
|
46
|
-
description: "Require interactive HTML elements mixed with other content to be extracted into components.",
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
create(context) {
|
|
50
|
-
if (!context.filename.endsWith(".tsx") && !context.filename.endsWith(".jsx"))
|
|
51
|
-
return {};
|
|
52
|
-
return {
|
|
53
|
-
JSXElement(node) {
|
|
54
|
-
if (!isInteractive(node))
|
|
55
|
-
return;
|
|
56
|
-
if (isComponentElement(node.parent)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (isInteractive(node.parent)) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (isComponentReturn(node)) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const name = tagName(node);
|
|
66
|
-
if (name === undefined)
|
|
67
|
-
return;
|
|
68
|
-
context.report({
|
|
69
|
-
node,
|
|
70
|
-
message: `Extract the interactive <${name}> into a descriptive component. ` +
|
|
71
|
-
"See docs/code-organization-guide/rules/interactive-component-rule.md",
|
|
72
|
-
});
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* All JSON rules for the package.json checks.
|
|
3
|
-
*/
|
|
4
|
-
import { noCacheFlagRule } from "./no-cache-flag.js";
|
|
5
|
-
import { noVulykDependencyRule } from "./no-vulyk-dependency.js";
|
|
6
|
-
export const jsonRules = {
|
|
7
|
-
"no-cache-flag": noCacheFlagRule,
|
|
8
|
-
"no-vulyk-dependency": noVulykDependencyRule,
|
|
9
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: pasika/no-cache-flag
|
|
3
|
-
*
|
|
4
|
-
* A lint command MUST NOT pass ESLint's --cache flag, because rules that
|
|
5
|
-
* compare a file against the rest of the tree need every file in the run.
|
|
6
|
-
*
|
|
7
|
-
* @see docs/agent-policy.md
|
|
8
|
-
*/
|
|
9
|
-
import type { JSONRuleDefinition } from "@eslint/json";
|
|
10
|
-
export declare const noCacheFlagRule: JSONRuleDefinition;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: pasika/no-cache-flag
|
|
3
|
-
*
|
|
4
|
-
* A lint command MUST NOT pass ESLint's --cache flag, because rules that
|
|
5
|
-
* compare a file against the rest of the tree need every file in the run.
|
|
6
|
-
*
|
|
7
|
-
* @see docs/agent-policy.md
|
|
8
|
-
*/
|
|
9
|
-
function memberName(member) {
|
|
10
|
-
return member.name.type === "String" ? member.name.value : member.name.name;
|
|
11
|
-
}
|
|
12
|
-
export const noCacheFlagRule = {
|
|
13
|
-
meta: {
|
|
14
|
-
schema: [],
|
|
15
|
-
type: "problem",
|
|
16
|
-
docs: {
|
|
17
|
-
description: "Require lint scripts to not pass ESLint's --cache flag.",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
create(context) {
|
|
21
|
-
return {
|
|
22
|
-
Document(node) {
|
|
23
|
-
const root = node.body;
|
|
24
|
-
if (root.type !== "Object")
|
|
25
|
-
return;
|
|
26
|
-
const scripts = root.members.find((member) => memberName(member) === "scripts");
|
|
27
|
-
if (scripts?.value.type !== "Object")
|
|
28
|
-
return;
|
|
29
|
-
for (const member of scripts.value.members) {
|
|
30
|
-
const name = memberName(member);
|
|
31
|
-
if (name !== "lint" && name !== "fix")
|
|
32
|
-
continue;
|
|
33
|
-
if (member.value.type !== "String")
|
|
34
|
-
continue;
|
|
35
|
-
if (member.value.value.includes("--cache")) {
|
|
36
|
-
context.report({
|
|
37
|
-
node: member,
|
|
38
|
-
message: "Lint scripts must not pass ESLint's --cache flag because cross-file rules require every file in the run.",
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
},
|
|
45
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: pasika/no-vulyk-dependency
|
|
3
|
-
*
|
|
4
|
-
* Vulyk MUST NOT be added to package.json in order to run its CLI; it MUST run
|
|
5
|
-
* as an ephemeral command such as npx vulyk@latest.
|
|
6
|
-
*
|
|
7
|
-
* @see docs/agent-policy.md
|
|
8
|
-
*/
|
|
9
|
-
import type { JSONRuleDefinition } from "@eslint/json";
|
|
10
|
-
export declare const noVulykDependencyRule: JSONRuleDefinition;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: pasika/no-vulyk-dependency
|
|
3
|
-
*
|
|
4
|
-
* Vulyk MUST NOT be added to package.json in order to run its CLI; it MUST run
|
|
5
|
-
* as an ephemeral command such as npx vulyk@latest.
|
|
6
|
-
*
|
|
7
|
-
* @see docs/agent-policy.md
|
|
8
|
-
*/
|
|
9
|
-
function memberName(member) {
|
|
10
|
-
return member.name.type === "String" ? member.name.value : member.name.name;
|
|
11
|
-
}
|
|
12
|
-
export const noVulykDependencyRule = {
|
|
13
|
-
meta: {
|
|
14
|
-
schema: [],
|
|
15
|
-
type: "problem",
|
|
16
|
-
docs: {
|
|
17
|
-
description: "Require vulyk to run as an ephemeral command, not a package.json dependency.",
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
create(context) {
|
|
21
|
-
return {
|
|
22
|
-
Document(node) {
|
|
23
|
-
const root = node.body;
|
|
24
|
-
if (root.type !== "Object")
|
|
25
|
-
return;
|
|
26
|
-
for (const key of ["dependencies", "devDependencies"]) {
|
|
27
|
-
const section = root.members.find((member) => memberName(member) === key);
|
|
28
|
-
if (section?.value.type !== "Object")
|
|
29
|
-
continue;
|
|
30
|
-
const vulyk = section.value.members.find((member) => memberName(member) === "vulyk");
|
|
31
|
-
if (vulyk) {
|
|
32
|
-
context.report({
|
|
33
|
-
node: vulyk,
|
|
34
|
-
message: 'Vulyk must not be a package.json dependency. Run it as "npx vulyk@latest" instead.',
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared RuleTester wiring for the package.json rule tests.
|
|
3
|
-
*
|
|
4
|
-
* Each `describe` title in a rule test is the exact text of the requirement the
|
|
5
|
-
* case pins, which is how `pasika coverage` verifies that a requirement recorded
|
|
6
|
-
* as lint-enforced has a test behind it.
|
|
7
|
-
*/
|
|
8
|
-
import { describe } from "node:test";
|
|
9
|
-
import { RuleTester } from "eslint";
|
|
10
|
-
export declare const jsonRuleTester: RuleTester;
|
|
11
|
-
export { describe };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared RuleTester wiring for the package.json rule tests.
|
|
3
|
-
*
|
|
4
|
-
* Each `describe` title in a rule test is the exact text of the requirement the
|
|
5
|
-
* case pins, which is how `pasika coverage` verifies that a requirement recorded
|
|
6
|
-
* as lint-enforced has a test behind it.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it } from "node:test";
|
|
9
|
-
import { RuleTester } from "eslint";
|
|
10
|
-
import jsonPlugin from "@eslint/json";
|
|
11
|
-
import { jsonRules } from "../../index.js";
|
|
12
|
-
RuleTester.describe = describe;
|
|
13
|
-
RuleTester.it = it;
|
|
14
|
-
export const jsonRuleTester = new RuleTester({
|
|
15
|
-
language: "json/json",
|
|
16
|
-
plugins: {
|
|
17
|
-
json: { languages: { json: jsonPlugin.languages.json } },
|
|
18
|
-
pasika: { rules: jsonRules },
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
export { describe };
|
|
@@ -1,9 +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 type { Rule } from "eslint";
|
|
9
|
-
export declare const jsxHygieneRule: Rule.RuleModule;
|
|
@@ -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
|
-
};
|