Skip to content

Commit 66cbff3

Browse files
committed
chore: use context.sourceCode instead of compat
As of 3.x, we only support `8.57.1` and `>=9.0.0` of ESLint. Both of these have `context.sourceCode` available, so we should no longer need the `getSourceCode` compat helper. The helper does polyfill some missing methods but `8.57.1` seems to have all of those already.
1 parent 3bdf5d0 commit 66cbff3

Some content is hidden

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

53 files changed

+79
-134
lines changed

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(

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
isSvgElement,
77
isMathMLElement
88
} from '../utils/ast-utils.js';
9-
import { getSourceCode } from '../utils/compat.js';
109

1110
const TYPE_MESSAGES = {
1211
normal: 'HTML elements',
@@ -160,7 +159,7 @@ export default createRule('html-self-closing', {
160159
context.report({
161160
node,
162161
loc: {
163-
start: getSourceCode(context).getLocFromIndex(
162+
start: context.sourceCode.getLocFromIndex(
164163
node.startTag.range[1] - (node.startTag.selfClosing ? 2 : 1)
165164
),
166165
end: node.loc.end

packages/eslint-plugin-svelte/src/rules/indent-helpers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { isCommentToken } from '@eslint-community/eslint-utils';
88
import type { AnyToken, IndentOptions } from './commons.js';
99
import type { OffsetCalculator } from './offset-context.js';
1010
import { OffsetContext } from './offset-context.js';
11-
import { getFilename, getSourceCode } from '../../utils/compat.js';
11+
import { getFilename } from '../../utils/compat.js';
1212

1313
type IndentUserOptions = {
1414
indent?: number | 'tab';
@@ -81,7 +81,7 @@ export function defineVisitor(
8181
if (!getFilename(context).endsWith('.svelte')) return {};
8282

8383
const options = parseOptions(context.options[0] || {}, defaultOptions);
84-
const sourceCode = getSourceCode(context);
84+
const sourceCode = context.sourceCode;
8585
const offsets = new OffsetContext({ sourceCode, options });
8686

8787
/**

0 commit comments

Comments
 (0)