All checks were successful
Queue Release Build / prepare (push) Successful in 15s
Deploy Web Apps / deploy (push) Successful in 5m35s
Queue Release Build / build-linux (push) Successful in 24m45s
Queue Release Build / build-windows (push) Successful in 13m52s
Queue Release Build / finalize (push) Successful in 23s
98 lines
3.3 KiB
JavaScript
98 lines
3.3 KiB
JavaScript
// Custom ESLint rules shared across the workspace.
|
||
|
||
const FORBIDDEN_UNICODE_SYMBOLS = Object.freeze([
|
||
{ char: '\u2013', name: 'Unicode en dash (–)', replacement: '-' },
|
||
{ char: '\u2014', name: 'Unicode em dash (—)', replacement: '-' },
|
||
{ char: '\u2026', name: 'Unicode ellipsis (…)', replacement: '...' },
|
||
{ char: '\u2192', name: 'Unicode right arrow (→)', replacement: '->' },
|
||
{ char: '\u2190', name: 'Unicode left arrow (←)', replacement: '<-' },
|
||
{ char: '\u2194', name: 'Unicode left-right arrow (↔)', replacement: '<->' },
|
||
{ char: '\u21d2', name: 'Unicode right double arrow (⇒)', replacement: '=>' },
|
||
{ char: '\u21d0', name: 'Unicode left double arrow (⇐)', replacement: '<=' },
|
||
{ char: '\u21d4', name: 'Unicode left-right double arrow (⇔)', replacement: '<=>' }
|
||
]);
|
||
|
||
function createReplaceFix(range, replacement) {
|
||
return (fixer) => fixer.replaceTextRange(range, replacement);
|
||
}
|
||
|
||
module.exports = {
|
||
rules: {
|
||
'angular-template-spacing': {
|
||
meta: {
|
||
type: 'layout',
|
||
docs: {
|
||
description: 'Enforce spacing between elements and property grouping in Angular templates',
|
||
category: 'Stylistic Issues',
|
||
recommended: true
|
||
},
|
||
fixable: 'whitespace',
|
||
schema: []
|
||
},
|
||
create() {
|
||
// This is a placeholder for custom rule implementation.
|
||
// ESLint's template rules are limited, so manual formatting is recommended.
|
||
return {};
|
||
}
|
||
},
|
||
'no-unicode-symbols': {
|
||
meta: {
|
||
type: 'suggestion',
|
||
docs: {
|
||
description: 'Disallow AI/LLM-style Unicode symbols in source files'
|
||
},
|
||
fixable: 'code',
|
||
hasSuggestions: true,
|
||
schema: [],
|
||
messages: {
|
||
forbiddenSymbol: '{{name}} is not allowed. Use ASCII "{{replacement}}" instead.',
|
||
replaceSymbol: 'Replace with "{{replacement}}"'
|
||
}
|
||
},
|
||
create(context) {
|
||
const sourceCode = context.getSourceCode();
|
||
|
||
return {
|
||
Program() {
|
||
const sourceText = sourceCode.getText();
|
||
|
||
for (const symbol of FORBIDDEN_UNICODE_SYMBOLS) {
|
||
let index = sourceText.indexOf(symbol.char);
|
||
|
||
while (index !== -1) {
|
||
const range = [index, index + symbol.char.length];
|
||
const loc = {
|
||
start: sourceCode.getLocFromIndex(range[0]),
|
||
end: sourceCode.getLocFromIndex(range[1])
|
||
};
|
||
|
||
context.report({
|
||
loc,
|
||
messageId: 'forbiddenSymbol',
|
||
data: {
|
||
name: symbol.name,
|
||
replacement: symbol.replacement
|
||
},
|
||
fix: createReplaceFix(range, symbol.replacement),
|
||
suggest: [
|
||
{
|
||
messageId: 'replaceSymbol',
|
||
data: {
|
||
replacement: symbol.replacement
|
||
},
|
||
fix: createReplaceFix(range, symbol.replacement)
|
||
}
|
||
]
|
||
});
|
||
|
||
index = sourceText.indexOf(symbol.char, index + symbol.char.length);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
}
|
||
}
|
||
},
|
||
FORBIDDEN_UNICODE_SYMBOLS
|
||
};
|