UNPKG

@atlaskit/eslint-plugin-ui-styling-standard

Version:

The eslint plugin to enforce and educate on Atlassian's UI Styling Standard

29 lines (28 loc) • 843 B
/** * Structural stand-in for postcss-selector-parser's Node. Avoid importing that * Node type — under TSRS it expands into an infinite Container/Diff cycle. */ export function getRangeFromNode({ node, sourceNode }) { /** * The adjustment required to align the selector AST source position * with the ESTree source position. */ const adjustment = /** * Using a non-null `!` is safe here because ESLint requires the parser to * include a range value on nodes. * * https://eslint.org/docs/latest/extend/custom-parsers#all-nodes */ sourceNode.range[0] + ( /** * We add +1 if it's a literal to account for the opening `'` or `"` character. */ sourceNode.type === 'Literal' ? 1 : 0); const start = adjustment + node.sourceIndex; const end = start + node.value.length; return [start, end]; }