Permalink
Cannot retrieve contributors at this time
36 lines (32 sloc)
780 Bytes
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/node_modules/eslint-plugin-github/lib/rules/unescaped-html-literal.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
meta: { | |
type: 'problem', | |
docs: { | |
description: 'disallow unescaped HTML literals', | |
url: require('../url')(module), | |
}, | |
schema: [], | |
}, | |
create(context) { | |
const htmlOpenTag = /^<[a-zA-Z]/ | |
const message = 'Unescaped HTML literal. Use html`` tag template literal for secure escaping.' | |
return { | |
Literal(node) { | |
if (!htmlOpenTag.test(node.value)) return | |
context.report({ | |
node, | |
message, | |
}) | |
}, | |
TemplateLiteral(node) { | |
if (!htmlOpenTag.test(node.quasis[0].value.raw)) return | |
if (!node.parent.tag || node.parent.tag.name !== 'html') { | |
context.report({ | |
node, | |
message, | |
}) | |
} | |
}, | |
} | |
}, | |
} |