Skip to content

Commit

Permalink
Use in better-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 12, 2023
1 parent ea862e0 commit 45af5cd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions rules/better-regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const cleanRegexp = require('clean-regexp');
const {optimize} = require('regexp-tree');
const escapeString = require('./utils/escape-string.js');
const {newExpressionSelector} = require('./selectors/index.js');

Check failure on line 5 in rules/better-regex.js

View workflow job for this annotation

GitHub Actions / lint-test

'newExpressionSelector' is assigned a value but never used.
const {isStringLiteral} = require('./ast/index.js');
const {isStringLiteral, isNewExpression} = require('./ast/index.js');

const MESSAGE_ID = 'better-regex';
const MESSAGE_ID_PARSE_ERROR = 'better-regex/parse-error';
Expand All @@ -12,8 +12,6 @@ const messages = {
[MESSAGE_ID_PARSE_ERROR]: 'Problem parsing {{original}}: {{error}}',
};

const newRegExp = newExpressionSelector({name: 'RegExp', minimumArguments: 1});

/** @param {import('eslint').Rule.RuleContext} context */
const create = context => {
const {sortCharacterClasses} = context.options[0] || {};
Expand Down Expand Up @@ -80,7 +78,11 @@ const create = context => {
fix: fixer => fixer.replaceText(node, optimized),
});
},
[newRegExp](node) {
NewExpression(node) {
if (!isNewExpression(node, {name: 'RegExp', minimumArguments: 1})) {
return;
}

const [patternNode, flagsNode] = node.arguments;

if (!isStringLiteral(patternNode)) {
Expand Down

0 comments on commit 45af5cd

Please sign in to comment.