Website Structure
This commit is contained in:
parent
62812f2090
commit
71f0676a62
22365 changed files with 4265753 additions and 791 deletions
54
Frontend-Learner/node_modules/eslint-plugin-unicorn/rules/no-hex-escape.js
generated
vendored
Normal file
54
Frontend-Learner/node_modules/eslint-plugin-unicorn/rules/no-hex-escape.js
generated
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import {replaceTemplateElement} from './fix/index.js';
|
||||
import {isStringLiteral, isRegexLiteral, isTaggedTemplateLiteral} from './ast/index.js';
|
||||
|
||||
const MESSAGE_ID = 'no-hex-escape';
|
||||
const messages = {
|
||||
[MESSAGE_ID]: 'Use Unicode escapes instead of hexadecimal escapes.',
|
||||
};
|
||||
|
||||
function checkEscape(context, node, value) {
|
||||
const fixedValue = value.replaceAll(/(?<=(?:^|[^\\])(?:\\\\)*\\)x/g, 'u00');
|
||||
|
||||
if (value !== fixedValue) {
|
||||
return {
|
||||
node,
|
||||
messageId: MESSAGE_ID,
|
||||
fix: fixer =>
|
||||
node.type === 'TemplateElement'
|
||||
? replaceTemplateElement(node, fixedValue, context, fixer)
|
||||
: fixer.replaceText(node, fixedValue),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/** @param {import('eslint').Rule.RuleContext} context */
|
||||
const create = context => ({
|
||||
Literal(node) {
|
||||
if (isStringLiteral(node) || isRegexLiteral(node)) {
|
||||
return checkEscape(context, node, node.raw);
|
||||
}
|
||||
},
|
||||
TemplateElement(node) {
|
||||
if (isTaggedTemplateLiteral(node.parent, ['String.raw'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
return checkEscape(context, node, node.value.raw);
|
||||
},
|
||||
});
|
||||
|
||||
/** @type {import('eslint').Rule.RuleModule} */
|
||||
const config = {
|
||||
create,
|
||||
meta: {
|
||||
type: 'suggestion',
|
||||
docs: {
|
||||
description: 'Enforce the use of Unicode escapes instead of hexadecimal escapes.',
|
||||
recommended: 'unopinionated',
|
||||
},
|
||||
fixable: 'code',
|
||||
messages,
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
Loading…
Add table
Add a link
Reference in a new issue