@dloizides/frontend-devtools 1.0.1 → 1.0.2
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/dist/eslint/index.d.mts +77 -0
- package/dist/eslint/index.d.ts +77 -0
- package/dist/eslint/index.js +2000 -0
- package/dist/eslint/index.js.map +1 -0
- package/dist/eslint/index.mjs +1990 -0
- package/dist/eslint/index.mjs.map +1 -0
- package/dist/index.d.mts +71 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +2029 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2017 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +6 -1
- package/.eslintrc.js +0 -34
- package/jest.config.js +0 -24
- package/publish.ps1 +0 -107
- package/src/eslint/index.ts +0 -16
- package/src/eslint/legacy.ts +0 -44
- package/src/eslint/plugin.test.ts +0 -60
- package/src/eslint/plugin.ts +0 -87
- package/src/eslint/rules.behaviour.test.ts +0 -86
- package/src/eslint/rules.d.ts +0 -16
- package/src/eslint/types.ts +0 -27
- package/src/i18n/initI18n.test.ts +0 -101
- package/src/i18n/initI18n.ts +0 -109
- package/src/index.ts +0 -31
- package/src/rules/enforce-function-style.js +0 -278
- package/src/rules/enforce-module-structure.js +0 -323
- package/src/rules/enforce-route-preload.js +0 -288
- package/src/rules/enforce-test-colocation.js +0 -82
- package/src/rules/enum-file-isolation.js +0 -149
- package/src/rules/i18n-interpolation.js +0 -185
- package/src/rules/i18n-param-names.js +0 -119
- package/src/rules/no-barrel-companion-file.js +0 -142
- package/src/rules/no-duplicate-nav-prefix.js +0 -107
- package/src/rules/no-duplicate-shared-patterns.js +0 -166
- package/src/rules/no-generated-models-barrel-value-import.js +0 -70
- package/src/rules/no-null-check.js +0 -171
- package/src/rules/no-optional-undefined.js +0 -99
- package/src/rules/no-product-imports-in-shared.js +0 -164
- package/src/rules/prefer-const-enum.js +0 -127
- package/src/rules/require-stable-hook-args.js +0 -372
- package/src/rules/smart-max-lines.js +0 -344
- package/tsconfig.json +0 -25
- package/tsconfig.test.json +0 -11
- package/tsup.config.ts +0 -14
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom ESLint Plugin: i18n Parameter Name Enforcement
|
|
3
|
-
*
|
|
4
|
-
* Ensures that t() calls from react-i18next use standardized
|
|
5
|
-
* interpolation parameter names: p1, p2, p3. This complements the
|
|
6
|
-
* i18n-interpolation rule (which enforces {{p1}}/{{p2}}/{{p3}} in
|
|
7
|
-
* translation JSON files) by checking the call sites in TypeScript/TSX.
|
|
8
|
-
*
|
|
9
|
-
* DETECTS:
|
|
10
|
-
* t('key', { count }) — non-standard param name "count"
|
|
11
|
-
* t('key', { message: err }) — non-standard param name "message"
|
|
12
|
-
*
|
|
13
|
-
* ALLOWED:
|
|
14
|
-
* FM('key', value) — FM() enforces positional params by design
|
|
15
|
-
* t('key', { p1: value }) — standard param name
|
|
16
|
-
* t('key', { p1, p2 }) — shorthand with correct names
|
|
17
|
-
* t('key', 'default value') — string default (not an interpolation object)
|
|
18
|
-
*
|
|
19
|
-
* RECOMMENDS: Use FM() instead of t() for parameterized translations.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const ALLOWED_PARAM_NAMES = new Set(['p1', 'p2', 'p3']);
|
|
23
|
-
|
|
24
|
-
// i18next configuration keys that are NOT interpolation params
|
|
25
|
-
const I18NEXT_CONFIG_KEYS = new Set([
|
|
26
|
-
'defaultValue',
|
|
27
|
-
'ns',
|
|
28
|
-
'lng',
|
|
29
|
-
'context',
|
|
30
|
-
'returnObjects',
|
|
31
|
-
'keySeparator',
|
|
32
|
-
'nsSeparator',
|
|
33
|
-
'interpolation',
|
|
34
|
-
'joinArrays',
|
|
35
|
-
'postProcess',
|
|
36
|
-
'replace',
|
|
37
|
-
'ordinal',
|
|
38
|
-
'formatParams',
|
|
39
|
-
'missingInterpolationHandler',
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
const rule = {
|
|
43
|
-
meta: {
|
|
44
|
-
type: 'problem',
|
|
45
|
-
docs: {
|
|
46
|
-
description:
|
|
47
|
-
'Enforce p1/p2/p3 parameter names in t() interpolation calls. ' +
|
|
48
|
-
'Translation JSON uses {{p1}}/{{p2}}/{{p3}} placeholders, so call sites ' +
|
|
49
|
-
'must pass { p1: value } — not { count: value } or other names.',
|
|
50
|
-
category: 'Possible Errors',
|
|
51
|
-
recommended: true,
|
|
52
|
-
},
|
|
53
|
-
schema: [],
|
|
54
|
-
messages: {
|
|
55
|
-
nonStandardParam:
|
|
56
|
-
'Non-standard interpolation param "{{paramName}}" in t() call. ' +
|
|
57
|
-
'Translation placeholders use {{p1}}/{{p2}}/{{p3}}. ' +
|
|
58
|
-
'Use FM(key, value) or t(key, { p1: value }) instead.',
|
|
59
|
-
preferFM:
|
|
60
|
-
'Prefer FM() over t() for parameterized translations. ' +
|
|
61
|
-
'FM() enforces positional params (p1, p2, p3) by design.',
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
create(context) {
|
|
66
|
-
return {
|
|
67
|
-
CallExpression(node) {
|
|
68
|
-
// Only match t('key', { ... }) calls
|
|
69
|
-
if (node.callee.type !== 'Identifier' || node.callee.name !== 't')
|
|
70
|
-
return;
|
|
71
|
-
|
|
72
|
-
// Need at least 2 arguments: t(key, options)
|
|
73
|
-
if (node.arguments.length < 2) return;
|
|
74
|
-
|
|
75
|
-
// Find the options argument — could be 2nd or 3rd arg
|
|
76
|
-
// t(key, defaultValue, options) or t(key, options)
|
|
77
|
-
const optionsArg = node.arguments.length >= 3
|
|
78
|
-
? node.arguments[2]
|
|
79
|
-
: node.arguments[1];
|
|
80
|
-
|
|
81
|
-
// Only check object literals (not variables or expressions)
|
|
82
|
-
if (!optionsArg || optionsArg.type !== 'ObjectExpression') return;
|
|
83
|
-
|
|
84
|
-
const properties = optionsArg.properties;
|
|
85
|
-
|
|
86
|
-
for (const prop of properties) {
|
|
87
|
-
// Skip spread elements
|
|
88
|
-
if (prop.type === 'SpreadElement') continue;
|
|
89
|
-
|
|
90
|
-
const keyName =
|
|
91
|
-
prop.key.type === 'Identifier'
|
|
92
|
-
? prop.key.name
|
|
93
|
-
: prop.key.type === 'Literal'
|
|
94
|
-
? String(prop.key.value)
|
|
95
|
-
: null;
|
|
96
|
-
|
|
97
|
-
if (keyName === null) continue;
|
|
98
|
-
|
|
99
|
-
// Skip known i18next config keys
|
|
100
|
-
if (I18NEXT_CONFIG_KEYS.has(keyName)) continue;
|
|
101
|
-
|
|
102
|
-
// Flag non-standard interpolation param names
|
|
103
|
-
if (!ALLOWED_PARAM_NAMES.has(keyName))
|
|
104
|
-
context.report({
|
|
105
|
-
node: prop,
|
|
106
|
-
messageId: 'nonStandardParam',
|
|
107
|
-
data: { paramName: keyName },
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
export default {
|
|
116
|
-
rules: {
|
|
117
|
-
'i18n-param-names': rule,
|
|
118
|
-
},
|
|
119
|
-
};
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom ESLint Plugin: No Barrel Companion File
|
|
3
|
-
*
|
|
4
|
-
* Flags any .ts/.tsx file that has a same-named directory containing an
|
|
5
|
-
* index.ts or index.tsx barrel file. This pattern causes a silent resolution
|
|
6
|
-
* conflict: TypeScript resolves `import from './foo'` to `foo.ts` (the file),
|
|
7
|
-
* NOT `foo/index.ts` (the barrel). Any exports added to the barrel but missing
|
|
8
|
-
* from the companion file will cause "has no exported member" errors.
|
|
9
|
-
*
|
|
10
|
-
* Auto-fix: When the companion file contains ONLY re-exports (no local
|
|
11
|
-
* declarations or logic), the fix replaces the entire file with
|
|
12
|
-
* `export * from './<name>/index';`. Files with local code are flagged
|
|
13
|
-
* but NOT auto-fixed — those require manual resolution.
|
|
14
|
-
*
|
|
15
|
-
* Examples:
|
|
16
|
-
* BAD: types.ts exists alongside types/index.ts
|
|
17
|
-
* → import from './types' resolves to types.ts, ignoring types/index.ts
|
|
18
|
-
*
|
|
19
|
-
* GOOD: Only types/index.ts exists (no companion types.ts)
|
|
20
|
-
* → import from './types' resolves to types/index.ts as expected
|
|
21
|
-
*
|
|
22
|
-
* GOOD: Only types.ts exists (no directory)
|
|
23
|
-
* → No ambiguity
|
|
24
|
-
*
|
|
25
|
-
* OK: types.ts exists with `export * from './types/index';`
|
|
26
|
-
* → Companion is a pure passthrough, all exports forwarded
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
import { existsSync } from 'fs';
|
|
30
|
-
import { dirname, basename, join } from 'path';
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Checks whether a Program node contains only re-export statements
|
|
34
|
-
* (no local declarations, logic, or JSX). A "re-export" is an
|
|
35
|
-
* ExportNamedDeclaration or ExportAllDeclaration that has a `source`
|
|
36
|
-
* property (meaning it re-exports from another module).
|
|
37
|
-
* Import statements are also allowed (they may be needed for re-exports).
|
|
38
|
-
*/
|
|
39
|
-
function isPureReExportFile(programNode) {
|
|
40
|
-
const { body } = programNode;
|
|
41
|
-
if (body.length === 0) return false;
|
|
42
|
-
|
|
43
|
-
return body.every((stmt) => {
|
|
44
|
-
if (stmt.type === 'ImportDeclaration') return true;
|
|
45
|
-
if (stmt.type === 'ExportAllDeclaration') return true;
|
|
46
|
-
const isReExport = stmt.type === 'ExportNamedDeclaration' && stmt.source !== null;
|
|
47
|
-
return isReExport;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const noBarrelCompanionFileRule = {
|
|
52
|
-
meta: {
|
|
53
|
-
type: 'problem',
|
|
54
|
-
fixable: 'code',
|
|
55
|
-
docs: {
|
|
56
|
-
description:
|
|
57
|
-
'Disallow .ts/.tsx files that shadow a same-named directory barrel (index.ts). ' +
|
|
58
|
-
'This causes TypeScript to resolve imports to the file instead of the barrel, ' +
|
|
59
|
-
'leading to missing export errors.',
|
|
60
|
-
category: 'Possible Errors',
|
|
61
|
-
recommended: true,
|
|
62
|
-
},
|
|
63
|
-
schema: [],
|
|
64
|
-
messages: {
|
|
65
|
-
companionFileConflict:
|
|
66
|
-
'File "{{fileName}}" shadows the barrel "{{barrelPath}}". ' +
|
|
67
|
-
'TypeScript resolves `import from \'./{{baseName}}\'` to this file, ignoring the barrel. ' +
|
|
68
|
-
'Delete this file and update imports to use the barrel, or consolidate into one location.',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
create(context) {
|
|
73
|
-
return {
|
|
74
|
-
Program(node) {
|
|
75
|
-
const filePath = context.filename || context.getFilename();
|
|
76
|
-
|
|
77
|
-
// Only check .ts and .tsx files (not .d.ts, not index files themselves)
|
|
78
|
-
if (!filePath || (!filePath.endsWith('.ts') && !filePath.endsWith('.tsx'))) return;
|
|
79
|
-
if (filePath.endsWith('.d.ts')) return;
|
|
80
|
-
|
|
81
|
-
const fileBaseName = basename(filePath);
|
|
82
|
-
|
|
83
|
-
// Skip index files — they ARE the barrel, not the companion
|
|
84
|
-
if (fileBaseName === 'index.ts' || fileBaseName === 'index.tsx') return;
|
|
85
|
-
|
|
86
|
-
// Get the base name without extension
|
|
87
|
-
const ext = fileBaseName.endsWith('.tsx') ? '.tsx' : '.ts';
|
|
88
|
-
const baseName = fileBaseName.slice(0, -ext.length);
|
|
89
|
-
const dir = dirname(filePath);
|
|
90
|
-
|
|
91
|
-
// Check if a same-named directory exists with an index barrel
|
|
92
|
-
const siblingDir = join(dir, baseName);
|
|
93
|
-
const barrelTs = join(siblingDir, 'index.ts');
|
|
94
|
-
const barrelTsx = join(siblingDir, 'index.tsx');
|
|
95
|
-
|
|
96
|
-
const hasBarrelTs = existsSync(barrelTs);
|
|
97
|
-
const hasBarrelTsx = existsSync(barrelTsx);
|
|
98
|
-
|
|
99
|
-
if (hasBarrelTs || hasBarrelTsx) {
|
|
100
|
-
// If the companion is already a pure wildcard re-export of the
|
|
101
|
-
// barrel, it's safe — all exports are forwarded automatically.
|
|
102
|
-
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
103
|
-
const trimmed = sourceCode.text.trim();
|
|
104
|
-
const safePattern = `export * from './${baseName}/index';`;
|
|
105
|
-
if (trimmed === safePattern) return;
|
|
106
|
-
|
|
107
|
-
const barrelPath = hasBarrelTs
|
|
108
|
-
? `${baseName}/index.ts`
|
|
109
|
-
: `${baseName}/index.tsx`;
|
|
110
|
-
|
|
111
|
-
// Only provide auto-fix when the file is purely re-exports.
|
|
112
|
-
// Files with local declarations, logic, or JSX require manual
|
|
113
|
-
// resolution (move code into the barrel directory).
|
|
114
|
-
const canAutoFix = isPureReExportFile(node);
|
|
115
|
-
|
|
116
|
-
context.report({
|
|
117
|
-
node,
|
|
118
|
-
messageId: 'companionFileConflict',
|
|
119
|
-
data: {
|
|
120
|
-
fileName: fileBaseName,
|
|
121
|
-
barrelPath,
|
|
122
|
-
baseName,
|
|
123
|
-
},
|
|
124
|
-
...(canAutoFix && {
|
|
125
|
-
fix(fixer) {
|
|
126
|
-
const fullRange = [0, sourceCode.text.length];
|
|
127
|
-
const replacement = `export * from './${baseName}/index';\n`;
|
|
128
|
-
return fixer.replaceTextRange(fullRange, replacement);
|
|
129
|
-
},
|
|
130
|
-
}),
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export default {
|
|
139
|
-
rules: {
|
|
140
|
-
'no-barrel-companion-file': noBarrelCompanionFileRule,
|
|
141
|
-
},
|
|
142
|
-
};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom ESLint Plugin: No Duplicate Nav Route/Key
|
|
3
|
-
*
|
|
4
|
-
* Ensures every sidebar nav item within a module has a unique `route` and `key`.
|
|
5
|
-
* Duplicate routes cause multiple sidebar items to navigate to the same path,
|
|
6
|
-
* and duplicate keys cause rendering/highlighting issues.
|
|
7
|
-
*
|
|
8
|
-
* Scoped to module definition files: packages/[module]/src/index.ts
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {string} propName
|
|
13
|
-
* @param {string} messageId
|
|
14
|
-
*/
|
|
15
|
-
function createDuplicateChecker(propName, messageId) {
|
|
16
|
-
return {
|
|
17
|
-
/** @param {import('estree').ArrayExpression} node */
|
|
18
|
-
check(node, context) {
|
|
19
|
-
const objectsWithProp = node.elements.filter(
|
|
20
|
-
(el) =>
|
|
21
|
-
el &&
|
|
22
|
-
el.type === 'ObjectExpression' &&
|
|
23
|
-
el.properties.some(
|
|
24
|
-
(p) =>
|
|
25
|
-
p.type === 'Property' &&
|
|
26
|
-
p.key.type === 'Identifier' &&
|
|
27
|
-
p.key.name === propName,
|
|
28
|
-
),
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
if (objectsWithProp.length === 0) return;
|
|
32
|
-
|
|
33
|
-
/** @type {Map<string, import('estree').Property>} */
|
|
34
|
-
const seen = new Map();
|
|
35
|
-
|
|
36
|
-
for (const obj of objectsWithProp) {
|
|
37
|
-
const prop = obj.properties.find(
|
|
38
|
-
(p) =>
|
|
39
|
-
p.type === 'Property' &&
|
|
40
|
-
p.key.type === 'Identifier' &&
|
|
41
|
-
p.key.name === propName,
|
|
42
|
-
);
|
|
43
|
-
if (!prop) continue;
|
|
44
|
-
|
|
45
|
-
let value;
|
|
46
|
-
if (prop.value.type === 'Literal') {
|
|
47
|
-
value = String(prop.value.value);
|
|
48
|
-
} else if (prop.value.type === 'MemberExpression') {
|
|
49
|
-
const src = context.sourceCode || context.getSourceCode();
|
|
50
|
-
value = src.getText(prop.value);
|
|
51
|
-
} else if (prop.value.type === 'TemplateLiteral' && prop.value.quasis.length === 1) {
|
|
52
|
-
value = prop.value.quasis[0].value.cooked;
|
|
53
|
-
} else {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (seen.has(value)) {
|
|
58
|
-
context.report({
|
|
59
|
-
node: prop.value,
|
|
60
|
-
messageId,
|
|
61
|
-
data: { value },
|
|
62
|
-
});
|
|
63
|
-
} else {
|
|
64
|
-
seen.set(value, prop);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const noDuplicateNavPrefixRule = {
|
|
72
|
-
meta: {
|
|
73
|
-
type: 'problem',
|
|
74
|
-
docs: {
|
|
75
|
-
description:
|
|
76
|
-
'Disallow duplicate route or key values in module sidebarItems. ' +
|
|
77
|
-
'Duplicate routes cause navigation collisions; duplicate keys cause rendering issues.',
|
|
78
|
-
category: 'Possible Errors',
|
|
79
|
-
recommended: true,
|
|
80
|
-
},
|
|
81
|
-
schema: [],
|
|
82
|
-
messages: {
|
|
83
|
-
duplicateRoute:
|
|
84
|
-
'Duplicate route "{{value}}" - each sidebar item must have a unique route.',
|
|
85
|
-
duplicateKey:
|
|
86
|
-
'Duplicate key "{{value}}" - each sidebar item must have a unique key.',
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
create(context) {
|
|
91
|
-
const routeChecker = createDuplicateChecker('route', 'duplicateRoute');
|
|
92
|
-
const keyChecker = createDuplicateChecker('key', 'duplicateKey');
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
ArrayExpression(node) {
|
|
96
|
-
routeChecker.check(node, context);
|
|
97
|
-
keyChecker.check(node, context);
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export default {
|
|
104
|
-
rules: {
|
|
105
|
-
'no-duplicate-nav-prefix': noDuplicateNavPrefixRule,
|
|
106
|
-
},
|
|
107
|
-
};
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom ESLint Plugin: No Duplicate Shared Patterns
|
|
3
|
-
*
|
|
4
|
-
* Warns when product module directories create components with names
|
|
5
|
-
* that match existing shared components in src/components/. This
|
|
6
|
-
* helps prevent accidental duplication of shared UI patterns.
|
|
7
|
-
*
|
|
8
|
-
* Scanned directories (product-specific code):
|
|
9
|
-
* - packages/* /src/ (product module packages)
|
|
10
|
-
* - src/features/ (feature directories)
|
|
11
|
-
*
|
|
12
|
-
* Reference directory (shared components):
|
|
13
|
-
* - src/components/ (recursively scanned for .tsx basenames)
|
|
14
|
-
*
|
|
15
|
-
* The rule collects all .tsx file basenames from src/components/ at
|
|
16
|
-
* startup and warns when a .tsx file in a product directory has the
|
|
17
|
-
* same basename.
|
|
18
|
-
*
|
|
19
|
-
* Examples:
|
|
20
|
-
* WARN: packages/onlinemenu-module/src/components/EmptyState.tsx
|
|
21
|
-
* (when src/components/Shared/EmptyState.tsx exists)
|
|
22
|
-
*
|
|
23
|
-
* OK: packages/onlinemenu-module/src/components/MenuCard.tsx
|
|
24
|
-
* (no matching shared component)
|
|
25
|
-
*
|
|
26
|
-
* OK: packages/onlinemenu-module/src/index.ts
|
|
27
|
-
* (not a .tsx component file)
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
import { readdirSync, existsSync } from 'fs';
|
|
31
|
-
import { posix, sep, basename, join } from 'path';
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Normalize a file path to use forward slashes.
|
|
35
|
-
*/
|
|
36
|
-
function normalizePath(filePath) {
|
|
37
|
-
return filePath.split(sep).join(posix.sep);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Recursively collect all .tsx basenames from a directory.
|
|
42
|
-
* Skips test files and index files.
|
|
43
|
-
*/
|
|
44
|
-
function collectComponentNames(dirPath) {
|
|
45
|
-
const names = new Set();
|
|
46
|
-
if (!existsSync(dirPath)) return names;
|
|
47
|
-
|
|
48
|
-
function walk(dir) {
|
|
49
|
-
try {
|
|
50
|
-
const entries = readdirSync(dir, { withFileTypes: true });
|
|
51
|
-
for (const entry of entries) {
|
|
52
|
-
if (entry.isDirectory()) {
|
|
53
|
-
walk(join(dir, entry.name));
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const name = entry.name;
|
|
57
|
-
if (!name.endsWith('.tsx')) continue;
|
|
58
|
-
if (name.endsWith('.test.tsx')) continue;
|
|
59
|
-
if (name === 'index.tsx') continue;
|
|
60
|
-
names.add(name);
|
|
61
|
-
}
|
|
62
|
-
} catch {
|
|
63
|
-
// Directory not readable, skip
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
walk(dirPath);
|
|
68
|
-
return names;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Check whether a file is inside a product-specific directory.
|
|
73
|
-
*/
|
|
74
|
-
function isInsideProductDirectory(filePath) {
|
|
75
|
-
const normalized = normalizePath(filePath);
|
|
76
|
-
return (
|
|
77
|
-
normalized.includes('/packages/') &&
|
|
78
|
-
normalized.includes('-module/src/')
|
|
79
|
-
) || normalized.includes('/src/features/');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Find the BaseClient src/components/ directory from a file path.
|
|
84
|
-
* Walks up looking for BaseClient/src/components/.
|
|
85
|
-
*/
|
|
86
|
-
function findSharedComponentsDir(filePath) {
|
|
87
|
-
const normalized = normalizePath(filePath);
|
|
88
|
-
const baseClientIdx = normalized.indexOf('/BaseClient/');
|
|
89
|
-
if (baseClientIdx === -1) return null;
|
|
90
|
-
const baseClientRoot = filePath
|
|
91
|
-
.split(sep)
|
|
92
|
-
.join(posix.sep)
|
|
93
|
-
.slice(0, baseClientIdx + '/BaseClient'.length);
|
|
94
|
-
// Convert back to OS path
|
|
95
|
-
const osPath = baseClientRoot.split(posix.sep).join(sep);
|
|
96
|
-
return join(osPath, 'src', 'components');
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Cache shared component names per components dir. */
|
|
100
|
-
const sharedNamesCache = new Map();
|
|
101
|
-
|
|
102
|
-
const noDuplicateSharedPatternsRule = {
|
|
103
|
-
meta: {
|
|
104
|
-
type: 'suggestion',
|
|
105
|
-
docs: {
|
|
106
|
-
description:
|
|
107
|
-
'Warn when product modules create components that share names ' +
|
|
108
|
-
'with existing shared components in src/components/.',
|
|
109
|
-
category: 'Best Practices',
|
|
110
|
-
recommended: false,
|
|
111
|
-
},
|
|
112
|
-
schema: [],
|
|
113
|
-
messages: {
|
|
114
|
-
duplicateSharedPattern:
|
|
115
|
-
'"{{fileName}}" already exists as a shared component in ' +
|
|
116
|
-
'src/components/. Consider reusing the shared version or ' +
|
|
117
|
-
'renaming this component to clarify its purpose.',
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
create(context) {
|
|
122
|
-
const filePath = context.filename || context.getFilename();
|
|
123
|
-
if (!filePath) return {};
|
|
124
|
-
|
|
125
|
-
// Only check .tsx files (components)
|
|
126
|
-
if (!filePath.endsWith('.tsx')) return {};
|
|
127
|
-
|
|
128
|
-
const fileName = basename(filePath);
|
|
129
|
-
|
|
130
|
-
// Skip test files and index files
|
|
131
|
-
if (fileName.endsWith('.test.tsx')) return {};
|
|
132
|
-
if (fileName === 'index.tsx') return {};
|
|
133
|
-
|
|
134
|
-
// Only check files in product-specific directories
|
|
135
|
-
if (!isInsideProductDirectory(filePath)) return {};
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
Program() {
|
|
139
|
-
const componentsDir = findSharedComponentsDir(filePath);
|
|
140
|
-
if (!componentsDir) return;
|
|
141
|
-
|
|
142
|
-
// Cache the shared component names
|
|
143
|
-
if (!sharedNamesCache.has(componentsDir))
|
|
144
|
-
sharedNamesCache.set(
|
|
145
|
-
componentsDir,
|
|
146
|
-
collectComponentNames(componentsDir),
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
const sharedNames = sharedNamesCache.get(componentsDir);
|
|
150
|
-
|
|
151
|
-
if (sharedNames.has(fileName))
|
|
152
|
-
context.report({
|
|
153
|
-
loc: { line: 1, column: 0 },
|
|
154
|
-
messageId: 'duplicateSharedPattern',
|
|
155
|
-
data: { fileName },
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
export default {
|
|
163
|
-
rules: {
|
|
164
|
-
'no-duplicate-shared-patterns': noDuplicateSharedPatternsRule,
|
|
165
|
-
},
|
|
166
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom ESLint Plugin: No Generated Models Barrel Value Import
|
|
3
|
-
*
|
|
4
|
-
* Disallows runtime (value) imports from the auto-generated model barrels:
|
|
5
|
-
* server/autoGeneratedHooks/<service>/models
|
|
6
|
-
* server/autoGeneratedHooks/<service>/models/index
|
|
7
|
-
*
|
|
8
|
-
* These barrels re-export all generated types for a service. Importing runtime
|
|
9
|
-
* values from them pulls the entire barrel into the module graph, preventing
|
|
10
|
-
* tree-shaking and inflating bundle size.
|
|
11
|
-
*
|
|
12
|
-
* Type-only imports are always allowed:
|
|
13
|
-
* import type { Foo } from '../../server/autoGeneratedHooks/questioner/models'; // OK
|
|
14
|
-
* import { type Foo } from '../../server/autoGeneratedHooks/questioner/models'; // OK
|
|
15
|
-
*
|
|
16
|
-
* Runtime value imports must target the specific leaf module instead:
|
|
17
|
-
* import { QuestionType } from '../../server/autoGeneratedHooks/questioner/models/questionType'; // OK
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/** Matches any path ending in autoGeneratedHooks/<service>/models or …/models/index */
|
|
21
|
-
const BARREL_PATTERN = /autoGeneratedHooks\/[^/]+\/models(?:\/index)?$/;
|
|
22
|
-
|
|
23
|
-
function isTypeOnlyImport(node) {
|
|
24
|
-
if (node.importKind === 'type') return true;
|
|
25
|
-
|
|
26
|
-
const specifiers = node.specifiers ?? [];
|
|
27
|
-
if (specifiers.length === 0) return false;
|
|
28
|
-
|
|
29
|
-
return specifiers.every((s) => s.importKind === 'type');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const noGeneratedModelsBarrelValueImportRule = {
|
|
33
|
-
meta: {
|
|
34
|
-
type: 'problem',
|
|
35
|
-
docs: {
|
|
36
|
-
description:
|
|
37
|
-
'Disallow runtime (value) imports from generated model barrels; use specific leaf modules or type-only imports.',
|
|
38
|
-
category: 'Best Practices',
|
|
39
|
-
recommended: true,
|
|
40
|
-
},
|
|
41
|
-
schema: [],
|
|
42
|
-
messages: {
|
|
43
|
-
noValueImport:
|
|
44
|
-
'Do not import runtime values from "{{module}}". Import from a specific leaf model module instead (e.g. …/models/questionType). Type-only imports are allowed.',
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
create(context) {
|
|
49
|
-
return {
|
|
50
|
-
ImportDeclaration(node) {
|
|
51
|
-
const moduleName = node.source?.value;
|
|
52
|
-
if (typeof moduleName !== 'string') return;
|
|
53
|
-
if (!BARREL_PATTERN.test(moduleName)) return;
|
|
54
|
-
if (isTypeOnlyImport(node)) return;
|
|
55
|
-
|
|
56
|
-
context.report({
|
|
57
|
-
node,
|
|
58
|
-
messageId: 'noValueImport',
|
|
59
|
-
data: { module: moduleName },
|
|
60
|
-
});
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export default {
|
|
67
|
-
rules: {
|
|
68
|
-
'no-generated-models-barrel-value-import': noGeneratedModelsBarrelValueImportRule,
|
|
69
|
-
},
|
|
70
|
-
};
|