New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no-irregular-whitespace: Inside of regexp irregular whitespace #5840
Comments
I actually don't think this is a bug - seems to be working as intended, as the rule states it causes warnings if irregular whitespace characters are found outside of strings or comments. From the docs:
I think that it's not working for your first example because it's a regex literal (not a string). The reason |
Oh sorry, my explanation was lacking. If this is regular behavior, I think this should documentation with incorrect example. Because regexp with |
Got it - I'm going to label this as an enhancement and let's see what @nzakas thinks. Thanks for the issue report! |
Hmm, I cannot find reasons that irregular spaces in strings are good but irregular spaces in regular expressions are bad. And I got aware that template literals have the same issue: /^[\s\ ]*$/ /*error Irregular whitespace not allowed (no-irregular-whitespace)*/
new RegExp(`^[\s\ ]*$`) /*error Irregular whitespace not allowed (no-irregular-whitespace)*/
new RegExp("^[\s\ ]*$") // good. I wish to fix this behavior since this does not have consistency, IMO. What about adding options for each type? {
"no-irregular-whitespace": ["error", {
"skipStrings": false,
"skipTemplates": false,
"skipRegExps": false,
"skipComments": false // "skipComments" exists already.
}]
} In my ideal, all default are |
Irregular whitespace in strings might be intentional for output. No objections to adding the options if @mysticatea wants to as long as the default behavior remains the same. |
I just encountered this bug today and sent a PR for this in #6018. Could you check it? |
Problem: no-irregal-whitespace ignores string literals correctly, but doen't regular expressions. Solution: also check that the node is a regular expression in removeInvalidNodeErrorsInIdentifierOrLiteral().
@rhysd Thank you for the PR 😄. But the consensus on this issue is to add options above. Could you update the PR with the options? |
@mysticatea I'll fix my PR today 👍 |
"skipStrings": false,
"skipTemplates": false, Should we separate these options? I think |
@rhysd If we were designing the rule today, unlikely to find a use case to separate options for string literals from template literals. The reason is to avoid breaking existing behavior, as requested in #5840 (comment). Therefore, I think the default values of the options are as follows: {
"no-irregular-whitespace": ["error", {
"skipStrings": true, // current default is to skip strings
"skipTemplates": false,
"skipRegExps": false,
"skipComments": false // this option already exists
}]
} |
OK, I'll maintain the previous behavior 👍 |
Problem: no-irregal-whitespace ignores string literals correctly, but doen't regular expressions. (eslint#5840) Added below options to no-irregal-whitespace - skipStrings (default: true) - skipRegExps (default: false) - skipTemplates (default: true) Solution: also check that the node is a regular expression in removeInvalidNodeErrorsInIdentifierOrLiteral().
Problem: no-irregal-whitespace ignores string literals correctly, but doen't regular expressions. (eslint#5840) Solution: Also check that the node is a regular expression in removeInvalidNodeErrorsInIdentifierOrLiteral(). Added below options to no-irregal-whitespace - skipStrings (default: true) - skipRegExps (default: false) - skipTemplates (default: false)
) Problem: no-irregal-whitespace ignores string literals correctly, but doen't regular expressions. (eslint#5840) Solution: Also check that the node is a regular expression in removeInvalidNodeErrorsInIdentifierOrLiteral(). Added below options to no-irregal-whitespace - skipStrings (default: true) - skipRegExps (default: false) - skipTemplates (default: false)
) Problem: no-irregal-whitespace ignores string literals correctly, but doen't regular expressions. (eslint#5840) Solution: Also check that the node is a regular expression in removeInvalidNodeErrorsInIdentifierOrLiteral(). Added below options to no-irregal-whitespace - skipStrings (default: true) - skipRegExps (default: false) - skipTemplates (default: false)
) Problem: no-irregal-whitespace ignores string literals correctly, but doen't regular expressions. (eslint#5840) Solution: Also check that the node is a regular expression in removeInvalidNodeErrorsInIdentifierOrLiteral(). Added below options to no-irregal-whitespace - skipStrings (default: true) - skipRegExps (default: false) - skipTemplates (default: false)
) Problem: no-irregal-whitespace ignores string literals correctly, but doen't regular expressions. (eslint#5840) Solution: Also check that the node is a regular expression in removeInvalidNodeErrorsInIdentifierOrLiteral(). Added below options to no-irregal-whitespace - skipStrings (default: true) - skipRegExps (default: false) - skipTemplates (default: false)
) Problem: no-irregal-whitespace ignores string literals correctly, but doen't regular expressions. (eslint#5840) Solution: Also check that the node is a regular expression in removeInvalidNodeErrorsInIdentifierOrLiteral(). Added below options to no-irregal-whitespace - skipStrings (default: true) - skipRegExps (default: false) - skipTemplates (default: false)
What version of ESLint are you using?
2.7.0
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
What did you do? Please include the actual source code causing the issue.
I wrote those code.
What did you expect to happen?
I think this may bug because string literal is ignored on this rule.
If this is not bug, I want documentation or
skipRegexp
option.Note: I can avoid this error with
new RegExp('^[\s\ ]*$')
The text was updated successfully, but these errors were encountered: