Add disallowMultipleSpacesInRegularExpressionLiterals lint rule #121
Add disallowMultipleSpacesInRegularExpressionLiterals lint rule #121
Conversation
enter(path: Path): AnyNode { | ||
const {context, node} = path; | ||
|
||
const multipleSpacesPattern = /( {2,})(?: [+*{?]|[^+*{?]|$)/gu; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you hoist this regex to the top level of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good. I fixed.
This is missing normal regex literals. Is there any reason you didn't add a handler for |
Sorry, it is the lack of consideration |
(node.type === 'ExpressionStatement' && | ||
node.expression.type === 'RegExpLiteral' && | ||
multipleSpacesPattern.test(node.expression.pattern)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be:
(node.type === 'ExpressionStatement' && | |
node.expression.type === 'RegExpLiteral' && | |
multipleSpacesPattern.test(node.expression.pattern)) | |
(node.type === 'RegExpLiteral' && | |
multipleSpacesPattern.test(node.pattern)) |
It's overly specific because ExpressionStatement
is only used as the wrapper statement for an expression. A regexp should never appear on a line by itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see and accept suggestion, also fix conflict as soon as possible.
…pacesInRegularExpressionLiterals.ts Co-Authored-By: Sebastian <853712+sebmck@users.noreply.github.com>
@sebmck
It seems that all tests passed in local. |
Might be a transient error, nothing here that should cause it. Let me rerun CI and I'll see if it passes. |
Looks to be passing now, thank you! |
Add no-regex-spaces lint rule on #94