Skip to content

Commit fad6532

Browse files
authored
feat: use eslint-compat-utils (#316)
* feat: use eslint-compat-utils * Create rich-goats-notice.md * fix
1 parent 3859204 commit fad6532

29 files changed

+241
-74
lines changed

.changeset/rich-goats-notice.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": minor
3+
---
4+
5+
feat: use eslint-compat-utils

.eslintrc.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,55 @@ module.exports = {
2323
"@typescript-eslint/ban-ts-ignore": "off",
2424
"eslint-comments/no-unused-disable": "error",
2525
"@typescript-eslint/no-non-null-assertion": "off",
26+
// Repo rule
27+
"@typescript-eslint/no-restricted-imports": [
28+
"error",
29+
{
30+
patterns: [
31+
{
32+
group: ["/regexpp", "/regexpp/*"],
33+
message: "Please use `@eslint-community/regexpp` instead.",
34+
},
35+
{
36+
group: ["/eslint-utils", "/eslint-utils/*"],
37+
message: "Please use `@eslint-community/eslint-utils` instead.",
38+
},
39+
],
40+
},
41+
],
42+
"no-restricted-properties": [
43+
"error",
44+
{
45+
object: "context",
46+
property: "getSourceCode",
47+
message: "Use src/utils/compat.ts",
48+
},
49+
{
50+
object: "context",
51+
property: "getFilename",
52+
message: "Use src/utils/compat.ts",
53+
},
54+
{
55+
object: "context",
56+
property: "getPhysicalFilename",
57+
message: "Use src/utils/compat.ts",
58+
},
59+
{
60+
object: "context",
61+
property: "getCwd",
62+
message: "Use src/utils/compat.ts",
63+
},
64+
{
65+
object: "context",
66+
property: "getScope",
67+
message: "Use src/utils/compat.ts",
68+
},
69+
{
70+
object: "context",
71+
property: "parserServices",
72+
message: "Use src/utils/compat.ts",
73+
},
74+
],
2675
},
2776
overrides: [
2877
{

.github/workflows/format.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 👔 Format
2+
3+
on:
4+
workflow_dispatch: null
5+
6+
jobs:
7+
format:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout repo
12+
uses: actions/checkout@v4
13+
- name: Setup node
14+
uses: actions/setup-node@v4
15+
- name: Install deps
16+
run: npm install
17+
- name: Format
18+
run: npm run eslint-fix
19+
- name: Commit
20+
run: |
21+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
22+
git config --local user.name "github-actions[bot]"
23+
24+
git add .
25+
if [ -z "$(git status --porcelain)" ]; then
26+
echo "no formatting changed"
27+
exit 0
28+
fi
29+
git commit -m "chore: format"
30+
git push
31+
echo "pushed formatting changes https://github.com/$GITHUB_REPOSITORY/commit/$(git rev-parse HEAD)"

docs/.vuepress/components/demo/stylelint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module.exports = {
22
extends: ["stylelint-config-standard"],
33
rules: {
44
"no-descending-specificity": null,
5-
indentation: null,
65
"selector-max-empty-lines": null,
76
"selector-type-no-unknown": null,
87
"block-no-empty": null,

docs/.vuepress/components/stylelint.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ module.exports = {
22
extends: ["stylelint-config-standard", "stylelint-config-recommended-vue"],
33
rules: {
44
"no-descending-specificity": null,
5-
indentation: null,
65
},
76
};

lib/rules/enforce-style-type.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
isValidStyleContext,
1212
getCommentDirectivesReporter,
1313
} from "../styles/context";
14+
import { getSourceCode } from "../utils/compat";
1415

1516
const styleTypesAttrs = ["scoped", "module"] as const;
1617
type StyleTypes = "plain" | (typeof styleTypesAttrs)[number];
@@ -64,8 +65,9 @@ export = {
6465
}
6566

6667
const reporter = getCommentDirectivesReporter(context);
68+
const sourceCode = getSourceCode(context);
6769
const tokenStore =
68-
context.parserServices.getTemplateBodyTokenStore?.() as TokenStore;
70+
sourceCode.parserServices.getTemplateBodyTokenStore?.() as TokenStore;
6971
const { options } = context;
7072

7173
const allows: AllowsOption = options[0]?.allows ?? ["scoped"];

lib/rules/no-deprecated-deep-combinator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import type { VCSSSelectorCombinator } from "../styles/ast";
88
import type { RuleContext, Range, RuleListener } from "../types";
99
import { isDeepCombinator } from "../styles/utils/selectors";
10+
import { getSourceCode } from "../utils/compat";
1011

1112
export = {
1213
meta: {
@@ -45,7 +46,7 @@ export = {
4546
value: node.value.trim(),
4647
},
4748
fix(fixer) {
48-
const sourceCodeText = context.getSourceCode().text;
49+
const sourceCodeText = getSourceCode(context).text;
4950
const range = [...node.range] as Range;
5051
let newText = "::v-deep";
5152
if (sourceCodeText[range[0] - 1]?.trim()) {

lib/rules/no-unused-keyframes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getCommentDirectivesReporter,
88
} from "../styles/context";
99
import { isValidStyleContext } from "../styles/context/style";
10+
import { getSourceCode } from "../utils/compat";
1011

1112
export = {
1213
meta: {
@@ -42,7 +43,7 @@ export = {
4243
return {};
4344
}
4445
const reporter = getCommentDirectivesReporter(context);
45-
const sourceCode = context.getSourceCode();
46+
const sourceCode = getSourceCode(context);
4647

4748
/**
4849
* Reports the given node

lib/rules/require-scoped.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
isValidStyleContext,
1111
getCommentDirectivesReporter,
1212
} from "../styles/context";
13+
import { getSourceCode } from "../utils/compat";
1314

1415
export = {
1516
meta: {
@@ -40,8 +41,9 @@ export = {
4041
return {};
4142
}
4243
const reporter = getCommentDirectivesReporter(context);
44+
const sourceCode = getSourceCode(context);
4345
const tokenStore =
44-
context.parserServices.getTemplateBodyTokenStore?.() as TokenStore;
46+
sourceCode.parserServices.getTemplateBodyTokenStore?.() as TokenStore;
4547

4648
/**
4749
* Reports the given node.

lib/rules/require-v-deep-argument.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
isVCSSDeclarationProperty,
2323
isVCSSComment,
2424
} from "../styles/utils/css-nodes";
25+
import { getSourceCode } from "../utils/compat";
2526

2627
export = {
2728
meta: {
@@ -90,8 +91,7 @@ export = {
9091
nextNode.range[0],
9192
];
9293
if (
93-
context
94-
.getSourceCode()
94+
getSourceCode(context)
9595
.text.slice(...betweenRange)
9696
.trim()
9797
) {

lib/rules/v-deep-pseudo-style.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
isVDeepPseudo,
1111
isPseudoEmptyArguments,
1212
} from "../styles/utils/selectors";
13+
import { getSourceCode } from "../utils/compat";
1314

1415
export = {
1516
meta: {
@@ -50,7 +51,7 @@ export = {
5051
loc: node.loc,
5152
messageId: expected === ":deep" ? "expectedDeep" : "expectedVDeep",
5253
fix(fixer) {
53-
const nodeText = context.getSourceCode().text.slice(...node.range);
54+
const nodeText = getSourceCode(context).text.slice(...node.range);
5455
return fixer.replaceTextRange(
5556
node.range,
5657
nodeText.replace(

lib/rules/v-global-pseudo-style.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
isVGlobalPseudo,
1111
isPseudoEmptyArguments,
1212
} from "../styles/utils/selectors";
13+
import { getSourceCode } from "../utils/compat";
1314

1415
export = {
1516
meta: {
@@ -53,7 +54,7 @@ export = {
5354
messageId:
5455
expected === ":global" ? "expectedGlobal" : "expectedVGlobal",
5556
fix(fixer) {
56-
const nodeText = context.getSourceCode().text.slice(...node.range);
57+
const nodeText = getSourceCode(context).text.slice(...node.range);
5758
return fixer.replaceTextRange(
5859
node.range,
5960
nodeText.replace(

lib/rules/v-slotted-pseudo-style.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
isVSlottedPseudo,
1111
isPseudoEmptyArguments,
1212
} from "../styles/utils/selectors";
13+
import { getSourceCode } from "../utils/compat";
1314

1415
export = {
1516
meta: {
@@ -53,7 +54,7 @@ export = {
5354
messageId:
5455
expected === ":slotted" ? "expectedSlotted" : "expectedVSlotted",
5556
fix(fixer) {
56-
const nodeText = context.getSourceCode().text.slice(...node.range);
57+
const nodeText = getSourceCode(context).text.slice(...node.range);
5758
return fixer.replaceTextRange(
5859
node.range,
5960
nodeText.replace(

lib/styles/context/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
VueComponentContext,
1818
createVueComponentContext,
1919
} from "./vue-components";
20+
import { getSourceCode } from "../../utils/compat";
2021

2122
type CacheValue = {
2223
styles?: StyleContext[];
@@ -32,7 +33,7 @@ const CACHE = new WeakMap<AST.ESLintProgram, CacheValue>();
3233
* Gets the cache.
3334
*/
3435
function getCache(context: RuleContext): CacheValue {
35-
const sourceCode = context.getSourceCode();
36+
const sourceCode = getSourceCode(context);
3637
const { ast } = sourceCode;
3738
if (CACHE.has(ast)) {
3839
return CACHE.get(ast) as CacheValue;

lib/styles/context/style/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
} from "../../../types";
88
import type { VCSSStyleSheet, VCSSNode, VCSSSelectorNode } from "../../ast";
99
import { isVCSSContainerNode, hasSelectorNodes } from "../../utils/css-nodes";
10+
import { getSourceCode } from "../../../utils/compat";
1011

1112
/**
1213
* Check whether the program has invalid EOF or not.
@@ -18,16 +19,17 @@ function getInvalidEOFError(
1819
inDocumentFragment: boolean;
1920
error: AST.ParseError;
2021
} | null {
21-
const node = context.getSourceCode().ast;
22+
const node = getSourceCode(context).ast;
2223
const body = node.templateBody;
2324
let errors = body?.errors;
2425
let inDocumentFragment = false;
2526
if (errors == null) {
27+
const sourceCode = getSourceCode(context);
2628
/* istanbul ignore if */
27-
if (!context.parserServices.getDocumentFragment) {
29+
if (!sourceCode.parserServices.getDocumentFragment) {
2830
return null;
2931
}
30-
const df = context.parserServices.getDocumentFragment();
32+
const df = sourceCode.parserServices.getDocumentFragment();
3133
inDocumentFragment = true;
3234
errors = df?.errors;
3335
/* istanbul ignore if */
@@ -62,11 +64,11 @@ function getInvalidEOFError(
6264
*/
6365
function getStyleElements(context: RuleContext): AST.VElement[] {
6466
let document: AST.VDocumentFragment | null = null;
65-
if (context.parserServices.getDocumentFragment) {
67+
const sourceCode = getSourceCode(context);
68+
if (sourceCode.parserServices.getDocumentFragment) {
6669
// vue-eslint-parser v7.0.0
67-
document = context.parserServices.getDocumentFragment();
70+
document = sourceCode.parserServices.getDocumentFragment();
6871
} else {
69-
const sourceCode = context.getSourceCode();
7072
const { ast } = sourceCode;
7173
const templateBody = ast.templateBody as AST.ESLintProgram | undefined;
7274
/* istanbul ignore if */
@@ -189,7 +191,7 @@ export class StyleContextImpl {
189191
public readonly cssNode: VCSSStyleSheet | null;
190192

191193
public constructor(style: AST.VElement, context: RuleContext) {
192-
const sourceCode = context.getSourceCode();
194+
const sourceCode = getSourceCode(context);
193195
this.styleElement = style;
194196
this.sourceCode = sourceCode;
195197

lib/styles/context/vue-components/find-vue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AST } from "vue-eslint-parser";
22
import type { ASTNode, RuleContext } from "../../../types";
33
import { unwrapTypesExpression } from "../../utils/nodes";
4+
import { getSourceCode } from "../../../utils/compat";
45

56
const traverseNodes = AST.traverseNodes;
67

@@ -73,7 +74,7 @@ function findVueComponent(
7374
return cached.component;
7475
}
7576

76-
const sourceCode = context.getSourceCode();
77+
const sourceCode = getSourceCode(context);
7778
const componentComments = sourceCode
7879
.getAllComments()
7980
.filter((comment) => comment.value.includes("@vue/component"));

lib/styles/context/vue-components/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import findVueComponent from "./find-vue";
44
import type { RuleContext, ASTNode, AST } from "../../../types";
55
import type { Template } from "../../template";
66
import { isDefined } from "../../../utils/utils";
7+
import { getSourceCode } from "../../../utils/compat";
78

89
const traverseNodes = vueAST.traverseNodes;
910

@@ -288,7 +289,7 @@ function getClassesOperatedByClassList(
288289
): (AST.ESLintExpression | AST.ESLintSpreadElement)[] {
289290
const results: (AST.ESLintExpression | AST.ESLintSpreadElement)[] = [];
290291
traverseNodes(vueNode, {
291-
visitorKeys: context.getSourceCode().visitorKeys,
292+
visitorKeys: getSourceCode(context).visitorKeys,
292293
enterNode(node) {
293294
if (
294295
node.type !== "CallExpression" ||
@@ -351,7 +352,7 @@ function getReturnStatements(
351352
| AST.ESLintFunctionDeclaration
352353
)[] = [];
353354
traverseNodes(body, {
354-
visitorKeys: context.getSourceCode().visitorKeys,
355+
visitorKeys: getSourceCode(context).visitorKeys,
355356
enterNode(node) {
356357
if (skipNodes.length) {
357358
return;

lib/styles/selectors/query/attribute-tracker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function getAttributeValueNodes(
4747
// empty or syntax error
4848
continue;
4949
}
50+
if (expression.type === "VGenericExpression") continue;
5051
const expressions = getReferenceExpressions(expression, context);
5152
if (!expressions) {
5253
// Expressions not found.

lib/styles/selectors/query/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { isVElement, isTransitionElement } from "../../../utils/templates";
3838
import { isValidStyleContext } from "../../context/style";
3939
import type { ReferenceExpressions } from "./reference-expression";
4040
import { getReferenceExpressions } from "./reference-expression";
41+
import { getSourceCode } from "../../../utils/compat";
4142

4243
const TRANSITION_CLASS_BASES = [
4344
"enter",
@@ -130,7 +131,7 @@ class VueDocumentQueryContext extends QueryContext {
130131

131132
public constructor(context: RuleContext, options: ParsedQueryOptions) {
132133
super();
133-
const sourceCode = context.getSourceCode();
134+
const sourceCode = getSourceCode(context);
134135
const { ast } = sourceCode;
135136
this.elements = ast.templateBody
136137
? [...genDescendantElements([ast.templateBody])]

0 commit comments

Comments
 (0)