Skip to content

Commit 63d2515

Browse files
committed
ci: fix lint check
1 parent 1669f42 commit 63d2515

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

tools/stylelint/no-unused-import.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,34 @@ const factory = (isEnabled: boolean, _options: never, context: {fix: boolean}) =
4949

5050
/** Extracts the namespace of an `@use` rule from its parameters. */
5151
function extractNamespaceFromUseStatement(params: string): string|null {
52-
const closeQuoteIndex = Math.max(params.lastIndexOf(`"`), params.lastIndexOf(`'`));
52+
const openQuoteIndex = Math.max(params.indexOf(`"`), params.indexOf(`'`));
53+
const closeQuoteIndex =
54+
Math.max(params.indexOf(`"`, openQuoteIndex + 1), params.indexOf(`'`, openQuoteIndex + 1));
5355

5456
if (closeQuoteIndex > -1) {
5557
const asExpression = 'as ';
5658
const asIndex = params.indexOf(asExpression, closeQuoteIndex);
59+
const withIndex = params.indexOf(' with', asIndex);
5760

5861
// If we found an ` as ` expression, we consider the rest of the text as the namespace.
5962
if (asIndex > -1) {
60-
return params.slice(asIndex + asExpression.length).trim();
63+
return withIndex == -1 ?
64+
params.slice(asIndex + asExpression.length).trim() :
65+
params.slice(asIndex + asExpression.length, withIndex).trim();
6166
}
6267

63-
const openQuoteIndex = Math.max(params.lastIndexOf(`"`, closeQuoteIndex - 1),
64-
params.lastIndexOf(`'`, closeQuoteIndex - 1));
68+
const importPath = params.slice(openQuoteIndex + 1, closeQuoteIndex)
69+
// Sass allows for leading underscores to be omitted and it technically supports .scss.
70+
.replace(/^_|(\.import)?\.scss$|\.import$/g, '');
6571

66-
if (openQuoteIndex > -1) {
67-
const importPath = params.slice(openQuoteIndex + 1, closeQuoteIndex)
68-
// Sass allows for leading underscores to be omitted and it technically supports .scss.
69-
.replace(/^_|(\.import)?\.scss$|\.import$/g, '');
70-
71-
// Built-in Sass imports look like `sass:map`.
72-
if (importPath.startsWith('sass:')) {
73-
return importPath.split('sass:')[1];
74-
}
75-
76-
// Sass ignores `/index` and infers the namespace as the next segment in the path.
77-
const fileName = basename(importPath);
78-
return fileName === 'index' ? basename(join(fileName, '..')) : fileName;
72+
// Built-in Sass imports look like `sass:map`.
73+
if (importPath.startsWith('sass:')) {
74+
return importPath.split('sass:')[1];
7975
}
76+
77+
// Sass ignores `/index` and infers the namespace as the next segment in the path.
78+
const fileName = basename(importPath);
79+
return fileName === 'index' ? basename(join(fileName, '..')) : fileName;
8080
}
8181

8282
return null;

0 commit comments

Comments
 (0)