import type { TSESTree } from "@typescript-eslint/utils"; import type { Declaration } from "postcss"; /** * Consolidates postcss node position into an eslint compatible position, * taking the entire source file into account */ export function getDeclarationPosition( node: TSESTree.Node, declaration: Declaration | undefined, optionalEndDeclaration?: Declaration | undefined, ): Readonly | undefined { const startDeclaration = declaration; const endDeclaration = optionalEndDeclaration ?? declaration; if (!startDeclaration?.source?.start || !endDeclaration?.source?.end) { return; } const loc = { start: { column: startDeclaration.source.start.column - 1, line: node.loc.start.line - 1 + startDeclaration.source.start.line, }, end: { column: endDeclaration.source.end.column - 1, line: node.loc.start.line - 1 + endDeclaration.source.end.line, }, }; return loc; }