Skip to content
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

tools: add and apply eslint rule no-regex-spaces #26409

Closed
wants to merge 1 commit into from

Conversation

gengjiawen
Copy link
Member

Expert from https://eslint.org/docs/rules/no-regex-spaces:

Regular expressions can be very complex and difficult to understand, which is why it’s important to keep them as simple as possible in order to avoid mistakes. One of the more error-prone things you can do with a regular expression is to use more than one space, such as:

var re = /foo   bar/;

In this regular expression, it’s very hard to tell how many spaces are intended to be matched. It’s better to use only one space and then specify how many spaces are expected, such as:

var re = /foo {3}bar/;

Now it is very clear that three spaces are expected to be matched.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the tools Issues and PRs related to the tools directory. label Mar 3, 2019
@gengjiawen gengjiawen changed the title lint: add and apply eslint rule no-regex-spaces tools: add and apply eslint rule no-regex-spaces Mar 3, 2019
@cjihrig
Copy link
Contributor

cjihrig commented Mar 3, 2019

Personally, I find this less readable.

@gengjiawen
Copy link
Member Author

gengjiawen commented Mar 4, 2019

My main thought is that:

But I am not quite insistent on this. If most @nodejs/lint members not a a fan of this rule, I will drop this pr (Not quite sure how to start a poll, use emoji ?).

@Trott
Copy link
Member

Trott commented Mar 4, 2019

(Not quite sure how to start a poll, use emoji ?).

I'd rather we have discussions and avoid polls (meaning that one person giving a good reason for doing or not doing something is better than a dozen people saying "+1" or "-1".).

I'd prefer we don't do this. My feelings aren't strong enough to block it, but:

  • I agree with @cjihrig that it doesn't always improve readability.

  • When a message gets updated, I'd prefer to be able to copy/paste the message rather than have to modify it for the number of spaces.

  • This change could also mess things up when someone looks for usage of a message via grep or similar tool.

That said, I think a few of these would benefit from being changed from regular expressions to calls to String.prototype.includes().

@gengjiawen
Copy link
Member Author

@Trott Most cases involved in this rule looks like can be done using snapshot test (something like https://jestjs.io/docs/en/snapshot-testing). Maybe a different issue though.

I will close this.

@gengjiawen gengjiawen closed this Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants