804b9bf120
- Bump `eslint`, `typescript-eslint` and `eslint-plugin-unicorn` (to v68), and configure the rules added in unicorn v66/v67/v68. - Remove `eslint-plugin-github` and its workarounds (rules, type stub, pnpm peer override, in-code `eslint-disable` comments); the rules worth keeping are covered by `unicorn` equivalents. - Apply the resulting fixes and autofixes across the JS codebase. _Prepared with Claude (Opus 4.8)._ --------- Signed-off-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
// MIT license, Copyright (c) GitHub, Inc.
|
|
// https://github.com/github/eslint-plugin-github/blob/main/lib/rules/unescaped-html-literal.js
|
|
import type {JSRuleDefinition, JSRuleDefinitionTypeOptions} from 'eslint';
|
|
|
|
const htmlOpenTag = /^\s*<[a-zA-Z]/;
|
|
|
|
const rule: JSRuleDefinition<JSRuleDefinitionTypeOptions> = {
|
|
meta: {
|
|
type: 'problem',
|
|
messages: {
|
|
unescapedHtmlLiteral: 'Unescaped HTML literal. Use html`` tag template literal for secure escaping.',
|
|
},
|
|
},
|
|
|
|
create: (context) => ({
|
|
Literal(node) {
|
|
if (typeof node.value !== 'string' || !htmlOpenTag.test(node.value)) return;
|
|
|
|
context.report({
|
|
node,
|
|
messageId: 'unescapedHtmlLiteral',
|
|
});
|
|
},
|
|
TemplateLiteral(node) {
|
|
const templateStart = node.quasis[0]?.value.raw;
|
|
if (!templateStart || !htmlOpenTag.test(templateStart)) return;
|
|
|
|
const parent = node.parent;
|
|
if (parent?.type === 'TaggedTemplateExpression' && parent.tag.type === 'Identifier' && parent.tag.name === 'html') return;
|
|
|
|
context.report({
|
|
node,
|
|
messageId: 'unescapedHtmlLiteral',
|
|
});
|
|
},
|
|
}),
|
|
};
|
|
|
|
export default rule;
|