create: function(context) {
function isInvalidEntity(node) {
var configuration = context.options[0] || {};
var entities = configuration.forbid || DEFAULTS;
// HTML entites are already escaped in node.value (as well as node.raw),
// so pull the raw text from context.getSourceCode()
for (var i = node.loc.start.line; i <= node.loc.end.line; i++) {
var rawLine = context.getSourceCode().lines[i - 1];
var start = 0;
var end = rawLine.length;
if (i === node.loc.start.line) {
start = node.loc.start.column;
}
if (i === node.loc.end.line) {
end = node.loc.end.column;
}
rawLine = rawLine.substring(start, end);
for (var j = 0; j < entities.length; j++) {
for (var index = 0; index < rawLine.length; index++) {
var c = rawLine[index];
if (c === entities[j]) {
context.report({
loc: {line: i, column: start + index},
message: 'HTML entities must be escaped.',
node: node
});
}
}
}
}
}
return {
Literal: function(node) {
if (node.type === 'Literal' && node.parent.type === 'JSXElement') {
if (isInvalidEntity(node)) {
context.report(node, 'HTML entities must be escaped.');
}
}
}
};
This condition always evaluates to false:
if (isInvalidEntity(node)) {
context.report(node, 'HTML entities must be escaped.');
}
Likely, the original intent was to return true or false from isInvalidEntity, but then the code was rewritten so that isInvalidEntity reports errors on its own. So now the more correct name for it would be reportInvalidEntity function than isInvalidEntity. And, of course, the no-op if block should be removed.
Good catch!
Fixed in #1227
Most helpful comment
Fixed in #1227