massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / eslint / lib / rules / no-useless-computed-key.js
index b5e53174e42be7b3edfdfe766094b95ef50bdad8..a1cacc296129feae1fb38fe6ddc0d33835e61056 100644 (file)
@@ -8,15 +8,12 @@
 // Requirements
 //------------------------------------------------------------------------------
 
-const lodash = require("lodash");
 const astUtils = require("./utils/ast-utils");
 
 //------------------------------------------------------------------------------
 // Rule Definition
 //------------------------------------------------------------------------------
 
-const MESSAGE_UNNECESSARY_COMPUTED = "Unnecessarily computed property [{{property}}] found.";
-
 module.exports = {
     meta: {
         type: "suggestion",
@@ -38,7 +35,11 @@ module.exports = {
             },
             additionalProperties: false
         }],
-        fixable: "code"
+        fixable: "code",
+
+        messages: {
+            unnecessarilyComputedProperty: "Unnecessarily computed property [{{property}}] found."
+        }
     },
     create(context) {
         const sourceCode = context.getSourceCode();
@@ -68,17 +69,14 @@ module.exports = {
             if (key.type === "Literal" && (nodeType === "string" || nodeType === "number") && key.value !== allowedKey) {
                 context.report({
                     node,
-                    message: MESSAGE_UNNECESSARY_COMPUTED,
+                    messageId: "unnecessarilyComputedProperty",
                     data: { property: sourceCode.getText(key) },
                     fix(fixer) {
-                        const leftSquareBracket = sourceCode.getFirstToken(node, astUtils.isOpeningBracketToken);
-                        const rightSquareBracket = sourceCode.getFirstTokenBetween(node.key, node.value, astUtils.isClosingBracketToken);
-                        const tokensBetween = sourceCode.getTokensBetween(leftSquareBracket, rightSquareBracket, 1);
-
-                        if (tokensBetween.slice(0, -1).some((token, index) =>
-                            sourceCode.getText().slice(token.range[1], tokensBetween[index + 1].range[0]).trim())) {
+                        const leftSquareBracket = sourceCode.getTokenBefore(key, astUtils.isOpeningBracketToken);
+                        const rightSquareBracket = sourceCode.getTokenAfter(key, astUtils.isClosingBracketToken);
 
-                            // If there are comments between the brackets and the property name, don't do a fix.
+                        // If there are comments between the brackets and the property name, don't do a fix.
+                        if (sourceCode.commentsExistBetween(leftSquareBracket, rightSquareBracket)) {
                             return null;
                         }
 
@@ -96,9 +94,16 @@ module.exports = {
             }
         }
 
+        /**
+         * A no-op function to act as placeholder for checking a node when the `enforceForClassMembers` option is `false`.
+         * @returns {void}
+         * @private
+         */
+        function noop() {}
+
         return {
             Property: check,
-            MethodDefinition: enforceForClassMembers ? check : lodash.noop
+            MethodDefinition: enforceForClassMembers ? check : noop
         };
     }
 };