Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'Literal[regex]': node => {
const {raw: original, regex} = node;
// Regular Expressions with `u` flag are not well handled by `regexp-tree`
// https://github.com/DmitrySoshnikov/regexp-tree/issues/162
if (regex.flags.includes('u')) {
return;
}
let optimized = original;
try {
optimized = optimize(original).toString();
} catch (_) {}
if (original === optimized) {
return;
}
context.report({
node,
message: '{{original}} can be optimized to {{optimized}}',
data: {
original,
optimized
},
fix: fixer => fixer.replaceText(node, optimized)
});
},