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

Add eslint-plugin-regexp #142

Merged
merged 5 commits into from Sep 14, 2021
Merged

Add eslint-plugin-regexp #142

merged 5 commits into from Sep 14, 2021

Conversation

ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented Sep 14, 2021

Which issue, if any, is this issue related to?

Close #141

Is there anything in the PR that needs further explanation?

This change is created by:

  • the npm i eslint-plugin-regexp command
  • a few additions to the .eslintrc.js file.

See also https://www.npmjs.com/package/eslint-plugin-regexp

This change is created by:
- the `npm i eslint-plugin-regexp` command
- a few additions to the `.eslintrc.js` file.

Close #141
.eslintrc.js Outdated
@@ -113,5 +114,8 @@ module.exports = {
"prefer-template": "error",
"sort-requires/sort-requires": "error",
strict: ["error", "global"],

// Prefer code readability over a bit performance improvement.
"regexp/no-unused-capturing-group": "off",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[note] There is room for discussion about disabling regexp/no-unused-capturing-group. Please give me feedback if any.

See also #141 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?: is readable...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0-9 vs \d is not readable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexander-akait Thanks for the feedback!

?: is readable...

Did you mean we should enable regexp/no-unused-capturing-group?

0-9 vs \d is not readable

Did you mean we should disable prefer-d? This rule is for code style, so it seems acceptable to me that we can disable it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean we should enable regexp/no-unused-capturing-group?

Yes, I found perf is better here, ?: is not hard to read

Did you mean we should disable prefer-d? This rule is for code style, so it seems acceptable to me that we can disable it.

It is just my opinion, better to use explicit in some cases

/cc @hudochenkov @jeddy3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About prefer-d, the following demo in stylelint/stylelint#5516 may be helpful.

image

https://github.com/stylelint/stylelint/pull/5516/files#diff-bc86d8e365c9e39833c23e23b86683913daa42ccf65be917f15f1cab7f3c6659

Personally, I feel [0-9A-Za-z] is a bit more readable than [\dA-Za-z].

-const HEX = /^#[0-9A-Za-z]+/;
+const HEX = /^#[\dA-Za-z]+/;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's turn off prefer-d for now. We can always revisit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's turn off prefer-d for now.

Done 7d67470.


What about regexp/no-unused-capturing-group?

image

https://github.com/stylelint/stylelint/pull/5516/files#diff-0aada42ad688056595a24011819e7047990bbcf88104577fc706851596ce7263

In this case, ?: surely seems a bit hard to read, but performance is important too.

-const HEX = /^#([\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i;
+const HEX = /^#(?:[\da-f]{3,4}|[\da-f]{6}|[\da-f]{8})$/i;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's favour performance for now. We can always change back if it proves an issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeddy3 Thanks for the advice. Done 9047b8f. 👍🏼

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to include regexp in the plugins array?

@ybiquitous
Copy link
Member Author

@jeddy3 No, plugin:regexp/recommended includes plugins: ["regexp"]. See below:

https://github.com/ota-meshi/eslint-plugin-regexp/blob/v1.1.0/lib/configs/recommended.ts#L2

Also, in the PR #133, we will remove the needless plugins:
https://github.com/stylelint/eslint-config-stylelint/pull/133/files#r641133044

@jeddy3
Copy link
Member

jeddy3 commented Sep 14, 2021

@jeddy3 No, plugin:regexp/recommended includes plugins: ["regexp"].

Whoops, I knew that... it's the same approach we're adovating for in 14.0.0.

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

It's a major change, so let's release as 14.0.0.

@ybiquitous ybiquitous mentioned this pull request Sep 14, 2021
5 tasks
@jeddy3 jeddy3 merged commit 64d409b into master Sep 14, 2021
@jeddy3 jeddy3 deleted the add-eslint-plugin-regexp branch September 14, 2021 17:56
ybiquitous added a commit that referenced this pull request Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add eslint-plugin-regexp
4 participants