Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
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;
|