// 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",
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) {
}
return sourceCode.getLastToken(node, 1);
}
+
+ if (node.type === "StaticBlock") {
+ return sourceCode.getFirstToken(node, { skip: 1 }); // skip the `static` token
+ }
+
+ // "BlockStatement"
return sourceCode.getFirstToken(node);
}
}
/**
- * 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) {
return {
BlockStatement: checkSpacingInsideBraces,
+ StaticBlock: checkSpacingInsideBraces,
SwitchStatement: checkSpacingInsideBraces
};
}