securityos/node_modules/eslint-plugin-unicorn/rules/utils/get-switch-case-head-locati...

22 lines
718 B
JavaScript
Raw Normal View History

2024-09-06 15:32:35 +00:00
'use strict';
const {isColonToken} = require('@eslint-community/eslint-utils');
/**
@typedef {line: number, column: number} Position
Get the location of the given `SwitchCase` node for reporting.
@param {Node} node - The `SwitchCase` node to get.
@param {SourceCode} sourceCode - The source code object to get tokens from.
@returns {{start: Position, end: Position}} The location of the class node for reporting.
*/
function getSwitchCaseHeadLocation(node, sourceCode) {
const startToken = node.test || sourceCode.getFirstToken(node);
const colonToken = sourceCode.getTokenAfter(startToken, isColonToken);
return {start: node.loc.start, end: colonToken.loc.end};
}
module.exports = getSwitchCaseHeadLocation;