@bleedingdev/modern-js-code-tools 3.5.0-ultramodern.9 → 3.5.0-ultramodern.90
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/cjs/cli/i18n-check.cjs +0 -6
- package/dist/cjs/cli/workspace-source-check.cjs +0 -3
- package/dist/cjs/oxlint-plugin/ast.cjs +181 -0
- package/dist/cjs/oxlint-plugin/options.cjs +172 -0
- package/dist/cjs/oxlint-plugin/rules/no-hardcoded-jsx-text.cjs +82 -0
- package/dist/cjs/oxlint-plugin/rules/no-legacy-mf-boundary-attributes.cjs +61 -0
- package/dist/cjs/oxlint-plugin/rules/no-literal-visible-jsx-attributes.cjs +74 -0
- package/dist/cjs/oxlint-plugin/rules/no-manual-locale-copy-branching.cjs +80 -0
- package/dist/cjs/oxlint-plugin/rules/no-split-translation-keys.cjs +70 -0
- package/dist/cjs/oxlint-plugin/rules/strict-effect-api-boundaries.cjs +84 -0
- package/dist/cjs/oxlint-plugin/types.cjs +18 -0
- package/dist/cjs/oxlint-plugin.cjs +100 -382
- package/dist/esm/cli/i18n-check.js +1 -1
- package/dist/esm/cli/workspace-source-check.js +1 -1
- package/dist/esm/oxlint-plugin/ast.js +83 -0
- package/dist/esm/oxlint-plugin/options.js +89 -0
- package/dist/esm/oxlint-plugin/rules/no-hardcoded-jsx-text.js +44 -0
- package/dist/esm/oxlint-plugin/rules/no-legacy-mf-boundary-attributes.js +23 -0
- package/dist/esm/oxlint-plugin/rules/no-literal-visible-jsx-attributes.js +36 -0
- package/dist/esm/oxlint-plugin/rules/no-manual-locale-copy-branching.js +42 -0
- package/dist/esm/oxlint-plugin/rules/no-split-translation-keys.js +32 -0
- package/dist/esm/oxlint-plugin/rules/strict-effect-api-boundaries.js +46 -0
- package/dist/esm/oxlint-plugin/types.js +0 -0
- package/dist/esm/oxlint-plugin.js +15 -367
- package/dist/esm-node/cli/i18n-check.js +1 -1
- package/dist/esm-node/cli/workspace-source-check.js +1 -1
- package/dist/esm-node/oxlint-plugin/ast.js +84 -0
- package/dist/esm-node/oxlint-plugin/options.js +90 -0
- package/dist/esm-node/oxlint-plugin/rules/no-hardcoded-jsx-text.js +45 -0
- package/dist/esm-node/oxlint-plugin/rules/no-legacy-mf-boundary-attributes.js +24 -0
- package/dist/esm-node/oxlint-plugin/rules/no-literal-visible-jsx-attributes.js +37 -0
- package/dist/esm-node/oxlint-plugin/rules/no-manual-locale-copy-branching.js +43 -0
- package/dist/esm-node/oxlint-plugin/rules/no-split-translation-keys.js +33 -0
- package/dist/esm-node/oxlint-plugin/rules/strict-effect-api-boundaries.js +47 -0
- package/dist/esm-node/oxlint-plugin/types.js +1 -0
- package/dist/esm-node/oxlint-plugin.js +15 -367
- package/dist/types/cli/i18n-check.d.ts +0 -2
- package/dist/types/cli/workspace-source-check.d.ts +0 -1
- package/dist/types/oxlint-plugin/ast.d.ts +22 -0
- package/dist/types/oxlint-plugin/options.d.ts +62 -0
- package/dist/types/oxlint-plugin/rules/no-hardcoded-jsx-text.d.ts +2 -0
- package/dist/types/oxlint-plugin/rules/no-legacy-mf-boundary-attributes.d.ts +2 -0
- package/dist/types/oxlint-plugin/rules/no-literal-visible-jsx-attributes.d.ts +2 -0
- package/dist/types/oxlint-plugin/rules/no-manual-locale-copy-branching.d.ts +2 -0
- package/dist/types/oxlint-plugin/rules/no-split-translation-keys.d.ts +2 -0
- package/dist/types/oxlint-plugin/rules/strict-effect-api-boundaries.d.ts +2 -0
- package/dist/types/oxlint-plugin/types.d.ts +60 -0
- package/dist/types/oxlint-plugin.d.ts +15 -56
- package/package.json +6 -7
|
@@ -1,370 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const attributeOptionsSchema = {
|
|
17
|
-
type: 'object',
|
|
18
|
-
properties: {
|
|
19
|
-
...commonOptionsSchema.properties,
|
|
20
|
-
visibleAttributes: {
|
|
21
|
-
type: 'array',
|
|
22
|
-
items: {
|
|
23
|
-
type: 'string'
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
additionalProperties: false
|
|
28
|
-
};
|
|
29
|
-
const translationOptionsSchema = {
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: {
|
|
32
|
-
translationFunctions: {
|
|
33
|
-
type: 'array',
|
|
34
|
-
items: {
|
|
35
|
-
type: 'string'
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
additionalProperties: false
|
|
40
|
-
};
|
|
41
|
-
const DEFAULT_VISIBLE_ATTRIBUTES = [
|
|
42
|
-
'aria-label',
|
|
43
|
-
"aria-description",
|
|
44
|
-
"aria-roledescription",
|
|
45
|
-
'aria-valuetext',
|
|
46
|
-
'alt',
|
|
47
|
-
'placeholder',
|
|
48
|
-
'title'
|
|
49
|
-
];
|
|
50
|
-
const DEFAULT_ALLOWED_ELEMENTS = [
|
|
51
|
-
'code',
|
|
52
|
-
'kbd',
|
|
53
|
-
'samp'
|
|
54
|
-
];
|
|
55
|
-
const DEFAULT_TRANSLATION_FUNCTIONS = [
|
|
56
|
-
't'
|
|
57
|
-
];
|
|
58
|
-
const DEFAULT_IGNORE_COMMENT_PATTERN = 'i18n-ignore';
|
|
59
|
-
const LETTER_PATTERN = /\p{L}/u;
|
|
60
|
-
const SPLIT_TRANSLATION_KEY_PATTERN = /\.(?:prefix|suffix|before|after)$/u;
|
|
61
|
-
const API_SOURCE_FILE_PATTERN = /(?:^|\/)(?:api\/|shared\/api\.[cm]?[jt]sx?$)/u;
|
|
62
|
-
const FORBIDDEN_GENERATED_EFFECT_PATH_PATTERN = /(?:^|\/)(?:(?:apps|verticals)\/[^/]+\/(?:api\/(?:effect|lambda)|shared\/effect|src\/effect))(?:\/|$)/u;
|
|
63
|
-
const API_ENTRY_PATTERN = /(?:^|\/)(?:apps|verticals)\/[^/]+\/api\/index\.[cm]?[jt]sx?$/u;
|
|
64
|
-
const SHARED_API_CONTRACT_PATTERN = /(?:^|\/)(?:apps|verticals)\/[^/]+\/shared\/api\.[cm]?[jt]sx?$/u;
|
|
65
|
-
const isRecord = (value)=>Boolean(value) && 'object' == typeof value && !Array.isArray(value);
|
|
66
|
-
const asStringArray = (value, fallback)=>Array.isArray(value) && value.every((item)=>'string' == typeof item) ? value : fallback;
|
|
67
|
-
const getCommonRuleOption = (context, defaults)=>{
|
|
68
|
-
const options = context.options?.[0];
|
|
69
|
-
if (!isRecord(options)) return defaults;
|
|
70
|
-
return {
|
|
71
|
-
allowElements: asStringArray(options.allowElements, defaults.allowElements),
|
|
72
|
-
ignoreCommentPattern: 'string' == typeof options.ignoreCommentPattern ? options.ignoreCommentPattern : defaults.ignoreCommentPattern
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
const getAttributeRuleOption = (context, defaults)=>{
|
|
76
|
-
const options = context.options?.[0];
|
|
77
|
-
const commonOptions = getCommonRuleOption(context, defaults);
|
|
78
|
-
return {
|
|
79
|
-
...commonOptions,
|
|
80
|
-
visibleAttributes: isRecord(options) ? asStringArray(options.visibleAttributes, defaults.visibleAttributes) : defaults.visibleAttributes
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
const getSplitTranslationKeyRuleOption = (context, defaults)=>{
|
|
84
|
-
const options = context.options?.[0];
|
|
85
|
-
if (!isRecord(options)) return defaults;
|
|
86
|
-
return {
|
|
87
|
-
translationFunctions: asStringArray(options.translationFunctions, defaults.translationFunctions)
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
const normalizeVisibleText = (value)=>value.replaceAll(/\s+/gu, ' ').trim();
|
|
91
|
-
const hasLetters = (value)=>LETTER_PATTERN.test(value);
|
|
92
|
-
const getNodeName = (node)=>{
|
|
93
|
-
if (!node) return;
|
|
94
|
-
if ('string' == typeof node.name) return node.name;
|
|
95
|
-
if ('JSXIdentifier' === node.type && isRecord(node.name) && 'string' == typeof node.name.name) return node.name.name;
|
|
96
|
-
if ('JSXIdentifier' === node.type && 'string' == typeof node.name) return node.name;
|
|
97
|
-
if (('JSXMemberExpression' === node.type || 'MemberExpression' === node.type) && isRecord(node.property) && true !== node.computed) {
|
|
98
|
-
const objectName = getNodeName(node.object);
|
|
99
|
-
const propertyName = getNodeName(node.property);
|
|
100
|
-
return objectName && propertyName ? `${objectName}.${propertyName}` : propertyName;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const getJsxElementName = (node)=>{
|
|
104
|
-
if (node?.type !== 'JSXElement') return;
|
|
105
|
-
return getNodeName(node.openingElement?.name);
|
|
106
|
-
};
|
|
107
|
-
const hasAllowedElementAncestor = (node, allowedElements)=>{
|
|
108
|
-
let current = node;
|
|
109
|
-
while(current){
|
|
110
|
-
const elementName = getJsxElementName(current);
|
|
111
|
-
if (elementName && allowedElements.has(elementName)) return true;
|
|
112
|
-
current = current.parent;
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
};
|
|
116
|
-
const getTemplateLiteralValue = (node)=>{
|
|
117
|
-
if ('TemplateLiteral' !== node.type || (node.expressions?.length ?? 0) > 0) return;
|
|
118
|
-
const quasi = node.quasis?.[0];
|
|
119
|
-
if (!isRecord(quasi?.value)) return;
|
|
120
|
-
const cooked = quasi.value.cooked;
|
|
121
|
-
const raw = quasi.value.raw;
|
|
122
|
-
return 'string' == typeof cooked ? cooked : 'string' == typeof raw ? raw : void 0;
|
|
123
|
-
};
|
|
124
|
-
const getStringLiteralValue = (node)=>{
|
|
125
|
-
if (!node) return;
|
|
126
|
-
if (('Literal' === node.type || 'StringLiteral' === node.type) && 'string' == typeof node.value) return node.value;
|
|
127
|
-
return getTemplateLiteralValue(node);
|
|
128
|
-
};
|
|
129
|
-
const expressionStringValue = (node)=>getStringLiteralValue(node?.type === 'JSXExpressionContainer' ? node.expression : node);
|
|
130
|
-
const getLine = (node)=>node.loc?.start?.line;
|
|
131
|
-
const hasIgnoreComment = (node, context, pattern)=>{
|
|
132
|
-
const sourceCode = context.getSourceCode?.();
|
|
133
|
-
const nodeLine = getLine(node);
|
|
134
|
-
if (!sourceCode?.getAllComments || void 0 === nodeLine) return false;
|
|
135
|
-
return sourceCode.getAllComments().some((comment)=>{
|
|
136
|
-
const commentValue = String(comment.value ?? '');
|
|
137
|
-
if (!pattern.test(commentValue)) return false;
|
|
138
|
-
const startLine = comment.loc?.start?.line;
|
|
139
|
-
const endLine = comment.loc?.end?.line ?? startLine;
|
|
140
|
-
return void 0 !== startLine && void 0 !== endLine && startLine <= nodeLine + 1 && endLine >= nodeLine - 1;
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
const getIgnorePattern = (options)=>new RegExp(options.ignoreCommentPattern, 'u');
|
|
144
|
-
const reportVisibleText = (context, node, text)=>{
|
|
145
|
-
context.report({
|
|
146
|
-
node,
|
|
147
|
-
message: `Move user-visible JSX text to locale resources: ${JSON.stringify(text)}`
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
const createNoHardcodedJsxTextRule = ()=>({
|
|
151
|
-
meta: {
|
|
152
|
-
type: 'problem',
|
|
153
|
-
docs: {
|
|
154
|
-
description: 'Disallow literal user-visible text in JSX children in UltraModern generated apps.'
|
|
155
|
-
},
|
|
156
|
-
schema: [
|
|
157
|
-
commonOptionsSchema
|
|
158
|
-
]
|
|
159
|
-
},
|
|
160
|
-
create (context) {
|
|
161
|
-
const options = getCommonRuleOption(context, {
|
|
162
|
-
allowElements: DEFAULT_ALLOWED_ELEMENTS,
|
|
163
|
-
ignoreCommentPattern: DEFAULT_IGNORE_COMMENT_PATTERN
|
|
164
|
-
});
|
|
165
|
-
const allowedElements = new Set(options.allowElements);
|
|
166
|
-
const ignorePattern = getIgnorePattern(options);
|
|
167
|
-
const shouldSkipNode = (node)=>hasAllowedElementAncestor(node, allowedElements) || hasIgnoreComment(node, context, ignorePattern);
|
|
168
|
-
return {
|
|
169
|
-
JSXText (node) {
|
|
170
|
-
const text = normalizeVisibleText(String(node.value ?? ''));
|
|
171
|
-
if (!text || !hasLetters(text) || shouldSkipNode(node)) return;
|
|
172
|
-
reportVisibleText(context, node, text);
|
|
173
|
-
},
|
|
174
|
-
JSXExpressionContainer (node) {
|
|
175
|
-
if (node.parent?.type !== 'JSXElement' && node.parent?.type !== 'JSXFragment') return;
|
|
176
|
-
const text = normalizeVisibleText(expressionStringValue(node.expression) ?? '');
|
|
177
|
-
if (!text || !hasLetters(text) || shouldSkipNode(node)) return;
|
|
178
|
-
reportVisibleText(context, node, text);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
const createNoLiteralVisibleJsxAttributesRule = ()=>({
|
|
184
|
-
meta: {
|
|
185
|
-
type: 'problem',
|
|
186
|
-
docs: {
|
|
187
|
-
description: 'Disallow literal user-visible JSX attribute text in UltraModern generated apps.'
|
|
188
|
-
},
|
|
189
|
-
schema: [
|
|
190
|
-
attributeOptionsSchema
|
|
191
|
-
]
|
|
192
|
-
},
|
|
193
|
-
create (context) {
|
|
194
|
-
const options = getAttributeRuleOption(context, {
|
|
195
|
-
allowElements: DEFAULT_ALLOWED_ELEMENTS,
|
|
196
|
-
ignoreCommentPattern: DEFAULT_IGNORE_COMMENT_PATTERN,
|
|
197
|
-
visibleAttributes: DEFAULT_VISIBLE_ATTRIBUTES
|
|
198
|
-
});
|
|
199
|
-
const visibleAttributes = new Set(options.visibleAttributes);
|
|
200
|
-
const ignorePattern = getIgnorePattern(options);
|
|
201
|
-
return {
|
|
202
|
-
JSXAttribute (node) {
|
|
203
|
-
const attributeName = getNodeName(node.name);
|
|
204
|
-
if (!attributeName || !visibleAttributes.has(attributeName)) return;
|
|
205
|
-
const text = normalizeVisibleText(expressionStringValue(node.value) ?? '');
|
|
206
|
-
if (!text || !hasLetters(text) || hasIgnoreComment(node, context, ignorePattern)) return;
|
|
207
|
-
context.report({
|
|
208
|
-
node,
|
|
209
|
-
message: `Move literal ${attributeName} copy to locale resources: ${JSON.stringify(text)}`
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
const getSourceText = (context, node)=>context.getSourceCode?.().getText?.(node) ?? context.getSourceCode?.().text ?? '';
|
|
216
|
-
const normalizeFilename = (filePath)=>(filePath ?? '').replaceAll('\\', '/');
|
|
217
|
-
const isApiSourceFile = (filePath)=>API_SOURCE_FILE_PATTERN.test(normalizeFilename(filePath));
|
|
218
|
-
const isForbiddenGeneratedEffectPath = (filePath)=>FORBIDDEN_GENERATED_EFFECT_PATH_PATTERN.test(normalizeFilename(filePath));
|
|
219
|
-
const isApiEntryFile = (filePath)=>API_ENTRY_PATTERN.test(normalizeFilename(filePath));
|
|
220
|
-
const isSharedApiContractFile = (filePath)=>SHARED_API_CONTRACT_PATTERN.test(normalizeFilename(filePath));
|
|
221
|
-
const looksLikeLocaleTest = (context, node)=>{
|
|
222
|
-
const text = getSourceText(context, node);
|
|
223
|
-
return /\b(?:language|locale|lng|currentLanguage)\b/u.test(text) && /(?:={2,3}|!==?)/u.test(text) && /['"][a-z]{2}(?:-[A-Za-z0-9]+)?['"]/u.test(text);
|
|
224
|
-
};
|
|
225
|
-
const isAllowedBranchLiteral = (text)=>new Set([
|
|
226
|
-
'page',
|
|
227
|
-
'undefined',
|
|
228
|
-
'null',
|
|
229
|
-
'true',
|
|
230
|
-
'false'
|
|
231
|
-
]).has(text);
|
|
232
|
-
const createNoManualLocaleCopyBranchingRule = ()=>({
|
|
233
|
-
meta: {
|
|
234
|
-
type: 'problem',
|
|
235
|
-
docs: {
|
|
236
|
-
description: 'Disallow manual locale conditionals that choose user-visible copy.'
|
|
237
|
-
},
|
|
238
|
-
schema: []
|
|
239
|
-
},
|
|
240
|
-
create (context) {
|
|
241
|
-
const reportBranch = (node, text)=>{
|
|
242
|
-
context.report({
|
|
243
|
-
node,
|
|
244
|
-
message: `Move locale-specific copy branch to i18n resources: ${JSON.stringify(normalizeVisibleText(text))}`
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
return {
|
|
248
|
-
ConditionalExpression (node) {
|
|
249
|
-
if (!node.test || !looksLikeLocaleTest(context, node.test)) return;
|
|
250
|
-
for (const branch of [
|
|
251
|
-
node.consequent,
|
|
252
|
-
node.alternate
|
|
253
|
-
]){
|
|
254
|
-
const text = expressionStringValue(branch);
|
|
255
|
-
if (text && hasLetters(text) && !isAllowedBranchLiteral(text.trim())) reportBranch(branch, text);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
const getCallExpressionName = (node)=>getNodeName(node);
|
|
262
|
-
const createNoSplitTranslationKeysRule = ()=>({
|
|
263
|
-
meta: {
|
|
264
|
-
type: 'problem',
|
|
265
|
-
docs: {
|
|
266
|
-
description: 'Disallow split phrase translation key suffixes such as .prefix and .suffix.'
|
|
267
|
-
},
|
|
268
|
-
schema: [
|
|
269
|
-
translationOptionsSchema
|
|
270
|
-
]
|
|
271
|
-
},
|
|
272
|
-
create (context) {
|
|
273
|
-
const options = getSplitTranslationKeyRuleOption(context, {
|
|
274
|
-
translationFunctions: DEFAULT_TRANSLATION_FUNCTIONS
|
|
275
|
-
});
|
|
276
|
-
const translationFunctions = new Set(options.translationFunctions);
|
|
277
|
-
return {
|
|
278
|
-
CallExpression (node) {
|
|
279
|
-
const calleeName = getCallExpressionName(node.callee);
|
|
280
|
-
if (!calleeName || !translationFunctions.has(calleeName)) return;
|
|
281
|
-
const key = expressionStringValue(node.arguments?.[0]);
|
|
282
|
-
if (!key || !SPLIT_TRANSLATION_KEY_PATTERN.test(key)) return;
|
|
283
|
-
context.report({
|
|
284
|
-
node,
|
|
285
|
-
message: 'Keep translator-owned phrases whole instead of using split translation keys.'
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
const createNoLegacyMfBoundaryAttributesRule = ()=>({
|
|
292
|
-
meta: {
|
|
293
|
-
type: 'problem',
|
|
294
|
-
docs: {
|
|
295
|
-
description: 'Disallow legacy Module Federation boundary attributes in generated UltraModern workspaces.'
|
|
296
|
-
},
|
|
297
|
-
schema: []
|
|
298
|
-
},
|
|
299
|
-
create (context) {
|
|
300
|
-
return {
|
|
301
|
-
JSXAttribute (node) {
|
|
302
|
-
const attributeName = getNodeName(node.name);
|
|
303
|
-
if ('data-mf-boundary' !== attributeName && 'data-mf-remote' !== attributeName && 'data-mf-expose' !== attributeName) return;
|
|
304
|
-
context.report({
|
|
305
|
-
node,
|
|
306
|
-
message: 'Use data-modern-boundary-id and data-modern-mf-expose instead of legacy data-mf-* boundary attributes.'
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
const reportProgramPattern = (context, node, source, pattern, message)=>{
|
|
313
|
-
if (pattern.test(source)) context.report({
|
|
314
|
-
node,
|
|
315
|
-
message
|
|
316
|
-
});
|
|
317
|
-
};
|
|
318
|
-
const reportMissingProgramPattern = (context, node, source, pattern, message)=>{
|
|
319
|
-
if (!pattern.test(source)) context.report({
|
|
320
|
-
node,
|
|
321
|
-
message
|
|
322
|
-
});
|
|
323
|
-
};
|
|
324
|
-
const createStrictEffectApiBoundariesRule = ()=>({
|
|
325
|
-
meta: {
|
|
326
|
-
type: 'problem',
|
|
327
|
-
docs: {
|
|
328
|
-
description: 'Disallow raw HTTP handlers and non-Effect API runtime drift in UltraModern workspaces.'
|
|
329
|
-
},
|
|
330
|
-
schema: []
|
|
331
|
-
},
|
|
332
|
-
create (context) {
|
|
333
|
-
return {
|
|
334
|
-
Program (node) {
|
|
335
|
-
const source = getSourceText(context, node);
|
|
336
|
-
const filename = normalizeFilename(context.filename);
|
|
337
|
-
const apiFile = isApiSourceFile(filename);
|
|
338
|
-
if (isForbiddenGeneratedEffectPath(filename)) context.report({
|
|
339
|
-
node,
|
|
340
|
-
message: 'Generated UltraModern workspaces use direct api/index.ts, shared/api.ts and src/api/* paths; api/effect, api/lambda, shared/effect and src/effect are forbidden.'
|
|
341
|
-
});
|
|
342
|
-
reportProgramPattern(context, node, source, /@modern-js\/plugin-bff\/hono-server/u, 'UltraModern API workspaces must not import Hono server helpers; use @modern-js/plugin-bff/effect-edge and HttpApi.');
|
|
343
|
-
reportProgramPattern(context, node, source, /\bruntimeFramework\s*(?::|=)\s*['"]hono['"]/u, 'UltraModern API apps must use bff.runtimeFramework: "effect".');
|
|
344
|
-
reportProgramPattern(context, node, source, /(?:from|import)\s*['"][^'"]*(?:api\/effect|shared\/effect)[^'"]*['"]|shared-effect-api/u, 'Import API code from direct api/index.ts, shared/api.ts or src/api/* paths, not api/effect, shared/effect or shared Effect API packages.');
|
|
345
|
-
reportProgramPattern(context, node, source, /\bstrictEffectApproach\s*(?::|=)\s*false\b/u, 'UltraModern API apps must keep strictEffectApproach enabled.');
|
|
346
|
-
if (isApiEntryFile(filename)) {
|
|
347
|
-
reportMissingProgramPattern(context, node, source, /\bdefineEffectBff\b/u, 'Generated API entries must export defineEffectBff(...).');
|
|
348
|
-
reportMissingProgramPattern(context, node, source, /\bHttpApiBuilder\b/u, 'Generated API entries must implement handlers through HttpApiBuilder.');
|
|
349
|
-
reportMissingProgramPattern(context, node, source, /\bLayer\b/u, 'Generated API entries must compose dependencies with Effect Layer.');
|
|
350
|
-
reportMissingProgramPattern(context, node, source, /from\s+['"]\.\.\/shared\/api\.ts['"]/u, 'Generated API entries must import the contract from ../shared/api.ts.');
|
|
351
|
-
}
|
|
352
|
-
if (isSharedApiContractFile(filename)) {
|
|
353
|
-
reportMissingProgramPattern(context, node, source, /\bHttpApi\.make\b/u, 'Generated shared API contracts must declare an HttpApi contract.');
|
|
354
|
-
reportMissingProgramPattern(context, node, source, /\bHttpApiGroup\.make\b/u, 'Generated shared API contracts must declare HttpApi groups.');
|
|
355
|
-
reportMissingProgramPattern(context, node, source, /\bHttpApiEndpoint\./u, 'Generated shared API contracts must declare endpoints through HttpApiEndpoint.');
|
|
356
|
-
reportMissingProgramPattern(context, node, source, /\bSchema\./u, 'Generated shared API contracts must model request, response and error shapes with Schema.');
|
|
357
|
-
}
|
|
358
|
-
if (!apiFile) return;
|
|
359
|
-
reportProgramPattern(context, node, source, /\bnew\s+Response\s*\(|\bResponse\.json\s*\(/u, 'API modules must not hand-build Response objects; model endpoints through Effect HttpApi and schemas.');
|
|
360
|
-
reportProgramPattern(context, node, source, /\b(?:request|req)\.(?:json|text|formData|arrayBuffer)\s*\(/u, 'API modules must not manually parse request bodies; use HttpApiEndpoint payload/query/params schemas.');
|
|
361
|
-
reportProgramPattern(context, node, source, /\bexport\s+const\s+handler\b|\bexport\s+default\s+async\b/u, 'API modules must not export raw request handlers; export defineEffectBff(...) from api/index.ts.');
|
|
362
|
-
reportProgramPattern(context, node, source, /\bcreateHandler\s*[:=]\s*(?!defineEffectBff\b)/u, 'API modules must not define unbranded handler factories; use defineEffectBff(...).');
|
|
363
|
-
reportProgramPattern(context, node, source, /\bSchema\.(?:UnknownFromJsonString|Unknown|Any)\b/u, 'API modules must use concrete request, response and error schemas; Schema.UnknownFromJsonString, Schema.Unknown and Schema.Any are forbidden in UltraModern API code.');
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
});
|
|
1
|
+
import { createNoHardcodedJsxTextRule } from "./oxlint-plugin/rules/no-hardcoded-jsx-text.js";
|
|
2
|
+
import { createNoLegacyMfBoundaryAttributesRule } from "./oxlint-plugin/rules/no-legacy-mf-boundary-attributes.js";
|
|
3
|
+
import { createNoLiteralVisibleJsxAttributesRule } from "./oxlint-plugin/rules/no-literal-visible-jsx-attributes.js";
|
|
4
|
+
import { createNoManualLocaleCopyBranchingRule } from "./oxlint-plugin/rules/no-manual-locale-copy-branching.js";
|
|
5
|
+
import { createNoSplitTranslationKeysRule } from "./oxlint-plugin/rules/no-split-translation-keys.js";
|
|
6
|
+
import { createStrictEffectApiBoundariesRule } from "./oxlint-plugin/rules/strict-effect-api-boundaries.js";
|
|
7
|
+
export * from "./oxlint-plugin/ast.js";
|
|
8
|
+
export * from "./oxlint-plugin/options.js";
|
|
9
|
+
export * from "./oxlint-plugin/rules/no-hardcoded-jsx-text.js";
|
|
10
|
+
export * from "./oxlint-plugin/rules/no-legacy-mf-boundary-attributes.js";
|
|
11
|
+
export * from "./oxlint-plugin/rules/no-literal-visible-jsx-attributes.js";
|
|
12
|
+
export * from "./oxlint-plugin/rules/no-manual-locale-copy-branching.js";
|
|
13
|
+
export * from "./oxlint-plugin/rules/no-split-translation-keys.js";
|
|
14
|
+
export * from "./oxlint-plugin/rules/strict-effect-api-boundaries.js";
|
|
15
|
+
export * from "./oxlint-plugin/types.js";
|
|
368
16
|
const oxlint_plugin_plugin = {
|
|
369
17
|
meta: {
|
|
370
18
|
name: 'ultramodern'
|
|
@@ -24,4 +24,4 @@ const runSingleAppI18nCheck = ({ cwd = process.cwd(), targets = [
|
|
|
24
24
|
const main = ()=>{
|
|
25
25
|
process.exitCode = runSingleAppI18nCheck();
|
|
26
26
|
};
|
|
27
|
-
export {
|
|
27
|
+
export { main, runSingleAppI18nCheck };
|
|
@@ -143,4 +143,4 @@ const runWorkspaceSourceCheck = ({ cwd = process.cwd(), sourceRoots = [
|
|
|
143
143
|
const main = ()=>{
|
|
144
144
|
process.exitCode = runWorkspaceSourceCheck();
|
|
145
145
|
};
|
|
146
|
-
export {
|
|
146
|
+
export { main, runWorkspaceSourceCheck };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { API_ENTRY_PATTERN, API_SOURCE_FILE_PATTERN, FORBIDDEN_GENERATED_EFFECT_PATH_PATTERN, LETTER_PATTERN, SHARED_API_CONTRACT_PATTERN } from "./options.js";
|
|
3
|
+
const isRecord = (value)=>Boolean(value) && 'object' == typeof value && !Array.isArray(value);
|
|
4
|
+
const asStringArray = (value, fallback)=>Array.isArray(value) && value.every((item)=>'string' == typeof item) ? value : fallback;
|
|
5
|
+
const normalizeVisibleText = (value)=>value.replaceAll(/\s+/gu, ' ').trim();
|
|
6
|
+
const hasLetters = (value)=>LETTER_PATTERN.test(value);
|
|
7
|
+
const getNodeName = (node)=>{
|
|
8
|
+
if (!node) return;
|
|
9
|
+
if ('string' == typeof node.name) return node.name;
|
|
10
|
+
if ('JSXIdentifier' === node.type && isRecord(node.name) && 'string' == typeof node.name.name) return node.name.name;
|
|
11
|
+
if ('JSXIdentifier' === node.type && 'string' == typeof node.name) return node.name;
|
|
12
|
+
if (('JSXMemberExpression' === node.type || 'MemberExpression' === node.type) && isRecord(node.property) && true !== node.computed) {
|
|
13
|
+
const objectName = getNodeName(node.object);
|
|
14
|
+
const propertyName = getNodeName(node.property);
|
|
15
|
+
return objectName && propertyName ? `${objectName}.${propertyName}` : propertyName;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const getJsxElementName = (node)=>{
|
|
19
|
+
if (node?.type !== 'JSXElement') return;
|
|
20
|
+
return getNodeName(node.openingElement?.name);
|
|
21
|
+
};
|
|
22
|
+
const hasAllowedElementAncestor = (node, allowedElements)=>{
|
|
23
|
+
let current = node;
|
|
24
|
+
while(current){
|
|
25
|
+
const elementName = getJsxElementName(current);
|
|
26
|
+
if (elementName && allowedElements.has(elementName)) return true;
|
|
27
|
+
current = current.parent;
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
const getTemplateLiteralValue = (node)=>{
|
|
32
|
+
if ('TemplateLiteral' !== node.type || (node.expressions?.length ?? 0) > 0) return;
|
|
33
|
+
const quasi = node.quasis?.[0];
|
|
34
|
+
if (!isRecord(quasi?.value)) return;
|
|
35
|
+
const cooked = quasi.value.cooked;
|
|
36
|
+
const raw = quasi.value.raw;
|
|
37
|
+
return 'string' == typeof cooked ? cooked : 'string' == typeof raw ? raw : void 0;
|
|
38
|
+
};
|
|
39
|
+
const getStringLiteralValue = (node)=>{
|
|
40
|
+
if (!node) return;
|
|
41
|
+
if (('Literal' === node.type || 'StringLiteral' === node.type) && 'string' == typeof node.value) return node.value;
|
|
42
|
+
return getTemplateLiteralValue(node);
|
|
43
|
+
};
|
|
44
|
+
const expressionStringValue = (node)=>getStringLiteralValue(node?.type === 'JSXExpressionContainer' ? node.expression : node);
|
|
45
|
+
const getLine = (node)=>node.loc?.start?.line;
|
|
46
|
+
const hasIgnoreComment = (node, context, pattern)=>{
|
|
47
|
+
const sourceCode = context.getSourceCode?.();
|
|
48
|
+
const nodeLine = getLine(node);
|
|
49
|
+
if (!sourceCode?.getAllComments || void 0 === nodeLine) return false;
|
|
50
|
+
return sourceCode.getAllComments().some((comment)=>{
|
|
51
|
+
const commentValue = String(comment.value ?? '');
|
|
52
|
+
if (!pattern.test(commentValue)) return false;
|
|
53
|
+
const startLine = comment.loc?.start?.line;
|
|
54
|
+
const endLine = comment.loc?.end?.line ?? startLine;
|
|
55
|
+
return void 0 !== startLine && void 0 !== endLine && startLine <= nodeLine + 1 && endLine >= nodeLine - 1;
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
const getIgnorePattern = (options)=>new RegExp(options.ignoreCommentPattern, 'u');
|
|
59
|
+
const reportVisibleText = (context, node, text)=>{
|
|
60
|
+
context.report({
|
|
61
|
+
node,
|
|
62
|
+
message: `Move user-visible JSX text to locale resources: ${JSON.stringify(text)}`
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const getSourceText = (context, node)=>context.getSourceCode?.().getText?.(node) ?? context.getSourceCode?.().text ?? '';
|
|
66
|
+
const normalizeFilename = (filePath)=>(filePath ?? '').replaceAll('\\', '/');
|
|
67
|
+
const isApiSourceFile = (filePath)=>API_SOURCE_FILE_PATTERN.test(normalizeFilename(filePath));
|
|
68
|
+
const isForbiddenGeneratedEffectPath = (filePath)=>FORBIDDEN_GENERATED_EFFECT_PATH_PATTERN.test(normalizeFilename(filePath));
|
|
69
|
+
const isApiEntryFile = (filePath)=>API_ENTRY_PATTERN.test(normalizeFilename(filePath));
|
|
70
|
+
const isSharedApiContractFile = (filePath)=>SHARED_API_CONTRACT_PATTERN.test(normalizeFilename(filePath));
|
|
71
|
+
const getCallExpressionName = (node)=>getNodeName(node);
|
|
72
|
+
const reportProgramPattern = (context, node, source, pattern, message)=>{
|
|
73
|
+
if (pattern.test(source)) context.report({
|
|
74
|
+
node,
|
|
75
|
+
message
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
const reportMissingProgramPattern = (context, node, source, pattern, message)=>{
|
|
79
|
+
if (!pattern.test(source)) context.report({
|
|
80
|
+
node,
|
|
81
|
+
message
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export { asStringArray, expressionStringValue, getCallExpressionName, getIgnorePattern, getLine, getNodeName, getSourceText, getStringLiteralValue, hasAllowedElementAncestor, hasIgnoreComment, hasLetters, isApiEntryFile, isApiSourceFile, isForbiddenGeneratedEffectPath, isRecord, isSharedApiContractFile, normalizeFilename, normalizeVisibleText, reportMissingProgramPattern, reportProgramPattern, reportVisibleText };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { asStringArray, isRecord } from "./ast.js";
|
|
3
|
+
const commonOptionsSchema = {
|
|
4
|
+
type: 'object',
|
|
5
|
+
properties: {
|
|
6
|
+
allowElements: {
|
|
7
|
+
type: 'array',
|
|
8
|
+
items: {
|
|
9
|
+
type: 'string'
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
ignoreCommentPattern: {
|
|
13
|
+
type: 'string'
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
additionalProperties: false
|
|
17
|
+
};
|
|
18
|
+
const attributeOptionsSchema = {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
...commonOptionsSchema.properties,
|
|
22
|
+
visibleAttributes: {
|
|
23
|
+
type: 'array',
|
|
24
|
+
items: {
|
|
25
|
+
type: 'string'
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
additionalProperties: false
|
|
30
|
+
};
|
|
31
|
+
const translationOptionsSchema = {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
translationFunctions: {
|
|
35
|
+
type: 'array',
|
|
36
|
+
items: {
|
|
37
|
+
type: 'string'
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
additionalProperties: false
|
|
42
|
+
};
|
|
43
|
+
const DEFAULT_VISIBLE_ATTRIBUTES = [
|
|
44
|
+
'aria-label',
|
|
45
|
+
"aria-description",
|
|
46
|
+
"aria-roledescription",
|
|
47
|
+
'aria-valuetext',
|
|
48
|
+
'alt',
|
|
49
|
+
'placeholder',
|
|
50
|
+
'title'
|
|
51
|
+
];
|
|
52
|
+
const DEFAULT_ALLOWED_ELEMENTS = [
|
|
53
|
+
'code',
|
|
54
|
+
'kbd',
|
|
55
|
+
'samp'
|
|
56
|
+
];
|
|
57
|
+
const DEFAULT_TRANSLATION_FUNCTIONS = [
|
|
58
|
+
't'
|
|
59
|
+
];
|
|
60
|
+
const DEFAULT_IGNORE_COMMENT_PATTERN = 'i18n-ignore';
|
|
61
|
+
const LETTER_PATTERN = /\p{L}/u;
|
|
62
|
+
const SPLIT_TRANSLATION_KEY_PATTERN = /\.(?:prefix|suffix|before|after)$/u;
|
|
63
|
+
const API_SOURCE_FILE_PATTERN = /(?:^|\/)(?:api\/|shared\/api\.[cm]?[jt]sx?$)/u;
|
|
64
|
+
const FORBIDDEN_GENERATED_EFFECT_PATH_PATTERN = /(?:^|\/)(?:(?:apps|verticals)\/[^/]+\/(?:api\/(?:effect|lambda)|shared\/effect|src\/effect))(?:\/|$)/u;
|
|
65
|
+
const API_ENTRY_PATTERN = /(?:^|\/)(?:apps|verticals)\/[^/]+\/api\/index\.[cm]?[jt]sx?$/u;
|
|
66
|
+
const SHARED_API_CONTRACT_PATTERN = /(?:^|\/)(?:apps|verticals)\/[^/]+\/shared\/api\.[cm]?[jt]sx?$/u;
|
|
67
|
+
const getCommonRuleOption = (context, defaults)=>{
|
|
68
|
+
const options = context.options?.[0];
|
|
69
|
+
if (!isRecord(options)) return defaults;
|
|
70
|
+
return {
|
|
71
|
+
allowElements: asStringArray(options.allowElements, defaults.allowElements),
|
|
72
|
+
ignoreCommentPattern: 'string' == typeof options.ignoreCommentPattern ? options.ignoreCommentPattern : defaults.ignoreCommentPattern
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const getAttributeRuleOption = (context, defaults)=>{
|
|
76
|
+
const options = context.options?.[0];
|
|
77
|
+
const commonOptions = getCommonRuleOption(context, defaults);
|
|
78
|
+
return {
|
|
79
|
+
...commonOptions,
|
|
80
|
+
visibleAttributes: isRecord(options) ? asStringArray(options.visibleAttributes, defaults.visibleAttributes) : defaults.visibleAttributes
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const getSplitTranslationKeyRuleOption = (context, defaults)=>{
|
|
84
|
+
const options = context.options?.[0];
|
|
85
|
+
if (!isRecord(options)) return defaults;
|
|
86
|
+
return {
|
|
87
|
+
translationFunctions: asStringArray(options.translationFunctions, defaults.translationFunctions)
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export { API_ENTRY_PATTERN, API_SOURCE_FILE_PATTERN, DEFAULT_ALLOWED_ELEMENTS, DEFAULT_IGNORE_COMMENT_PATTERN, DEFAULT_TRANSLATION_FUNCTIONS, DEFAULT_VISIBLE_ATTRIBUTES, FORBIDDEN_GENERATED_EFFECT_PATH_PATTERN, LETTER_PATTERN, SHARED_API_CONTRACT_PATTERN, SPLIT_TRANSLATION_KEY_PATTERN, attributeOptionsSchema, commonOptionsSchema, getAttributeRuleOption, getCommonRuleOption, getSplitTranslationKeyRuleOption, translationOptionsSchema };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { expressionStringValue, getIgnorePattern, hasAllowedElementAncestor, hasIgnoreComment, hasLetters, normalizeVisibleText, reportVisibleText } from "../ast.js";
|
|
3
|
+
import { DEFAULT_ALLOWED_ELEMENTS, DEFAULT_IGNORE_COMMENT_PATTERN, commonOptionsSchema, getCommonRuleOption } from "../options.js";
|
|
4
|
+
const expressionVisibleText = (node)=>{
|
|
5
|
+
const text = expressionStringValue(node);
|
|
6
|
+
if (void 0 !== text) {
|
|
7
|
+
const visibleText = normalizeVisibleText(text);
|
|
8
|
+
return visibleText && hasLetters(visibleText) ? text : void 0;
|
|
9
|
+
}
|
|
10
|
+
if (node?.type === 'ConditionalExpression') return expressionVisibleText(node.consequent) ?? expressionVisibleText(node.alternate);
|
|
11
|
+
};
|
|
12
|
+
const createNoHardcodedJsxTextRule = ()=>({
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description: 'Disallow literal user-visible text in JSX children in UltraModern generated apps.'
|
|
17
|
+
},
|
|
18
|
+
schema: [
|
|
19
|
+
commonOptionsSchema
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
create (context) {
|
|
23
|
+
const options = getCommonRuleOption(context, {
|
|
24
|
+
allowElements: DEFAULT_ALLOWED_ELEMENTS,
|
|
25
|
+
ignoreCommentPattern: DEFAULT_IGNORE_COMMENT_PATTERN
|
|
26
|
+
});
|
|
27
|
+
const allowedElements = new Set(options.allowElements);
|
|
28
|
+
const ignorePattern = getIgnorePattern(options);
|
|
29
|
+
const shouldSkipNode = (node)=>hasAllowedElementAncestor(node, allowedElements) || hasIgnoreComment(node, context, ignorePattern);
|
|
30
|
+
return {
|
|
31
|
+
JSXText (node) {
|
|
32
|
+
const text = normalizeVisibleText(String(node.value ?? ''));
|
|
33
|
+
if (!text || !hasLetters(text) || shouldSkipNode(node)) return;
|
|
34
|
+
reportVisibleText(context, node, text);
|
|
35
|
+
},
|
|
36
|
+
JSXExpressionContainer (node) {
|
|
37
|
+
if (node.parent?.type !== 'JSXElement' && node.parent?.type !== 'JSXFragment') return;
|
|
38
|
+
const text = normalizeVisibleText(expressionVisibleText(node.expression) ?? '');
|
|
39
|
+
if (!text || !hasLetters(text) || shouldSkipNode(node)) return;
|
|
40
|
+
reportVisibleText(context, node, text);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
export { createNoHardcodedJsxTextRule };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { getNodeName } from "../ast.js";
|
|
3
|
+
const createNoLegacyMfBoundaryAttributesRule = ()=>({
|
|
4
|
+
meta: {
|
|
5
|
+
type: 'problem',
|
|
6
|
+
docs: {
|
|
7
|
+
description: 'Disallow legacy Module Federation boundary attributes in generated UltraModern workspaces.'
|
|
8
|
+
},
|
|
9
|
+
schema: []
|
|
10
|
+
},
|
|
11
|
+
create (context) {
|
|
12
|
+
return {
|
|
13
|
+
JSXAttribute (node) {
|
|
14
|
+
const attributeName = getNodeName(node.name);
|
|
15
|
+
if ('data-mf-boundary' !== attributeName && 'data-mf-remote' !== attributeName && 'data-mf-expose' !== attributeName) return;
|
|
16
|
+
context.report({
|
|
17
|
+
node,
|
|
18
|
+
message: 'Use data-modern-boundary-id and data-modern-mf-expose instead of legacy data-mf-* boundary attributes.'
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
export { createNoLegacyMfBoundaryAttributesRule };
|