ota-meshi / eslint-plugin-regexp

ESLint plugin for finding regex mistakes and style guide violations.
https://ota-meshi.github.io/eslint-plugin-regexp/
MIT License
701 stars 10 forks source link

Add `regexp/letter-case`/`unicorn/escape-case` conflict resolution to the doc #743

Open yvele opened 6 months ago

yvele commented 6 months ago

Information:

Description

With this rule elabled:

"regexp/letter-case" : "error"

The following code:

const REG = /\u036F/;

is reported as error:

error '\u036F' is not in lowercase regexp/letter-case

but should be automatically fixed to:

- const REG = /\u036F/;
+ const REG = /\u036f/;

Same problem with the u flag /\u036F/u

Note that the rule doc specifies that:

🔧 This rule is automatically fixable by the --fix CLI option.

yvele commented 6 months ago

Ok I find out that there is a conflict between the regexp/letter-case default options: https://ota-meshi.github.io/eslint-plugin-regexp/rules/letter-case.html#options

{
  "regexp/letter-case": ["error", {
    "unicodeEscape": "lowercase"
  }]
}

And the recommended unicorn/escape-case rule: https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/escape-case.md

Enforces defining escape sequence values with uppercase characters rather than lowercase ones. This promotes readability by making the escaped value more distinguishable from the identifier.

As an example let's see how core-js is doing: https://github.com/zloirock/core-js/blob/f1303f38bd80474f950cadb3e802db1c2618a2c5/tests/eslint/eslint.config.js#L705-L707C21

  // require escape sequences to use uppercase values
  'unicorn/escape-case': ERROR,

  'regexp/letter-case': [ERROR, {
    caseInsensitive: 'lowercase',
    unicodeEscape: 'uppercase',
  }],

Maybe we could explain that conflict in the doc? Because eslint-plugin-unicorn is super widely used.

ota-meshi commented 6 months ago

I welcome pull requests to add notes.