@trackunit/eslint-plugin-trackunit 0.7.20-alpha-563d99d17d6.0 → 0.7.20

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 (42) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/README.md +13 -0
  3. package/package.json +2 -2
  4. package/src/index.d.ts +1 -1
  5. package/src/index.js +2 -1
  6. package/src/lib/config/index.d.ts +32 -0
  7. package/src/lib/config/plugins.d.ts +26 -0
  8. package/src/lib/config/plugins.js +19 -1
  9. package/src/lib/config/presets/base.d.ts +9 -0
  10. package/src/lib/config/presets/react.d.ts +23 -0
  11. package/src/lib/config/presets/react.js +4 -0
  12. package/src/lib/rules/no-unused-translation-key/used-strings.js +1 -1
  13. package/src/lib/{utils → rules/no-unused-translation-key/utils/program-utils}/program-utils.js +1 -1
  14. package/src/lib/rules/require-component-directory/require-component-directory.d.ts +16 -0
  15. package/src/lib/rules/require-component-directory/require-component-directory.js +240 -0
  16. package/src/lib/rules/require-component-directory/utils/component-directory-structure-utils/component-directory-structure-utils.d.ts +34 -0
  17. package/src/lib/rules/require-component-directory/utils/component-directory-structure-utils/component-directory-structure-utils.js +114 -0
  18. package/src/lib/rules/require-hook-util-directory/require-hook-util-directory.d.ts +9 -0
  19. package/src/lib/rules/require-hook-util-directory/require-hook-util-directory.js +50 -0
  20. package/src/lib/rules/require-hook-util-directory/utils/hook-util-directory-structure-utils/hook-util-directory-structure-utils.d.ts +15 -0
  21. package/src/lib/rules/require-hook-util-directory/utils/hook-util-directory-structure-utils/hook-util-directory-structure-utils.js +44 -0
  22. package/src/lib/rules/require-iris-app-ai-navigation/require-iris-app-ai-navigation.d.ts +4 -0
  23. package/src/lib/rules/require-iris-app-ai-navigation/require-iris-app-ai-navigation.js +61 -0
  24. package/src/lib/rules/require-nested-components-directory/require-nested-components-directory.d.ts +9 -0
  25. package/src/lib/rules/require-nested-components-directory/require-nested-components-directory.js +44 -0
  26. package/src/lib/rules/require-nested-components-directory/utils/nested-component-directory-utils/nested-component-directory-utils.d.ts +17 -0
  27. package/src/lib/rules/require-nested-components-directory/utils/nested-component-directory-utils/nested-component-directory-utils.js +206 -0
  28. package/src/lib/rules/require-nested-components-privacy/require-nested-components-privacy.d.ts +9 -0
  29. package/src/lib/rules/require-nested-components-privacy/require-nested-components-privacy.js +63 -0
  30. package/src/lib/rules/require-nested-components-privacy/utils/nested-component-privacy-utils/nested-component-privacy-utils.d.ts +14 -0
  31. package/src/lib/rules/require-nested-components-privacy/utils/nested-component-privacy-utils/nested-component-privacy-utils.js +62 -0
  32. package/src/lib/rules/require-page-directory/require-page-directory.d.ts +8 -0
  33. package/src/lib/rules/require-page-directory/require-page-directory.js +44 -0
  34. package/src/lib/rules/require-page-directory/utils/page-directory-structure-utils/page-directory-structure-utils.d.ts +18 -0
  35. package/src/lib/rules/require-page-directory/utils/page-directory-structure-utils/page-directory-structure-utils.js +159 -0
  36. package/src/lib/rules-map.d.ts +3 -0
  37. package/src/lib/rules-map.js +2 -0
  38. package/src/lib/utils/create-rule/create-rule.d.ts +7 -0
  39. package/src/lib/utils/create-rule/create-rule.js +9 -0
  40. package/src/lib/utils/source-tree-utils/source-tree-utils.d.ts +43 -0
  41. package/src/lib/utils/source-tree-utils/source-tree-utils.js +136 -0
  42. /package/src/lib/{utils → rules/no-unused-translation-key/utils/program-utils}/program-utils.d.ts +0 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Shared helpers for folder-structure rules that need to look beyond the file
