]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/lib/rules/block-spacing.js
import 8.41.0 source
[pve-eslint.git] / eslint / lib / rules / block-spacing.js
index c4b30b0b70b9839bd145fdd36c5e947d0d1d1a72..dd4851c68435ebb5ddfe7a415bf0ccfba7972237 100644 (file)
@@ -11,15 +11,15 @@ const util = require("./utils/ast-utils");
 // Rule Definition
 //------------------------------------------------------------------------------
 
+/** @type {import('../shared/types').Rule} */
 module.exports = {
     meta: {
         type: "layout",
 
         docs: {
-            description: "disallow or enforce spaces inside of blocks after opening block and before closing block",
-            category: "Stylistic Issues",
+            description: "Disallow or enforce spaces inside of blocks after opening block and before closing block",
             recommended: false,
-            url: "https://eslint.org/docs/rules/block-spacing"
+            url: "https://eslint.org/docs/latest/rules/block-spacing"
         },
 
         fixable: "whitespace",
@@ -37,11 +37,11 @@ module.exports = {
     create(context) {
         const always = (context.options[0] !== "never"),
             messageId = always ? "missing" : "extra",
-            sourceCode = context.getSourceCode();
+            sourceCode = context.sourceCode;
 
         /**
          * Gets the open brace token from a given node.
-         * @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
+         * @param {ASTNode} node A BlockStatement/StaticBlock/SwitchStatement node to get.
          * @returns {Token} The token of the open brace.
          */
         function getOpenBrace(node) {
@@ -51,6 +51,12 @@ module.exports = {
                 }
                 return sourceCode.getLastToken(node, 1);
             }
+
+            if (node.type === "StaticBlock") {
+                return sourceCode.getFirstToken(node, { skip: 1 }); // skip the `static` token
+            }
+
+            // "BlockStatement"
             return sourceCode.getFirstToken(node);
         }
 
@@ -73,8 +79,8 @@ module.exports = {
         }
 
         /**
-         * Reports invalid spacing style inside braces.
-         * @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
+         * Checks and reports invalid spacing style inside braces.
+         * @param {ASTNode} node A BlockStatement/StaticBlock/SwitchStatement node to check.
          * @returns {void}
          */
         function checkSpacingInsideBraces(node) {
@@ -158,6 +164,7 @@ module.exports = {
 
         return {
             BlockStatement: checkSpacingInsideBraces,
+            StaticBlock: checkSpacingInsideBraces,
             SwitchStatement: checkSpacingInsideBraces
         };
     }