Skip to content

Commit 5dffc9b

Browse files
authored
fix: error when using ESLint v9.30.0 or later (#400)
* fix: error when using ESLint v9.30.0 or later * Create sweet-poems-chew.md
1 parent e39e6fe commit 5dffc9b

File tree

4 files changed

+396
-210
lines changed

4 files changed

+396
-210
lines changed

.changeset/sweet-poems-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-vue-scoped-css": patch
3+
---
4+
5+
fix: error when using ESLint v9.30.0 or later

lib/styles/parser/selector/css-selector-parser.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,21 @@ export class CSSSelectorParser {
174174
): VCSSSelectorNode | null {
175175
const { sourceCode } = this;
176176

177+
/**
178+
* Get index from location
179+
*/
180+
function getIndexFromLoc(loc: LineAndColumnData): number {
181+
if (loc.column >= 0) {
182+
return sourceCode.getIndexFromLoc(loc);
183+
}
184+
// A column index can be negative if the starting position contains a newline.
185+
const index = sourceCode.getIndexFromLoc({
186+
line: loc.line,
187+
column: 0,
188+
});
189+
return index + loc.column;
190+
}
191+
177192
const loc = {
178193
start: getESLintLineAndColumnFromPostCSSSelectorParserNode(
179194
offsetLocation,
@@ -186,8 +201,8 @@ export class CSSSelectorParser {
186201
"end",
187202
),
188203
};
189-
const start = sourceCode.getIndexFromLoc(loc.start);
190-
const end = sourceCode.getIndexFromLoc(loc.end);
204+
const start = getIndexFromLoc(loc.start);
205+
const end = getIndexFromLoc(loc.end);
191206

192207
const astNode = this[typeToConvertMethodName(node.type)](
193208
node as never,

0 commit comments

Comments
 (0)