@trackunit/eslint-plugin-trackunit 0.7.19 → 0.7.20-alpha-563d99d17d6.0
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/CHANGELOG.md +0 -92
- package/README.md +0 -13
- package/package.json +2 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -2
- package/src/lib/config/index.d.ts +0 -32
- package/src/lib/config/plugins.d.ts +0 -26
- package/src/lib/config/plugins.js +1 -19
- package/src/lib/config/presets/base.d.ts +0 -9
- package/src/lib/config/presets/react.d.ts +0 -23
- package/src/lib/config/presets/react.js +0 -4
- package/src/lib/rules/no-unused-translation-key/used-strings.js +1 -1
- package/src/lib/rules-map.d.ts +0 -3
- package/src/lib/rules-map.js +0 -2
- package/src/lib/{rules/no-unused-translation-key/utils/program-utils → utils}/program-utils.js +1 -1
- package/src/lib/rules/require-component-directory/require-component-directory.d.ts +0 -16
- package/src/lib/rules/require-component-directory/require-component-directory.js +0 -240
- package/src/lib/rules/require-component-directory/utils/component-directory-structure-utils/component-directory-structure-utils.d.ts +0 -34
- package/src/lib/rules/require-component-directory/utils/component-directory-structure-utils/component-directory-structure-utils.js +0 -114
- package/src/lib/rules/require-hook-util-directory/require-hook-util-directory.d.ts +0 -9
- package/src/lib/rules/require-hook-util-directory/require-hook-util-directory.js +0 -50
- package/src/lib/rules/require-hook-util-directory/utils/hook-util-directory-structure-utils/hook-util-directory-structure-utils.d.ts +0 -15
- package/src/lib/rules/require-hook-util-directory/utils/hook-util-directory-structure-utils/hook-util-directory-structure-utils.js +0 -44
- package/src/lib/rules/require-iris-app-ai-navigation/require-iris-app-ai-navigation.d.ts +0 -4
- package/src/lib/rules/require-iris-app-ai-navigation/require-iris-app-ai-navigation.js +0 -61
- package/src/lib/rules/require-nested-components-directory/require-nested-components-directory.d.ts +0 -9
- package/src/lib/rules/require-nested-components-directory/require-nested-components-directory.js +0 -44
- package/src/lib/rules/require-nested-components-directory/utils/nested-component-directory-utils/nested-component-directory-utils.d.ts +0 -17
- package/src/lib/rules/require-nested-components-directory/utils/nested-component-directory-utils/nested-component-directory-utils.js +0 -206
- package/src/lib/rules/require-nested-components-privacy/require-nested-components-privacy.d.ts +0 -9
- package/src/lib/rules/require-nested-components-privacy/require-nested-components-privacy.js +0 -63
- package/src/lib/rules/require-nested-components-privacy/utils/nested-component-privacy-utils/nested-component-privacy-utils.d.ts +0 -14
- package/src/lib/rules/require-nested-components-privacy/utils/nested-component-privacy-utils/nested-component-privacy-utils.js +0 -62
- package/src/lib/rules/require-page-directory/require-page-directory.d.ts +0 -8
- package/src/lib/rules/require-page-directory/require-page-directory.js +0 -44
- package/src/lib/rules/require-page-directory/utils/page-directory-structure-utils/page-directory-structure-utils.d.ts +0 -18
- package/src/lib/rules/require-page-directory/utils/page-directory-structure-utils/page-directory-structure-utils.js +0 -159
- package/src/lib/utils/create-rule/create-rule.d.ts +0 -7
- package/src/lib/utils/create-rule/create-rule.js +0 -9
- package/src/lib/utils/source-tree-utils/source-tree-utils.d.ts +0 -43
- package/src/lib/utils/source-tree-utils/source-tree-utils.js +0 -136
- /package/src/lib/{rules/no-unused-translation-key/utils/program-utils → utils}/program-utils.d.ts +0 -0
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* ESLint rule: require-component-directory
|
|
4
|
-
*
|
|
5
|
-
* Disallows a flat `components/` directory where component files, specs, stories,
|
|
6
|
-
* and related UI files live directly alongside each other.
|
|
7
|
-
*
|
|
8
|
-
* Each component must have its own PascalCase folder:
|
|
9
|
-
* `components/Button/Button.tsx`, not `components/Button.tsx`.
|
|
10
|
-
*
|
|
11
|
-
* See README.md for incorrect/correct examples.
|
|
12
|
-
*/
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.requireComponentDirectory = void 0;
|
|
15
|
-
const tslib_1 = require("tslib");
|
|
16
|
-
const utils_1 = require("@typescript-eslint/utils");
|
|
17
|
-
const fs = tslib_1.__importStar(require("fs"));
|
|
18
|
-
const path = tslib_1.__importStar(require("path"));
|
|
19
|
-
const ts = tslib_1.__importStar(require("typescript"));
|
|
20
|
-
const component_utils_1 = require("../../utils/component-utils");
|
|
21
|
-
const create_rule_1 = require("../../utils/create-rule/create-rule");
|
|
22
|
-
const component_directory_structure_utils_1 = require("./utils/component-directory-structure-utils/component-directory-structure-utils");
|
|
23
|
-
const COMPANION_FILE_PATTERN = /\.(spec|stories|docs|variants|module)\.(tsx|ts)$/;
|
|
24
|
-
/**
|
|
25
|
-
* Same exported-component detection as `one-component-per-file`. A PascalCase
|
|
26
|
-
* file that does not export a component (a context object, a reducer) is not a
|
|
27
|
-
* component file. Specs, stories, docs, and variants still move with the component.
|
|
28
|
-
*/
|
|
29
|
-
const fileExportsComponent = (program) => {
|
|
30
|
-
const tracker = (0, component_utils_1.createComponentFileTracker)();
|
|
31
|
-
for (const statement of program.body) {
|
|
32
|
-
if (statement.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration) {
|
|
33
|
-
tracker.onExportNamedDeclaration(statement);
|
|
34
|
-
const declaration = statement.declaration;
|
|
35
|
-
if (declaration?.type === utils_1.AST_NODE_TYPES.FunctionDeclaration) {
|
|
36
|
-
tracker.onFunctionDeclaration(declaration);
|
|
37
|
-
}
|
|
38
|
-
if (declaration?.type === utils_1.AST_NODE_TYPES.VariableDeclaration) {
|
|
39
|
-
for (const declarator of declaration.declarations) {
|
|
40
|
-
tracker.onVariableDeclarator(declarator);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
if (exportsClassComponent(declaration)) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
if (statement.type === utils_1.AST_NODE_TYPES.FunctionDeclaration) {
|
|
49
|
-
tracker.onFunctionDeclaration(statement);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
if (statement.type === utils_1.AST_NODE_TYPES.VariableDeclaration) {
|
|
53
|
-
for (const declarator of statement.declarations) {
|
|
54
|
-
tracker.onVariableDeclarator(declarator);
|
|
55
|
-
}
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (statement.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration) {
|
|
59
|
-
tracker.onExportDefaultDeclaration(statement);
|
|
60
|
-
if (statement.declaration.type === utils_1.AST_NODE_TYPES.FunctionDeclaration) {
|
|
61
|
-
tracker.onFunctionDeclaration(statement.declaration);
|
|
62
|
-
}
|
|
63
|
-
if (exportsClassComponent(statement.declaration)) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return tracker.getExportedComponents().length > 0;
|
|
69
|
-
};
|
|
70
|
-
const exportsClassComponent = (declaration) => {
|
|
71
|
-
if (declaration?.type !== utils_1.AST_NODE_TYPES.ClassDeclaration) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
const name = declaration.id?.name;
|
|
75
|
-
return name === undefined || /^[A-Z]/.test(name);
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* A spec, story, or docs file moves with its component. When the sibling owner
|
|
79
|
-
* exists and does not export a component (a context, a reducer), the companion
|
|
80
|
-
* stays where it is.
|
|
81
|
-
*/
|
|
82
|
-
const REACT_WRAPPER_NAMES = new Set(["memo", "forwardRef"]);
|
|
83
|
-
const isComponentInitializer = (expression) => {
|
|
84
|
-
if (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression)) {
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
return (ts.isCallExpression(expression) &&
|
|
88
|
-
ts.isIdentifier(expression.expression) &&
|
|
89
|
-
REACT_WRAPPER_NAMES.has(expression.expression.text));
|
|
90
|
-
};
|
|
91
|
-
const statementIsExported = (node) => ts.canHaveModifiers(node) &&
|
|
92
|
-
ts.getModifiers(node)?.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword) === true;
|
|
93
|
-
/**
|
|
94
|
-
* Reads a companion's sibling owner. A context or reducer does not count as a component.
|
|
95
|
-
* `export default Foo` and `export { Foo }` count when `Foo` is a top-level PascalCase
|
|
96
|
-
* function, class, or component arrow.
|
|
97
|
-
*/
|
|
98
|
-
const pathExportsComponent = (ownerPath) => {
|
|
99
|
-
let content;
|
|
100
|
-
try {
|
|
101
|
-
content = fs.readFileSync(ownerPath, "utf8");
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
const sourceFile = ts.createSourceFile(ownerPath, content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
|
|
107
|
-
const localComponentNames = new Set();
|
|
108
|
-
const exportedNames = [];
|
|
109
|
-
let exportsComponent = false;
|
|
110
|
-
let defaultExportName;
|
|
111
|
-
let defaultExportIsComponent = false;
|
|
112
|
-
const rememberComponent = (name) => {
|
|
113
|
-
if (!/^[A-Z]/.test(name)) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
localComponentNames.add(name);
|
|
117
|
-
return true;
|
|
118
|
-
};
|
|
119
|
-
for (const statement of sourceFile.statements) {
|
|
120
|
-
if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name !== undefined) {
|
|
121
|
-
if (rememberComponent(statement.name.text) && statementIsExported(statement)) {
|
|
122
|
-
exportsComponent = true;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if (ts.isVariableStatement(statement)) {
|
|
126
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
127
|
-
if (ts.isIdentifier(declaration.name) &&
|
|
128
|
-
declaration.initializer !== undefined &&
|
|
129
|
-
isComponentInitializer(declaration.initializer) &&
|
|
130
|
-
rememberComponent(declaration.name.text) &&
|
|
131
|
-
statementIsExported(statement)) {
|
|
132
|
-
exportsComponent = true;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (ts.isExportAssignment(statement) && !statement.isExportEquals) {
|
|
137
|
-
if (ts.isIdentifier(statement.expression)) {
|
|
138
|
-
defaultExportName = statement.expression.text;
|
|
139
|
-
}
|
|
140
|
-
if (isComponentInitializer(statement.expression)) {
|
|
141
|
-
defaultExportIsComponent = true;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (ts.isExportDeclaration(statement) &&
|
|
145
|
-
statement.exportClause !== undefined &&
|
|
146
|
-
ts.isNamedExports(statement.exportClause)) {
|
|
147
|
-
for (const element of statement.exportClause.elements) {
|
|
148
|
-
const localName = element.propertyName ?? element.name;
|
|
149
|
-
if (ts.isIdentifier(localName)) {
|
|
150
|
-
exportedNames.push(localName.text);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (defaultExportIsComponent || (defaultExportName !== undefined && localComponentNames.has(defaultExportName))) {
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
return exportsComponent || exportedNames.some(name => localComponentNames.has(name));
|
|
159
|
-
};
|
|
160
|
-
const companionOwnerExportsComponent = (filePath) => {
|
|
161
|
-
const fileName = path.basename(filePath);
|
|
162
|
-
if (!COMPANION_FILE_PATTERN.test(fileName)) {
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
const ownerBaseName = fileName.replace(COMPANION_FILE_PATTERN, "");
|
|
166
|
-
const ownerPath = [`${ownerBaseName}.tsx`, `${ownerBaseName}.ts`]
|
|
167
|
-
.map(candidate => path.join(path.dirname(filePath), candidate))
|
|
168
|
-
.find(candidate => fs.existsSync(candidate));
|
|
169
|
-
if (ownerPath === undefined) {
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
return pathExportsComponent(ownerPath);
|
|
173
|
-
};
|
|
174
|
-
exports.requireComponentDirectory = (0, create_rule_1.createRule)({
|
|
175
|
-
name: "require-component-directory",
|
|
176
|
-
meta: {
|
|
177
|
-
type: "suggestion",
|
|
178
|
-
docs: {
|
|
179
|
-
description: "Require one folder per component under `components/`.",
|
|
180
|
-
},
|
|
181
|
-
schema: [],
|
|
182
|
-
messages: {
|
|
183
|
-
flatComponentFile: "Component files must live in their own folder. Move `{{file}}` to `{{suggestedPath}}`.",
|
|
184
|
-
flatComponentSuffixFile: "Suffix files must live inside their component folder. Move `{{file}}` to `{{suggestedPath}}`.",
|
|
185
|
-
suffixComponentNameMismatch: "Suffix file `{{file}}` stays with `{{folderName}}`. Move it to `{{suggestedPath}}`.",
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
defaultOptions: [],
|
|
189
|
-
create(context) {
|
|
190
|
-
return {
|
|
191
|
-
Program(node) {
|
|
192
|
-
const violation = (0, component_directory_structure_utils_1.analyzeComponentFolderStructure)(context.filename);
|
|
193
|
-
if (violation === null) {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const fileName = path.basename(context.filename);
|
|
197
|
-
if (violation.kind === "flatComponentFile" && companionOwnerExportsComponent(context.filename) === false) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
if (violation.kind === "flatComponentFile" &&
|
|
201
|
-
!COMPANION_FILE_PATTERN.test(fileName) &&
|
|
202
|
-
!fileExportsComponent(node)) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
if (violation.kind === "flatComponentSuffixFile") {
|
|
206
|
-
context.report({
|
|
207
|
-
node,
|
|
208
|
-
messageId: "flatComponentSuffixFile",
|
|
209
|
-
data: {
|
|
210
|
-
file: fileName,
|
|
211
|
-
suggestedPath: (0, component_directory_structure_utils_1.getSuggestedComponentFolderPath)(context.filename, violation.componentName),
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (violation.kind === "suffixComponentNameMismatch") {
|
|
217
|
-
context.report({
|
|
218
|
-
node,
|
|
219
|
-
messageId: "suffixComponentNameMismatch",
|
|
220
|
-
data: {
|
|
221
|
-
file: fileName,
|
|
222
|
-
folderName: violation.folderName,
|
|
223
|
-
suggestedPath: (0, component_directory_structure_utils_1.getSuggestedSuffixRolePath)(context.filename, violation.componentName, violation.suffix),
|
|
224
|
-
},
|
|
225
|
-
});
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
context.report({
|
|
229
|
-
node,
|
|
230
|
-
messageId: "flatComponentFile",
|
|
231
|
-
data: {
|
|
232
|
-
file: fileName,
|
|
233
|
-
suggestedPath: (0, component_directory_structure_utils_1.getSuggestedComponentFolderPath)(context.filename, violation.componentName),
|
|
234
|
-
},
|
|
235
|
-
});
|
|
236
|
-
},
|
|
237
|
-
};
|
|
238
|
-
},
|
|
239
|
-
});
|
|
240
|
-
//# sourceMappingURL=require-component-directory.js.map
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
type ComponentFolderViolation = {
|
|
2
|
-
readonly kind: "flatComponentSuffixFile";
|
|
3
|
-
readonly componentName: string;
|
|
4
|
-
readonly suffix: string;
|
|
5
|
-
} | {
|
|
6
|
-
readonly kind: "suffixComponentNameMismatch";
|
|
7
|
-
readonly componentName: string;
|
|
8
|
-
readonly folderName: string;
|
|
9
|
-
readonly suffix: string;
|
|
10
|
-
} | {
|
|
11
|
-
readonly kind: "flatComponentFile";
|
|
12
|
-
readonly componentName: string;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Returns a folder-structure violation when `filePath` is a direct child of a
|
|
16
|
-
* `components/` directory (including scoped `components/` folders), or
|
|
17
|
-
* when a suffix file inside a component folder does not match that folder name,
|
|
18
|
-
* or `null` when the path is allowed.
|
|
19
|
-
*/
|
|
20
|
-
export declare const analyzeComponentFolderStructure: (filePath: string) => ComponentFolderViolation | null;
|
|
21
|
-
/**
|
|
22
|
-
* `components/Button.tsx` → `components/Button/Button.tsx`, relative to the
|
|
23
|
-
* `components/` directory's parent. Every violation this rule reports lives
|
|
24
|
-
* either directly under `components/` or one level below it, so the target is
|
|
25
|
-
* the same in both cases.
|
|
26
|
-
*/
|
|
27
|
-
export declare const getSuggestedComponentFolderPath: (filePath: string, componentName: string) => string;
|
|
28
|
-
/**
|
|
29
|
-
* A suffix file inside `components/<Parent>/` that does not match `<Parent>`
|
|
30
|
-
* stays with that parent. Suggest `components/<Parent>/<role>/<name>/<name>.ts`
|
|
31
|
-
* rather than a new component folder named after the suffix prefix.
|
|
32
|
-
*/
|
|
33
|
-
export declare const getSuggestedSuffixRolePath: (filePath: string, componentName: string, suffix: string) => string;
|
|
34
|
-
export {};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSuggestedSuffixRolePath = exports.getSuggestedComponentFolderPath = exports.analyzeComponentFolderStructure = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const source_tree_utils_1 = require("../../../../utils/source-tree-utils/source-tree-utils");
|
|
7
|
-
const COMPONENTS_DIRECTORY_NAME = "components";
|
|
8
|
-
const MODULE_DIRECTORY_NAMES = new Set([COMPONENTS_DIRECTORY_NAME, "pages"]);
|
|
9
|
-
const FLAT_COMPONENT_SUFFIX_PATTERN = /\.(utils|types|constants|helpers)$/i;
|
|
10
|
-
const ROLE_DIRECTORY_BY_SUFFIX = {
|
|
11
|
-
utils: "utils",
|
|
12
|
-
helpers: "utils",
|
|
13
|
-
constants: "constants",
|
|
14
|
-
types: "types",
|
|
15
|
-
};
|
|
16
|
-
const PASCAL_CASE_FILE_PATTERN = /^([A-Z][a-zA-Z0-9]*)(?:\.(spec|stories|docs|variants|module))?\.(tsx|ts)$/;
|
|
17
|
-
const parseSuffixFileName = (baseName) => {
|
|
18
|
-
const suffixMatch = FLAT_COMPONENT_SUFFIX_PATTERN.exec(baseName);
|
|
19
|
-
if (suffixMatch === null) {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
const componentName = baseName.slice(0, -suffixMatch[0].length);
|
|
23
|
-
const suffix = suffixMatch[1];
|
|
24
|
-
if (suffix === undefined || !source_tree_utils_1.PASCAL_CASE_PATTERN.test(componentName)) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
return { componentName, suffix };
|
|
28
|
-
};
|
|
29
|
-
/** `components/<PascalCase>/<file>` or `pages/<PascalCase>/<file>`. */
|
|
30
|
-
const getEnclosingModule = (normalizedPath) => {
|
|
31
|
-
const parentDirectory = path.dirname(normalizedPath);
|
|
32
|
-
const folderName = path.basename(parentDirectory);
|
|
33
|
-
const moduleDirectoryName = path.basename(path.dirname(parentDirectory));
|
|
34
|
-
if (!MODULE_DIRECTORY_NAMES.has(moduleDirectoryName) || !source_tree_utils_1.PASCAL_CASE_PATTERN.test(folderName)) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
return { folderName, moduleDirectoryName };
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Returns a folder-structure violation when `filePath` is a direct child of a
|
|
41
|
-
* `components/` directory (including scoped `components/` folders), or
|
|
42
|
-
* when a suffix file inside a component folder does not match that folder name,
|
|
43
|
-
* or `null` when the path is allowed.
|
|
44
|
-
*/
|
|
45
|
-
const analyzeComponentFolderStructure = (filePath) => {
|
|
46
|
-
const normalizedPath = path.normalize(filePath);
|
|
47
|
-
const parentDirectory = path.dirname(normalizedPath);
|
|
48
|
-
const parentDirectoryName = path.basename(parentDirectory);
|
|
49
|
-
const fileName = path.basename(normalizedPath);
|
|
50
|
-
const baseName = (0, source_tree_utils_1.getBaseName)(fileName);
|
|
51
|
-
if (baseName === "index") {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
const suffixFileName = parseSuffixFileName(baseName);
|
|
55
|
-
const enclosingModule = getEnclosingModule(normalizedPath);
|
|
56
|
-
if (suffixFileName !== null) {
|
|
57
|
-
if (parentDirectoryName === COMPONENTS_DIRECTORY_NAME) {
|
|
58
|
-
return {
|
|
59
|
-
kind: "flatComponentSuffixFile",
|
|
60
|
-
componentName: suffixFileName.componentName,
|
|
61
|
-
suffix: suffixFileName.suffix,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
if (enclosingModule !== null && suffixFileName.componentName !== enclosingModule.folderName) {
|
|
65
|
-
return {
|
|
66
|
-
kind: "suffixComponentNameMismatch",
|
|
67
|
-
componentName: suffixFileName.componentName,
|
|
68
|
-
folderName: enclosingModule.folderName,
|
|
69
|
-
suffix: suffixFileName.suffix,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
if (enclosingModule !== null) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
if (parentDirectoryName !== COMPONENTS_DIRECTORY_NAME) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
const pascalCaseMatch = PASCAL_CASE_FILE_PATTERN.exec(fileName);
|
|
81
|
-
const componentName = pascalCaseMatch?.[1];
|
|
82
|
-
if (componentName !== undefined) {
|
|
83
|
-
return {
|
|
84
|
-
kind: "flatComponentFile",
|
|
85
|
-
componentName,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
};
|
|
90
|
-
exports.analyzeComponentFolderStructure = analyzeComponentFolderStructure;
|
|
91
|
-
/**
|
|
92
|
-
* `components/Button.tsx` → `components/Button/Button.tsx`, relative to the
|
|
93
|
-
* `components/` directory's parent. Every violation this rule reports lives
|
|
94
|
-
* either directly under `components/` or one level below it, so the target is
|
|
95
|
-
* the same in both cases.
|
|
96
|
-
*/
|
|
97
|
-
const getSuggestedComponentFolderPath = (filePath, componentName) => path.posix.join(COMPONENTS_DIRECTORY_NAME, componentName, path.basename(path.normalize(filePath)));
|
|
98
|
-
exports.getSuggestedComponentFolderPath = getSuggestedComponentFolderPath;
|
|
99
|
-
/**
|
|
100
|
-
* A suffix file inside `components/<Parent>/` that does not match `<Parent>`
|
|
101
|
-
* stays with that parent. Suggest `components/<Parent>/<role>/<name>/<name>.ts`
|
|
102
|
-
* rather than a new component folder named after the suffix prefix.
|
|
103
|
-
*/
|
|
104
|
-
const getSuggestedSuffixRolePath = (filePath, componentName, suffix) => {
|
|
105
|
-
const normalizedPath = path.normalize(filePath);
|
|
106
|
-
const enclosingModule = getEnclosingModule(normalizedPath);
|
|
107
|
-
const moduleDirectoryName = enclosingModule?.moduleDirectoryName ?? COMPONENTS_DIRECTORY_NAME;
|
|
108
|
-
const folderName = enclosingModule?.folderName ?? path.basename(path.dirname(normalizedPath));
|
|
109
|
-
const roleDirectory = ROLE_DIRECTORY_BY_SUFFIX[suffix] ?? suffix;
|
|
110
|
-
const roleName = `${componentName.charAt(0).toLowerCase()}${componentName.slice(1)}`;
|
|
111
|
-
return path.posix.join(moduleDirectoryName, folderName, roleDirectory, roleName, `${roleName}.ts`);
|
|
112
|
-
};
|
|
113
|
-
exports.getSuggestedSuffixRolePath = getSuggestedSuffixRolePath;
|
|
114
|
-
//# sourceMappingURL=component-directory-structure-utils.js.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: require-hook-util-directory
|
|
3
|
-
*
|
|
4
|
-
* Each hook or util source file must live in its own folder under `hooks/` or
|
|
5
|
-
* `utils/` so specs can colocate (e.g. `hooks/useFoo/useFoo.ts`).
|
|
6
|
-
*/
|
|
7
|
-
export declare const requireHookUtilDirectory: import("@typescript-eslint/utils/ts-eslint").RuleModule<"flatHookOrUtilFile", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
8
|
-
name: string;
|
|
9
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* ESLint rule: require-hook-util-directory
|
|
4
|
-
*
|
|
5
|
-
* Each hook or util source file must live in its own folder under `hooks/` or
|
|
6
|
-
* `utils/` so specs can colocate (e.g. `hooks/useFoo/useFoo.ts`).
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.requireHookUtilDirectory = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
11
|
-
const path = tslib_1.__importStar(require("path"));
|
|
12
|
-
const create_rule_1 = require("../../utils/create-rule/create-rule");
|
|
13
|
-
const hook_util_directory_structure_utils_1 = require("./utils/hook-util-directory-structure-utils/hook-util-directory-structure-utils");
|
|
14
|
-
exports.requireHookUtilDirectory = (0, create_rule_1.createRule)({
|
|
15
|
-
name: "require-hook-util-directory",
|
|
16
|
-
meta: {
|
|
17
|
-
type: "suggestion",
|
|
18
|
-
docs: {
|
|
19
|
-
description: "Require hook and util files directly under `hooks/` or `utils/` to live in their own folder, one export per folder.",
|
|
20
|
-
},
|
|
21
|
-
schema: [],
|
|
22
|
-
messages: {
|
|
23
|
-
flatHookOrUtilFile: "Hook and util files must live in their own folder. Move `{{file}}` to `{{suggestedPath}}` and colocate `{{specFile}}` there.",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
defaultOptions: [],
|
|
27
|
-
create(context) {
|
|
28
|
-
return {
|
|
29
|
-
Program(node) {
|
|
30
|
-
const violation = (0, hook_util_directory_structure_utils_1.analyzeHookUtilFolderStructure)(context.filename);
|
|
31
|
-
if (violation === null) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const fileName = path.basename(context.filename);
|
|
35
|
-
const specExtension = path.extname(fileName) === ".tsx" ? ".tsx" : ".ts";
|
|
36
|
-
const suggestedPath = (0, hook_util_directory_structure_utils_1.getSuggestedHookUtilFolderPath)(context.filename);
|
|
37
|
-
context.report({
|
|
38
|
-
node,
|
|
39
|
-
messageId: "flatHookOrUtilFile",
|
|
40
|
-
data: {
|
|
41
|
-
file: fileName,
|
|
42
|
-
suggestedPath,
|
|
43
|
-
specFile: `${violation.baseName}.spec${specExtension}`,
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
//# sourceMappingURL=require-hook-util-directory.js.map
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type HookUtilFolderViolation = {
|
|
2
|
-
readonly kind: "flatHookOrUtilFile";
|
|
3
|
-
readonly roleFolder: "hooks" | "utils";
|
|
4
|
-
readonly baseName: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* Returns a violation when a hook or util source file sits directly under
|
|
8
|
-
* `hooks/` or `utils/` instead of its own subfolder.
|
|
9
|
-
*/
|
|
10
|
-
export declare const analyzeHookUtilFolderStructure: (filePath: string) => HookUtilFolderViolation | null;
|
|
11
|
-
/**
|
|
12
|
-
* Suggested path relative to the parent of `hooks/` or `utils/`.
|
|
13
|
-
* `hooks/useFoo.ts` → `hooks/useFoo/useFoo.ts`.
|
|
14
|
-
*/
|
|
15
|
-
export declare const getSuggestedHookUtilFolderPath: (filePath: string) => string;
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSuggestedHookUtilFolderPath = exports.analyzeHookUtilFolderStructure = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const source_tree_utils_1 = require("../../../../utils/source-tree-utils/source-tree-utils");
|
|
7
|
-
const isUnderMocksDirectory = (normalizedPath) => normalizedPath.split(path.sep).includes("__mocks__");
|
|
8
|
-
/**
|
|
9
|
-
* Returns a violation when a hook or util source file sits directly under
|
|
10
|
-
* `hooks/` or `utils/` instead of its own subfolder.
|
|
11
|
-
*/
|
|
12
|
-
const analyzeHookUtilFolderStructure = (filePath) => {
|
|
13
|
-
const normalizedPath = path.normalize(filePath);
|
|
14
|
-
if (!(0, source_tree_utils_1.isSourceFile)(normalizedPath) || isUnderMocksDirectory(normalizedPath)) {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
const baseName = (0, source_tree_utils_1.getBaseName)(path.basename(normalizedPath));
|
|
18
|
-
const parentDirectoryName = path.basename(path.dirname(normalizedPath));
|
|
19
|
-
if (parentDirectoryName !== "hooks" && parentDirectoryName !== "utils") {
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
if (baseName === "index") {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
kind: "flatHookOrUtilFile",
|
|
27
|
-
roleFolder: parentDirectoryName === "hooks" ? "hooks" : "utils",
|
|
28
|
-
baseName,
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
exports.analyzeHookUtilFolderStructure = analyzeHookUtilFolderStructure;
|
|
32
|
-
/**
|
|
33
|
-
* Suggested path relative to the parent of `hooks/` or `utils/`.
|
|
34
|
-
* `hooks/useFoo.ts` → `hooks/useFoo/useFoo.ts`.
|
|
35
|
-
*/
|
|
36
|
-
const getSuggestedHookUtilFolderPath = (filePath) => {
|
|
37
|
-
const normalizedPath = path.normalize(filePath);
|
|
38
|
-
const fileName = path.basename(normalizedPath);
|
|
39
|
-
const baseName = (0, source_tree_utils_1.getBaseName)(fileName);
|
|
40
|
-
const parentDirectoryName = path.basename(path.dirname(normalizedPath));
|
|
41
|
-
return path.posix.join(parentDirectoryName, baseName, fileName);
|
|
42
|
-
};
|
|
43
|
-
exports.getSuggestedHookUtilFolderPath = getSuggestedHookUtilFolderPath;
|
|
44
|
-
//# sourceMappingURL=hook-util-directory-structure-utils.js.map
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requireIrisAppAiNavigation = void 0;
|
|
4
|
-
const utils_1 = require("@typescript-eslint/utils");
|
|
5
|
-
const createRule = utils_1.ESLintUtils.RuleCreator(name => `https://github.com/trackunit/manager/blob/master/libs/eslint/plugin-trackunit/src/lib/rules/${name}/README.md`);
|
|
6
|
-
/**
|
|
7
|
-
* Mirrors `aiNavigableExtensionTypes` in `@trackunit/iris-app-api`. The plugin is published
|
|
8
|
-
* without depending on the Iris SDK, so the list is kept here.
|
|
9
|
-
*/
|
|
10
|
-
const AI_NAVIGABLE_EXTENSION_TYPES = new Set([
|
|
11
|
-
"FLEET_EXTENSION",
|
|
12
|
-
"ADMIN_EXTENSION",
|
|
13
|
-
"IRIS_APP_SETTINGS_EXTENSION",
|
|
14
|
-
"ASSET_HOME_EXTENSION",
|
|
15
|
-
"SITE_HOME_EXTENSION",
|
|
16
|
-
"CUSTOMER_HOME_EXTENSION",
|
|
17
|
-
"ASSET_EVENTS_ACTIONS_EXTENSION",
|
|
18
|
-
]);
|
|
19
|
-
const propertyName = (property) => {
|
|
20
|
-
if (property.computed) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
if (property.key.type === utils_1.AST_NODE_TYPES.Identifier) {
|
|
24
|
-
return property.key.name;
|
|
25
|
-
}
|
|
26
|
-
return typeof property.key.value === "string" ? property.key.value : undefined;
|
|
27
|
-
};
|
|
28
|
-
const findProperty = (node, name) => node.properties.find((property) => property.type === utils_1.AST_NODE_TYPES.Property && propertyName(property) === name);
|
|
29
|
-
exports.requireIrisAppAiNavigation = createRule({
|
|
30
|
-
name: "require-iris-app-ai-navigation",
|
|
31
|
-
meta: {
|
|
32
|
-
type: "problem",
|
|
33
|
-
docs: {
|
|
34
|
-
description: "Require Iris extension manifests with navigable pages to declare aiNavigation",
|
|
35
|
-
},
|
|
36
|
-
messages: {
|
|
37
|
-
missingAiNavigation: "{{type}} manifests must declare 'aiNavigation' so the Manager AI assistant can find and open their pages. Describe each page in its route's staticData and read them with extractAiNavigationFromTanstackRouter, or list each page's path, title, and description.",
|
|
38
|
-
},
|
|
39
|
-
schema: [],
|
|
40
|
-
},
|
|
41
|
-
defaultOptions: [],
|
|
42
|
-
create(context) {
|
|
43
|
-
return {
|
|
44
|
-
ObjectExpression(node) {
|
|
45
|
-
const typeProperty = findProperty(node, "type");
|
|
46
|
-
const type = typeProperty?.value.type === utils_1.AST_NODE_TYPES.Literal && typeof typeProperty.value.value === "string"
|
|
47
|
-
? typeProperty.value.value
|
|
48
|
-
: undefined;
|
|
49
|
-
if (typeProperty === undefined || type === undefined || !AI_NAVIGABLE_EXTENSION_TYPES.has(type)) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const hasSpread = node.properties.some(property => property.type === utils_1.AST_NODE_TYPES.SpreadElement);
|
|
53
|
-
if (hasSpread || findProperty(node, "aiNavigation") !== undefined) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
context.report({ node: typeProperty, messageId: "missingAiNavigation", data: { type } });
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
//# sourceMappingURL=require-iris-app-ai-navigation.js.map
|
package/src/lib/rules/require-nested-components-directory/require-nested-components-directory.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ESLint rule: require-nested-components-directory
|
|
3
|
-
*
|
|
4
|
-
* When a component module owns a child component, that child lives under
|
|
5
|
-
* `<Parent>/components/`. Contexts, reducers, and route components are excluded.
|
|
6
|
-
*/
|
|
7
|
-
export declare const requireNestedComponentsDirectory: import("@typescript-eslint/utils/ts-eslint").RuleModule<"nestedComponentsNotInSubfolder", [], unknown, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
8
|
-
name: string;
|
|
9
|
-
};
|
package/src/lib/rules/require-nested-components-directory/require-nested-components-directory.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* ESLint rule: require-nested-components-directory
|
|
4
|
-
*
|
|
5
|
-
* When a component module owns a child component, that child lives under
|
|
6
|
-
* `<Parent>/components/`. Contexts, reducers, and route components are excluded.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.requireNestedComponentsDirectory = void 0;
|
|
10
|
-
const create_rule_1 = require("../../utils/create-rule/create-rule");
|
|
11
|
-
const nested_component_directory_utils_1 = require("./utils/nested-component-directory-utils/nested-component-directory-utils");
|
|
12
|
-
exports.requireNestedComponentsDirectory = (0, create_rule_1.createRule)({
|
|
13
|
-
name: "require-nested-components-directory",
|
|
14
|
-
meta: {
|
|
15
|
-
type: "suggestion",
|
|
16
|
-
docs: {
|
|
17
|
-
description: "Require child components under `<Parent>/components/` instead of beside the parent.",
|
|
18
|
-
},
|
|
19
|
-
schema: [],
|
|
20
|
-
messages: {
|
|
21
|
-
nestedComponentsNotInSubfolder: "Move child components into `components/`. In `{{parentComponentName}}/`, move {{childComponentNames}} under `components/`.",
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
defaultOptions: [],
|
|
25
|
-
create(context) {
|
|
26
|
-
return {
|
|
27
|
-
Program(node) {
|
|
28
|
-
const violation = (0, nested_component_directory_utils_1.analyzeNestedComponentsFolderStructure)(context.filename);
|
|
29
|
-
if (violation === null) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
context.report({
|
|
33
|
-
node,
|
|
34
|
-
messageId: "nestedComponentsNotInSubfolder",
|
|
35
|
-
data: {
|
|
36
|
-
parentComponentName: violation.parentComponentName,
|
|
37
|
-
childComponentNames: violation.childComponentNames.join(", "),
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
//# sourceMappingURL=require-nested-components-directory.js.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
type NestedComponentsFolderViolation = {
|
|
2
|
-
readonly kind: "nestedComponentsNotInSubfolder";
|
|
3
|
-
readonly parentComponentName: string;
|
|
4
|
-
readonly childComponentNames: ReadonlyArray<string>;
|
|
5
|
-
};
|
|
6
|
-
export declare const isParentComponentModule: (parentDirectory: string) => boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Returns a violation when `filePath` belongs to a component module that keeps
|
|
9
|
-
* a child component beside the parent instead of under `components/`.
|
|
10
|
-
* A sibling counts only when it exports a component. Compound parts, whose names
|
|
11
|
-
* extend the parent, stay beside the parent. Flat files that extend a plural
|
|
12
|
-
* parent's singular stem stay too. A child folder is not exempted by that stem.
|
|
13
|
-
* Route components are not children.
|
|
14
|
-
*/
|
|
15
|
-
export declare const analyzeNestedComponentsFolderStructure: (filePath: string) => NestedComponentsFolderViolation | null;
|
|
16
|
-
export declare const getSuggestedNestedComponentsPath: (parentDirectory: string, childComponentName: string) => string;
|
|
17
|
-
export {};
|