Skip to content

Commit 8e53e58

Browse files
authored
chore: use context.sourceCode instead of compat (#1173)
1 parent 3bdf5d0 commit 8e53e58

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+85
-143
lines changed

.changeset/happy-donuts-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
chore: use `context.sourceCode` directly rather than a compatibility helper.

packages/eslint-plugin-svelte/eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const config = [
7070
],
7171
'no-restricted-properties': [
7272
'error',
73-
{ object: 'context', property: 'getSourceCode', message: 'Use src/utils/compat.ts' },
73+
{ object: 'context', property: 'getSourceCode', message: 'Use `context.sourceCode`' },
7474
{ object: 'context', property: 'getFilename', message: 'Use src/utils/compat.ts' },
7575
{
7676
object: 'context',

packages/eslint-plugin-svelte/src/rules/@typescript-eslint/no-unnecessary-condition.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
isTupleType
2323
} from '../../utils/ts-utils/index.js';
2424
import type { TS, TSTools } from '../../utils/ts-utils/index.js';
25-
import { getSourceCode } from '../../utils/compat.js';
2625

2726
/**
2827
* Returns all types of a union type or an array containing `type` itself if it's no union type.
@@ -157,7 +156,7 @@ export default createRule('@typescript-eslint/no-unnecessary-condition', {
157156

158157
const { service, ts } = tools;
159158
const checker = service.program.getTypeChecker();
160-
const sourceCode = getSourceCode(context);
159+
const sourceCode = context.sourceCode;
161160
const compilerOptions = service.program.getCompilerOptions();
162161
const isStrictNullChecks = compilerOptions.strict
163162
? compilerOptions.strictNullChecks !== false

packages/eslint-plugin-svelte/src/rules/block-lang.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { createRule } from '../utils/index.js';
22
import { findAttribute, getLangValue } from '../utils/ast-utils.js';
33
import type { SvelteScriptElement, SvelteStyleElement } from 'svelte-eslint-parser/lib/ast';
4-
import { getSourceCode } from '../utils/compat.js';
54
import type { SuggestionReportDescriptor, SourceCode } from '../types.js';
65

76
export default createRule('block-lang', {
@@ -59,7 +58,7 @@ export default createRule('block-lang', {
5958
hasSuggestions: true
6059
},
6160
create(context) {
62-
if (!getSourceCode(context).parserServices.isSvelte) {
61+
if (!context.sourceCode.parserServices.isSvelte) {
6362
return {};
6463
}
6564
const enforceScriptPresent: boolean = context.options[0]?.enforceScriptPresent ?? false;
@@ -91,7 +90,7 @@ export default createRule('block-lang', {
9190
message: `The <script> block should be present and its lang attribute should be ${prettyPrintLangs(
9291
allowedScriptLangs
9392
)}.`,
94-
suggest: buildAddLangSuggestions(allowedScriptLangs, 'script', getSourceCode(context))
93+
suggest: buildAddLangSuggestions(allowedScriptLangs, 'script', context.sourceCode)
9594
});
9695
}
9796
for (const scriptNode of scriptNodes) {
@@ -106,7 +105,7 @@ export default createRule('block-lang', {
106105
}
107106
}
108107
if (styleNodes.length === 0 && enforceStylePresent) {
109-
const sourceCode = getSourceCode(context);
108+
const sourceCode = context.sourceCode;
110109
context.report({
111110
loc: { line: 1, column: 1 },
112111
message: `The <style> block should be present and its lang attribute should be ${prettyPrintLangs(

packages/eslint-plugin-svelte/src/rules/comment-directive.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { AST } from 'svelte-eslint-parser';
22
import { getShared } from '../shared/index.js';
33
import type { CommentDirectives } from '../shared/comment-directives.js';
44
import { createRule } from '../utils/index.js';
5-
import { getFilename, getSourceCode } from '../utils/compat.js';
5+
import { getFilename } from '../utils/compat.js';
66

77
type RuleAndLocation = {
88
ruleId: string;
@@ -63,7 +63,7 @@ export default createRule('comment-directive', {
6363
reportUnusedDisableDirectives
6464
});
6565

66-
const sourceCode = getSourceCode(context);
66+
const sourceCode = context.sourceCode;
6767

6868
/**
6969
* Parse a given comment.

packages/eslint-plugin-svelte/src/rules/consistent-selector-style.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
Tag as SelectorTag
88
} from 'postcss-selector-parser';
99
import { findClassesInAttribute } from '../utils/ast-utils.js';
10-
import { getSourceCode } from '../utils/compat.js';
1110
import { createRule } from '../utils/index.js';
1211

1312
export default createRule('consistent-selector-style', {
@@ -48,7 +47,7 @@ export default createRule('consistent-selector-style', {
4847
type: 'suggestion'
4948
},
5049
create(context) {
51-
const sourceCode = getSourceCode(context);
50+
const sourceCode = context.sourceCode;
5251
if (
5352
!sourceCode.parserServices.isSvelte ||
5453
sourceCode.parserServices.getStyleSelectorAST === undefined ||

packages/eslint-plugin-svelte/src/rules/first-attribute-linebreak.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { AST } from 'svelte-eslint-parser';
22
import { createRule } from '../utils/index.js';
3-
import { getSourceCode } from '../utils/compat.js';
43

54
export default createRule('first-attribute-linebreak', {
65
meta: {
@@ -30,7 +29,7 @@ export default createRule('first-attribute-linebreak', {
3029
create(context) {
3130
const multiline: 'below' | 'beside' = context.options[0]?.multiline || 'below';
3231
const singleline: 'below' | 'beside' = context.options[0]?.singleline || 'beside';
33-
const sourceCode = getSourceCode(context);
32+
const sourceCode = context.sourceCode;
3433

3534
/**
3635
* Report attribute

packages/eslint-plugin-svelte/src/rules/html-closing-bracket-new-line.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { AST } from 'svelte-eslint-parser';
22
import { createRule } from '../utils/index.js';
3-
import { getSourceCode } from '../utils/compat.js';
43
import type { SourceCode } from '../types.js';
54

65
type ExpectedNode = AST.SvelteStartTag | AST.SvelteEndTag;
@@ -123,7 +122,7 @@ export default createRule('html-closing-bracket-new-line', {
123122
options.singleline ??= 'never';
124123
options.multiline ??= 'always';
125124

126-
const sourceCode = getSourceCode(context);
125+
const sourceCode = context.sourceCode;
127126

128127
return {
129128
'SvelteStartTag, SvelteEndTag'(node: ExpectedNode) {

packages/eslint-plugin-svelte/src/rules/html-closing-bracket-spacing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default createRule('html-closing-bracket-spacing', {
4040
selfClosingTag: 'always',
4141
...ctx.options[0]
4242
};
43-
const src = ctx.getSourceCode();
43+
const src = ctx.sourceCode;
4444

4545
/**
4646
* Returns true if string contains newline characters

packages/eslint-plugin-svelte/src/rules/html-quotes.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { createRule } from '../utils/index.js';
33
import type { QuoteAndRange } from '../utils/ast-utils.js';
44
import { getMustacheTokens } from '../utils/ast-utils.js';
55
import { getAttributeValueQuoteAndRange } from '../utils/ast-utils.js';
6-
import { getSourceCode } from '../utils/compat.js';
76

87
const QUOTE_CHARS = {
98
double: '"',
@@ -49,7 +48,7 @@ export default createRule('html-quotes', {
4948
type: 'layout' // "problem",
5049
},
5150
create(context) {
52-
const sourceCode = getSourceCode(context);
51+
const sourceCode = context.sourceCode;
5352
const preferQuote: 'double' | 'single' = context.options[0]?.prefer ?? 'double';
5453
const dynamicQuote = context.options[0]?.dynamic?.quoted ? preferQuote : 'unquoted';
5554
const avoidInvalidUnquotedInHTML = Boolean(

0 commit comments

Comments
 (0)