Repository: ota-meshi/eslint-plugin-regexp (ts)

Issue:
`regexp/negation`: Strange suggested fix for Unicode property escapes
See the following:

```js
var foo = /[^\P{Ll}]/u;
```

![image](https://user-images.githubusercontent.com/20878432/124464437-7b644800-dd94-11eb-9061-9e7dd5c579e1.png)

The fix is a little longer than expected.

Pull request:
Fixed `regexp/negation` suggested fix
This fixes #267.

Patch:
diff --git a/.github/workflows/NodeCI.yml b/.github/workflows/NodeCI.yml
index ac07536..79a4e00 100644
--- a/.github/workflows/NodeCI.yml
+++ b/.github/workflows/NodeCI.yml
@@ -59,7 +59,7 @@ jobs:
             - name: Test
               run: npm run test:nyc
             - name: Coveralls GitHub Action
-              uses: coverallsapp/github-action@v1.1.2
+              uses: coverallsapp/github-action@1.1.3
               with:
                   github-token: ${{ secrets.GITHUB_TOKEN }}
     update:
diff --git a/lib/rules/negation.ts b/lib/rules/negation.ts
index 2753755..4fe008c 100644
--- a/lib/rules/negation.ts
+++ b/lib/rules/negation.ts
@@ -64,28 +64,14 @@ export default createRule("negation", {
 function getNegationText(
     node: EscapeCharacterSet | UnicodePropertyCharacterSet,
 ) {
-    let text: string
-    if (node.kind === "digit") {
-        text = "d"
-    } else if (node.kind === "space") {
-        text = "s"
-    } else if (node.kind === "word") {
-        text = "w"
-    } else if (node.kind === "property") {
-        text = "p"
+    // they are all of the form: /\\[dswp](?:\{[^{}]+\})?/
+    let kind = node.raw[1]
+
+    if (kind.toLowerCase() === kind) {
+        kind = kind.toUpperCase()
     } else {
-        throw new Error(`unknown kind:${node.kind}`)
-    }
-    if (!node.negate) {
-        text = text.toUpperCase()
-    }
-    if (node.kind === "property") {
-        if (node.value != null) {
-            text += `{${node.key}=${node.value}}`
-        } else {
-            text += `{${node.key}}`
-        }
+        kind = kind.toLowerCase()
     }
 
-    return `\\${text}`
+    return `\\${kind}${node.raw.slice(2)}`
 }
diff --git a/lib/rules/sort-alternatives.ts b/lib/rules/sort-alternatives.ts
index 40362f0..af88ffa 100644
--- a/lib/rules/sort-alternatives.ts
+++ b/lib/rules/sort-alternatives.ts
@@ -204,7 +204,7 @@ function trySortNumberAlternatives(alternatives: Alternative[]): void {
     {
         let start = 0
         for (let i = 0; i < alternatives.length; i++) {
-            if (!/^0|[1-9]\d*$/.test(alternatives[i].raw)) {
+            if (!/^(?:0|[1-9]\d*)$/.test(alternatives[i].raw)) {
                 if (start < i) {
                     numberRanges.push([start, i])
                 }
diff --git a/package-lock.json b/package-lock.json
index 38d2ad1..68cbb2e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1327,9 +1327,9 @@
             }
         },
         "@types/estree": {
-            "version": "0.0.49",
-            "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.49.tgz",
-            "integrity": "sha512-K1AFuMe8a+pXmfHTtnwBvqoEylNKVeaiKYkjmcEAdytMQVJ/i9Fu7sc13GxgXdO49gkE7Hy8SyJonUZUn+eVaw==",
+            "version": "0.0.50",
+            "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.50.tgz",
+            "integrity": "sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw==",
             "dev": true
         },
         "@types/glob": {
diff --git a/package.json b/package.json
index 3790304..98bf7cb 100644
--- a/package.json
+++ b/package.json
@@ -52,7 +52,7 @@
         "@ota-meshi/eslint-plugin": "^0.7.0",
         "@types/eslint": "^7.2.0",
         "@types/eslint-scope": "^3.7.0",
-        "@types/estree": "^0.0.49",
+        "@types/estree": "^0.0.50",
         "@types/mocha": "^8.0.0",
         "@types/node": "^14.14.39",
         "@typescript-eslint/eslint-plugin": "^4.14.0",


Test patch:
diff --git a/tests/lib/rules/negation.ts b/tests/lib/rules/negation.ts
index dab7861..cdd1097 100644
--- a/tests/lib/rules/negation.ts
+++ b/tests/lib/rules/negation.ts
@@ -87,6 +87,13 @@ tester.run("negation", rule as any, {
                 "Unexpected negated character class. Use '\\p{Script=Hiragana}' instead.",
             ],
         },
+        {
+            code: String.raw`/[^\P{Ll}]/u;`,
+            output: String.raw`/\p{Ll}/u;`,
+            errors: [
+                "Unexpected negated character class. Use '\\p{Ll}' instead.",
+            ],
+        },
         {
             code: String.raw`const s ="[^\\w]"
             new RegExp(s)`,