massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / eslint / lib / rules / radix.js
index e322566238809b3b403475d1669b76b8bf598da3..d1b67e5e280b93193e3d23e78c834f0620a38e71 100644 (file)
@@ -82,7 +82,8 @@ module.exports = {
             description: "enforce the consistent use of the radix argument when using `parseInt()`",
             category: "Best Practices",
             recommended: false,
-            url: "https://eslint.org/docs/rules/radix"
+            url: "https://eslint.org/docs/rules/radix",
+            suggestion: true
         },
 
         schema: [
@@ -95,7 +96,8 @@ module.exports = {
             missingParameters: "Missing parameters.",
             redundantRadix: "Redundant radix parameter.",
             missingRadix: "Missing radix parameter.",
-            invalidRadix: "Invalid radix parameter, must be an integer between 2 and 36."
+            invalidRadix: "Invalid radix parameter, must be an integer between 2 and 36.",
+            addRadixParameter10: "Add radix parameter `10` for parsing decimal numbers."
         }
     },
 
@@ -123,7 +125,21 @@ module.exports = {
                     if (mode === MODE_ALWAYS) {
                         context.report({
                             node,
-                            messageId: "missingRadix"
+                            messageId: "missingRadix",
+                            suggest: [
+                                {
+                                    messageId: "addRadixParameter10",
+                                    fix(fixer) {
+                                        const sourceCode = context.getSourceCode();
+                                        const tokens = sourceCode.getTokens(node);
+                                        const lastToken = tokens[tokens.length - 1]; // Parenthesis.
+                                        const secondToLastToken = tokens[tokens.length - 2]; // May or may not be a comma.
+                                        const hasTrailingComma = secondToLastToken.type === "Punctuator" && secondToLastToken.value === ",";
+
+                                        return fixer.insertTextBefore(lastToken, hasTrailingComma ? " 10," : ", 10");
+                                    }
+                                }
+                            ]
                         });
                     }
                     break;