@dloizides/frontend-devtools 1.0.1 → 1.0.3
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 +69 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +31 -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,149 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom ESLint Plugin: Enum File Isolation
|
|
3
|
-
*
|
|
4
|
-
* Flags exported enums in files that also contain unrelated exports.
|
|
5
|
-
* Enums should live in dedicated files (e.g., status.enum.ts or status.ts).
|
|
6
|
-
*
|
|
7
|
-
* Related helpers (functions/variables/types that reference the enum name)
|
|
8
|
-
* are allowed in the same file as the enum.
|
|
9
|
-
*
|
|
10
|
-
* Examples:
|
|
11
|
-
* FLAGGED - enum mixed with unrelated exports:
|
|
12
|
-
* export const enum ExportType { Csv = 'csv', Excel = 'excel' }
|
|
13
|
-
* export interface TableColumn { ... } // Unrelated to ExportType
|
|
14
|
-
*
|
|
15
|
-
* FLAGGED - multiple exported enums in one file:
|
|
16
|
-
* export const enum ErrorActionType { ... }
|
|
17
|
-
* export const enum ErrorSeverity { ... }
|
|
18
|
-
*
|
|
19
|
-
* NOT FLAGGED - enum with related helpers:
|
|
20
|
-
* export const enum MenuStatus { Active = 'active', Inactive = 'inactive' }
|
|
21
|
-
* export const menuStatusToLabel = (s: MenuStatus): string => { ... }
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
const enumFileIsolationRule = {
|
|
25
|
-
meta: {
|
|
26
|
-
type: 'suggestion',
|
|
27
|
-
docs: {
|
|
28
|
-
description:
|
|
29
|
-
'Exported enums should live in dedicated files. Only related helpers may share the file.',
|
|
30
|
-
category: 'Best Practices',
|
|
31
|
-
recommended: true,
|
|
32
|
-
},
|
|
33
|
-
schema: [],
|
|
34
|
-
messages: {
|
|
35
|
-
multipleEnums:
|
|
36
|
-
'File contains multiple exported enums ({{enumNames}}). Each enum should have its own dedicated file.',
|
|
37
|
-
unrelatedExports:
|
|
38
|
-
'Exported enum "{{enumName}}" is in a file with unrelated exports. Move the enum to a dedicated file (e.g., {{suggestedFile}}) or move unrelated exports elsewhere.',
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
create(context) {
|
|
43
|
-
const exportedEnums = [];
|
|
44
|
-
const otherExportNodes = [];
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Collect exported enum declarations.
|
|
48
|
-
*/
|
|
49
|
-
function collectExportedEnum(node) {
|
|
50
|
-
// ExportNamedDeclaration > TSEnumDeclaration
|
|
51
|
-
if (
|
|
52
|
-
node.type === 'ExportNamedDeclaration' &&
|
|
53
|
-
node.declaration &&
|
|
54
|
-
node.declaration.type === 'TSEnumDeclaration'
|
|
55
|
-
) {
|
|
56
|
-
exportedEnums.push({
|
|
57
|
-
name: node.declaration.id.name,
|
|
58
|
-
node: node.declaration.id,
|
|
59
|
-
});
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Collect non-enum exported declarations.
|
|
67
|
-
*/
|
|
68
|
-
function collectOtherExport(node) {
|
|
69
|
-
if (node.type !== 'ExportNamedDeclaration') return;
|
|
70
|
-
// Skip if it's an enum (already collected)
|
|
71
|
-
if (
|
|
72
|
-
node.declaration &&
|
|
73
|
-
node.declaration.type === 'TSEnumDeclaration'
|
|
74
|
-
)
|
|
75
|
-
return;
|
|
76
|
-
|
|
77
|
-
otherExportNodes.push(node);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Check if a source text references an enum name using word boundary.
|
|
82
|
-
*/
|
|
83
|
-
function referencesEnum(sourceText, enumName) {
|
|
84
|
-
const regex = new RegExp(`\\b${enumName}\\b`);
|
|
85
|
-
return regex.test(sourceText);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
ExportNamedDeclaration(node) {
|
|
90
|
-
if (!collectExportedEnum(node)) collectOtherExport(node);
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
'Program:exit'() {
|
|
94
|
-
// No exported enums -> nothing to check
|
|
95
|
-
if (exportedEnums.length === 0) return;
|
|
96
|
-
|
|
97
|
-
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
98
|
-
|
|
99
|
-
// Check for multiple exported enums in the same file
|
|
100
|
-
if (exportedEnums.length > 1) {
|
|
101
|
-
const enumNames = exportedEnums
|
|
102
|
-
.map((e) => e.name)
|
|
103
|
-
.join(', ');
|
|
104
|
-
for (const enumInfo of exportedEnums) {
|
|
105
|
-
context.report({
|
|
106
|
-
node: enumInfo.node,
|
|
107
|
-
messageId: 'multipleEnums',
|
|
108
|
-
data: { enumNames },
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Single enum - check if other exports are related
|
|
115
|
-
const enumName = exportedEnums[0].name;
|
|
116
|
-
const enumNode = exportedEnums[0].node;
|
|
117
|
-
|
|
118
|
-
// If no other exports, the file is fine
|
|
119
|
-
if (otherExportNodes.length === 0) return;
|
|
120
|
-
|
|
121
|
-
// Check each other export to see if it references the enum
|
|
122
|
-
const unrelatedExports = otherExportNodes.filter((node) => {
|
|
123
|
-
const text = sourceCode.getText(node);
|
|
124
|
-
return !referencesEnum(text, enumName);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
if (unrelatedExports.length > 0) {
|
|
128
|
-
// Convert PascalCase to kebab-case for suggested filename
|
|
129
|
-
const suggestedFile = enumName
|
|
130
|
-
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
131
|
-
.toLowerCase()
|
|
132
|
-
.concat('.ts');
|
|
133
|
-
|
|
134
|
-
context.report({
|
|
135
|
-
node: enumNode,
|
|
136
|
-
messageId: 'unrelatedExports',
|
|
137
|
-
data: { enumName, suggestedFile },
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
export default {
|
|
146
|
-
rules: {
|
|
147
|
-
'enum-file-isolation': enumFileIsolationRule,
|
|
148
|
-
},
|
|
149
|
-
};
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom ESLint Plugin: i18n Interpolation Placeholder Enforcement
|
|
3
|
-
*
|
|
4
|
-
* Ensures translation JSON files only use standardized placeholders:
|
|
5
|
-
* {{p1}}, {{p2}}, {{p3}} (compatible with the FM() helper).
|
|
6
|
-
*
|
|
7
|
-
* Detects and autofixes:
|
|
8
|
-
* - Non-standard double-brace placeholders: {{message}} → {{p1}}
|
|
9
|
-
* - Single-brace placeholders: {p1} → {{p1}}
|
|
10
|
-
* - Placeholders exceeding the 3-param FM() limit (error only, no autofix)
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
const DOUBLE_BRACE_REGEX = /\{\{(\w+)\}\}/g;
|
|
14
|
-
const SINGLE_BRACE_REGEX = /(?<!\{)\{(\w+)\}(?!\})/g;
|
|
15
|
-
const ALLOWED_NAMES = new Set(['p1', 'p2', 'p3']);
|
|
16
|
-
const MAX_POSITIONAL_PARAMS = 3;
|
|
17
|
-
|
|
18
|
-
const rule = {
|
|
19
|
-
meta: {
|
|
20
|
-
type: 'problem',
|
|
21
|
-
docs: {
|
|
22
|
-
description:
|
|
23
|
-
'Enforce {{p1}}/{{p2}}/{{p3}} interpolation placeholders in translation JSON files',
|
|
24
|
-
},
|
|
25
|
-
fixable: 'code',
|
|
26
|
-
schema: [],
|
|
27
|
-
messages: {
|
|
28
|
-
nonStandardPlaceholder:
|
|
29
|
-
'Non-standard placeholder "{{placeholder}}" found. Use {{p1}}/{{p2}}/{{p3}} instead.',
|
|
30
|
-
singleBracePlaceholder:
|
|
31
|
-
'Single-brace placeholder "{{{placeholder}}}" found. Use double braces: {{{{{fixedName}}}}}.',
|
|
32
|
-
tooManyPlaceholders:
|
|
33
|
-
'Translation has {{count}} unique placeholders but FM() only supports 3. Refactor the translation string.',
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
create(context) {
|
|
38
|
-
return {
|
|
39
|
-
JSONLiteral(node) {
|
|
40
|
-
if (typeof node.value !== 'string') return;
|
|
41
|
-
|
|
42
|
-
const raw = node.value;
|
|
43
|
-
|
|
44
|
-
// Collect all non-standard double-brace placeholders
|
|
45
|
-
const doubleBraceMatches = [];
|
|
46
|
-
let match;
|
|
47
|
-
while ((match = DOUBLE_BRACE_REGEX.exec(raw)) !== null) {
|
|
48
|
-
if (!ALLOWED_NAMES.has(match[1]))
|
|
49
|
-
doubleBraceMatches.push({ name: match[1], index: match.index });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Collect single-brace placeholders (any name)
|
|
53
|
-
const singleBraceMatches = [];
|
|
54
|
-
while ((match = SINGLE_BRACE_REGEX.exec(raw)) !== null)
|
|
55
|
-
singleBraceMatches.push({ name: match[1], index: match.index });
|
|
56
|
-
|
|
57
|
-
const hasDoubleBraceIssues = doubleBraceMatches.length > 0;
|
|
58
|
-
const hasSingleBraceIssues = singleBraceMatches.length > 0;
|
|
59
|
-
|
|
60
|
-
if (!hasDoubleBraceIssues && !hasSingleBraceIssues) return;
|
|
61
|
-
|
|
62
|
-
// Build ordered mapping of unique placeholder names → p1/p2/p3
|
|
63
|
-
const seenNames = [];
|
|
64
|
-
const allMatches = [...doubleBraceMatches, ...singleBraceMatches].sort(
|
|
65
|
-
(a, b) => a.index - b.index,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
for (const m of allMatches) {
|
|
69
|
-
if (!seenNames.includes(m.name) && !ALLOWED_NAMES.has(m.name))
|
|
70
|
-
seenNames.push(m.name);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Check if too many unique placeholders
|
|
74
|
-
// Count existing valid ones too
|
|
75
|
-
const existingValid = new Set();
|
|
76
|
-
let m2;
|
|
77
|
-
const tempRegex = /\{\{(\w+)\}\}/g;
|
|
78
|
-
while ((m2 = tempRegex.exec(raw)) !== null) {
|
|
79
|
-
if (ALLOWED_NAMES.has(m2[1])) existingValid.add(m2[1]);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Also count single-brace valid ones
|
|
83
|
-
const tempSingleRegex = /(?<!\{)\{(\w+)\}(?!\})/g;
|
|
84
|
-
while ((m2 = tempSingleRegex.exec(raw)) !== null) {
|
|
85
|
-
if (ALLOWED_NAMES.has(m2[1])) existingValid.add(m2[1]);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const totalUnique = seenNames.length + existingValid.size;
|
|
89
|
-
|
|
90
|
-
if (totalUnique > MAX_POSITIONAL_PARAMS) {
|
|
91
|
-
context.report({
|
|
92
|
-
node,
|
|
93
|
-
messageId: 'tooManyPlaceholders',
|
|
94
|
-
data: { count: String(totalUnique) },
|
|
95
|
-
});
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Determine the next available positional name
|
|
100
|
-
const usedPositional = new Set(existingValid);
|
|
101
|
-
const nameMap = {};
|
|
102
|
-
const positionalNames = ['p1', 'p2', 'p3'];
|
|
103
|
-
let nextIdx = 0;
|
|
104
|
-
|
|
105
|
-
// Skip already-used positional names
|
|
106
|
-
for (const name of seenNames) {
|
|
107
|
-
while (
|
|
108
|
-
nextIdx < positionalNames.length &&
|
|
109
|
-
usedPositional.has(positionalNames[nextIdx])
|
|
110
|
-
)
|
|
111
|
-
nextIdx++;
|
|
112
|
-
|
|
113
|
-
if (nextIdx < positionalNames.length) {
|
|
114
|
-
nameMap[name] = positionalNames[nextIdx];
|
|
115
|
-
usedPositional.add(positionalNames[nextIdx]);
|
|
116
|
-
nextIdx++;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Report and fix double-brace non-standard placeholders
|
|
121
|
-
if (hasDoubleBraceIssues) {
|
|
122
|
-
const fixedValue = raw.replace(DOUBLE_BRACE_REGEX, (full, name) => {
|
|
123
|
-
if (ALLOWED_NAMES.has(name)) return full;
|
|
124
|
-
const replacement = nameMap[name];
|
|
125
|
-
return replacement !== undefined ? `{{${replacement}}}` : full;
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
context.report({
|
|
129
|
-
node,
|
|
130
|
-
messageId: 'nonStandardPlaceholder',
|
|
131
|
-
data: { placeholder: doubleBraceMatches[0].name },
|
|
132
|
-
fix(fixer) {
|
|
133
|
-
let finalValue = fixedValue;
|
|
134
|
-
|
|
135
|
-
// Also fix single-brace issues in the same pass
|
|
136
|
-
if (hasSingleBraceIssues)
|
|
137
|
-
finalValue = finalValue.replace(
|
|
138
|
-
SINGLE_BRACE_REGEX,
|
|
139
|
-
(full, name) => {
|
|
140
|
-
if (ALLOWED_NAMES.has(name)) return `{{${name}}}`;
|
|
141
|
-
const replacement = nameMap[name];
|
|
142
|
-
return replacement !== undefined
|
|
143
|
-
? `{{${replacement}}}`
|
|
144
|
-
: `{{${name}}}`;
|
|
145
|
-
},
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
return fixer.replaceText(node, JSON.stringify(finalValue));
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
} else if (hasSingleBraceIssues) {
|
|
152
|
-
// Only single-brace issues
|
|
153
|
-
const fixedValue = raw.replace(SINGLE_BRACE_REGEX, (full, name) => {
|
|
154
|
-
if (ALLOWED_NAMES.has(name)) return `{{${name}}}`;
|
|
155
|
-
const replacement = nameMap[name];
|
|
156
|
-
return replacement !== undefined
|
|
157
|
-
? `{{${replacement}}}`
|
|
158
|
-
: `{{${name}}}`;
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
context.report({
|
|
162
|
-
node,
|
|
163
|
-
messageId: 'singleBracePlaceholder',
|
|
164
|
-
data: {
|
|
165
|
-
placeholder: singleBraceMatches[0].name,
|
|
166
|
-
fixedName: ALLOWED_NAMES.has(singleBraceMatches[0].name)
|
|
167
|
-
? singleBraceMatches[0].name
|
|
168
|
-
: nameMap[singleBraceMatches[0].name] ??
|
|
169
|
-
singleBraceMatches[0].name,
|
|
170
|
-
},
|
|
171
|
-
fix(fixer) {
|
|
172
|
-
return fixer.replaceText(node, JSON.stringify(fixedValue));
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
export default {
|
|
182
|
-
rules: {
|
|
183
|
-
'i18n-interpolation': rule,
|
|
184
|
-
},
|
|
185
|
-
};
|
|
@@ -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
|
-
};
|