3
+ * ESLint is currently linting: walking a library's `src/` tree and resolving
4
+ * relative imports.
5
+ *
6
+ * ## Main Functions
7
+ * - `getSrcRoot()` - Locate the `src/` directory that owns a file
8
+ * - `walkSourceFiles()` - List every non-spec/story source file under a directory
9
+ * - `resolveRelativeImportPath()` - Resolve `./foo` the way TypeScript would (`.ts`, `.tsx`, `index.*`)
10
+ * - `createSrcRootCache()` - Memoise an expensive per-`src/`-root computation
11
+ * - `clearSourceTreeCaches()` - Reset every cache created here. Useful for testing.
12
+ */
13
+ export declare const SOURCE_FILE_EXTENSIONS: readonly [".ts", ".tsx", ".js", ".jsx"];
14
+ export declare const PASCAL_CASE_PATTERN: RegExp;
15
+ export declare const isSourceFile: (filePath: string) => boolean;
16
+ /** `useFoo.spec.tsx` → `useFoo.spec`; `Button.tsx` → `Button`. */
17
+ export declare const getBaseName: (fileName: string) => string;
18
+ /** The innermost `…/src` directory containing `filePath`, or `null` when there is none. */
19
+ export declare const getSrcRoot: (filePath: string) => string | null;
20
+ export declare const readSourceFile: (filePath: string) => string | null;
21
+ export declare const walkSourceFiles: (directory: string) => ReadonlyArray<string>;
22
+ /**
23
+ * Resolve a relative import the way TypeScript does: exact path, then each
24
+ * source extension, then a directory `index.*`. Non-relative specifiers
25
+ * (packages, path aliases) resolve to `null`.
26
+ */
27
+ export declare const resolveRelativeImportPath: (importerFilePath: string, importSource: string) => string | null;
28
+ type SrcRootCache<TValue> = {
29
+ readonly get: (srcRoot: string) => TValue;
30
+ };
31
+ /**
32
+ * Memoise `compute` per `src/` root for the lifetime of the ESLint process.
33
+ *
34
+ * Rules that inspect the whole tree would otherwise redo the same walk for every
35
+ * file they lint. The trade-off is that a long-lived editor ESLint server sees a
36
+ * snapshot from its first lint of each library until it is restarted.
37
+ */
38
+ export declare const createSrcRootCache: <TValue>(compute: (srcRoot: string) => TValue) => SrcRootCache<TValue>;
39
+ /**
40
+ * Clear every cache created with `createSrcRootCache`. Useful for testing.
41
+ */
42
+ export declare const clearSourceTreeCaches: () => void;
43
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clearSourceTreeCaches = exports.createSrcRootCache = exports.resolveRelativeImportPath = exports.walkSourceFiles = exports.readSourceFile = exports.getSrcRoot = exports.getBaseName = exports.isSourceFile = exports.PASCAL_CASE_PATTERN = exports.SOURCE_FILE_EXTENSIONS = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ /**
8
+ * Shared helpers for folder-structure rules that need to look beyond the file
9
+ * ESLint is currently linting: walking a library's `src/` tree and resolving
10
+ * relative imports.
11
+ *
12
+ * ## Main Functions
13
+ * - `getSrcRoot()` - Locate the `src/` directory that owns a file
14
+ * - `walkSourceFiles()` - List every non-spec/story source file under a directory
15
+ * - `resolveRelativeImportPath()` - Resolve `./foo` the way TypeScript would (`.ts`, `.tsx`, `index.*`)
16
+ * - `createSrcRootCache()` - Memoise an expensive per-`src/`-root computation
17
+ * - `clearSourceTreeCaches()` - Reset every cache created here. Useful for testing.
18
+ */
19
+ exports.SOURCE_FILE_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"];
20
+ exports.PASCAL_CASE_PATTERN = /^[A-Z][a-zA-Z0-9]*$/;
21
+ const TEST_OR_STORY_FILE_PATTERN = /\.(spec|stories)\.(tsx?|jsx?)$/;
22
+ const IGNORED_DIRECTORY_NAMES = new Set(["node_modules", "dist", "generated"]);
23
+ const isSourceExtension = (extension) => exports.SOURCE_FILE_EXTENSIONS.some(sourceExtension => sourceExtension === extension);
24
+ const isSourceFile = (filePath) => isSourceExtension(path.extname(filePath)) && !TEST_OR_STORY_FILE_PATTERN.test(filePath);
25
+ exports.isSourceFile = isSourceFile;
26
+ /** `useFoo.spec.tsx` → `useFoo.spec`; `Button.tsx` → `Button`. */
27
+ const getBaseName = (fileName) => fileName.slice(0, -path.extname(fileName).length);
28
+ exports.getBaseName = getBaseName;
29
+ /** The innermost `…/src` directory containing `filePath`, or `null` when there is none. */
30
+ const getSrcRoot = (filePath) => {
31
+ const parts = path.normalize(filePath).split(path.sep);
32
+ const srcIndex = parts.lastIndexOf("src");
33
+ if (srcIndex === -1) {
34
+ return null;
35
+ }
36
+ return parts.slice(0, srcIndex + 1).join(path.sep);
37
+ };
38
+ exports.getSrcRoot = getSrcRoot;
39
+ const readSourceFile = (filePath) => {
40
+ try {
41
+ return fs.readFileSync(filePath, "utf8");
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ };
47
+ exports.readSourceFile = readSourceFile;
48
+ const walkSourceFiles = (directory) => {
49
+ const files = [];
50
+ const visit = (currentDirectory) => {
51
+ let entries;
52
+ try {
53
+ entries = fs.readdirSync(currentDirectory, { withFileTypes: true });
54
+ }
55
+ catch {
56
+ return;
57
+ }
58
+ for (const entry of entries) {
59
+ const entryPath = path.join(currentDirectory, entry.name);
60
+ if (entry.isDirectory()) {
61
+ if (!IGNORED_DIRECTORY_NAMES.has(entry.name)) {
62
+ visit(entryPath);
63
+ }
64
+ continue;
65
+ }
66
+ if (entry.isFile() && (0, exports.isSourceFile)(entryPath)) {
67
+ files.push(entryPath);
68
+ }
69
+ }
70
+ };
71
+ visit(directory);
72
+ return files;
73
+ };
74
+ exports.walkSourceFiles = walkSourceFiles;
75
+ /**
76
+ * Resolve a relative import the way TypeScript does: exact path, then each
77
+ * source extension, then a directory `index.*`. Non-relative specifiers
78
+ * (packages, path aliases) resolve to `null`.
79
+ */
80
+ const resolveRelativeImportPath = (importerFilePath, importSource) => {
81
+ if (!importSource.startsWith(".")) {
82
+ return null;
83
+ }
84
+ const resolvedBase = path.normalize(path.resolve(path.dirname(importerFilePath), importSource));
85
+ const candidates = [
86
+ resolvedBase,
87
+ ...exports.SOURCE_FILE_EXTENSIONS.map(extension => `${resolvedBase}${extension}`),
88
+ ...exports.SOURCE_FILE_EXTENSIONS.map(extension => path.join(resolvedBase, `index${extension}`)),
89
+ ];
90
+ for (const candidate of candidates) {
91
+ try {
92
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
93
+ return path.normalize(candidate);
94
+ }
95
+ }
96
+ catch {
97
+ continue;
98
+ }
99
+ }
100
+ return null;
101
+ };
102
+ exports.resolveRelativeImportPath = resolveRelativeImportPath;
103
+ const cacheResets = [];
104
+ /**
105
+ * Memoise `compute` per `src/` root for the lifetime of the ESLint process.
106
+ *
107
+ * Rules that inspect the whole tree would otherwise redo the same walk for every
108
+ * file they lint. The trade-off is that a long-lived editor ESLint server sees a
109
+ * snapshot from its first lint of each library until it is restarted.
110
+ */
111
+ const createSrcRootCache = (compute) => {
112
+ const cache = new Map();
113
+ cacheResets.push(() => cache.clear());
114
+ return {
115
+ get: srcRoot => {
116
+ const cached = cache.get(srcRoot);
117
+ if (cached !== undefined) {
118
+ return cached;
119
+ }
120
+ const computed = compute(srcRoot);
121
+ cache.set(srcRoot, computed);
122
+ return computed;
123
+ },
124
+ };
125
+ };
126
+ exports.createSrcRootCache = createSrcRootCache;
127
+ /**
128
+ * Clear every cache created with `createSrcRootCache`. Useful for testing.
129
+ */
130
+ const clearSourceTreeCaches = () => {
131
+ for (const reset of cacheResets) {
132
+ reset();
133
+ }
134
+ };
135
+ exports.clearSourceTreeCaches = clearSourceTreeCaches;
136
+ //# sourceMappingURL=source-tree-utils.js.map