Skip to content

Commit b696ef3

Browse files
authored
chore: use context.filename and context.physicalFilename (#1174)
1 parent 8e53e58 commit b696ef3

File tree

13 files changed

+25
-47
lines changed

13 files changed

+25
-47
lines changed

.changeset/petite-impalas-reply.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.filename` and `context.physicalFilename` instead of compat functions.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ const config = [
7171
'no-restricted-properties': [
7272
'error',
7373
{ object: 'context', property: 'getSourceCode', message: 'Use `context.sourceCode`' },
74-
{ object: 'context', property: 'getFilename', message: 'Use src/utils/compat.ts' },
74+
{ object: 'context', property: 'getFilename', message: 'Use `context.filename`' },
7575
{
7676
object: 'context',
7777
property: 'getPhysicalFilename',
78-
message: 'Use src/utils/compat.ts'
78+
message: 'Use `context.physicalFilename`'
7979
},
8080
{ object: 'context', property: 'getCwd', message: 'Use src/utils/compat.ts' },
8181
{ object: 'context', property: 'getScope', message: 'Use src/utils/compat.ts' },

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ 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 } from '../utils/compat.js';
65

76
type RuleAndLocation = {
87
ruleId: string;
@@ -54,7 +53,7 @@ export default createRule('comment-directive', {
5453
type: 'problem'
5554
},
5655
create(context) {
57-
const shared = getShared(getFilename(context));
56+
const shared = getShared(context.filename);
5857
if (!shared) return {};
5958
const options = context.options[0] || {};
6059
const reportUnusedDisableDirectives = Boolean(options.reportUnusedDisableDirectives);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ 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 } from '../../utils/compat.js';
1211

1312
type IndentUserOptions = {
1413
indent?: number | 'tab';
@@ -78,7 +77,7 @@ export function defineVisitor(
7877
context: RuleContext,
7978
defaultOptions: Partial<IndentOptions>
8079
): RuleListener {
81-
if (!getFilename(context).endsWith('.svelte')) return {};
80+
if (!context.filename.endsWith('.svelte')) return {};
8281

8382
const options = parseOptions(context.options[0] || {}, defaultOptions);
8483
const sourceCode = context.sourceCode;

packages/eslint-plugin-svelte/src/rules/no-unused-props.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { TSESTree } from '@typescript-eslint/types';
44
import type ts from 'typescript';
55
import { findVariable } from '../utils/ast-utils.js';
66
import { toRegExp } from '../utils/regexp.js';
7-
import { getFilename } from '../utils/compat.js';
87

98
type PropertyPathArray = string[];
109

@@ -58,7 +57,7 @@ export default createRule('no-unused-props', {
5857
]
5958
},
6059
create(context) {
61-
const fileName = getFilename(context);
60+
const fileName = context.filename;
6261
const tools = getTypeScriptTools(context);
6362
if (!tools) {
6463
return {};

packages/eslint-plugin-svelte/src/rules/system.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { getShared } from '../shared/index.js';
22
import { createRule } from '../utils/index.js';
3-
import { getFilename } from '../utils/compat.js';
43
import { isRegExp, toRegExp } from '../utils/regexp.js';
54

65
export default createRule('system', {
@@ -15,7 +14,7 @@ export default createRule('system', {
1514
type: 'problem'
1615
},
1716
create(context) {
18-
const shared = getShared(getFilename(context));
17+
const shared = getShared(context.filename);
1918
if (!shared) return {};
2019

2120
const directives = shared.newCommentDirectives({

packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/less.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type less from 'less';
33
import type { RuleContext } from '../../../types.js';
44
import type { TransformResult } from './types.js';
55
import { loadModule } from '../../../utils/load-module.js';
6-
import { getFilename } from '../../../utils/compat.js';
76

87
type Less = typeof less;
98
/**
@@ -26,7 +25,7 @@ export function transform(
2625
}
2726
const code = text.slice(...inputRange);
2827

29-
const filename = `${getFilename(context)}.less`;
28+
const filename = `${context.filename}.less`;
3029
try {
3130
let output: Awaited<ReturnType<Less['render']>> | undefined;
3231

packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/postcss.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import postcss from 'postcss';
33
import postcssLoadConfig from 'postcss-load-config';
44
import type { RuleContext } from '../../../types.js';
55
import type { TransformResult } from './types.js';
6-
import { getCwd, getFilename } from '../../../utils/compat.js';
6+
import { getCwd } from '../../../utils/compat.js';
77

88
/**
99
* Transform with postcss
@@ -25,7 +25,7 @@ export function transform(
2525
}
2626
const code = text.slice(...inputRange);
2727

28-
const filename = `${getFilename(context)}.css`;
28+
const filename = `${context.filename}.css`;
2929
try {
3030
const configFilePath = postcssConfig?.configFilePath;
3131

packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/stylus.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { RawSourceMap } from 'source-map-js';
44
import type { RuleContext } from '../../../types.js';
55
import type { TransformResult } from './types.js';
66
import { loadModule } from '../../../utils/load-module.js';
7-
import { getFilename } from '../../../utils/compat.js';
87

98
type Stylus = typeof stylus;
109
/**
@@ -27,7 +26,7 @@ export function transform(
2726
}
2827
const code = text.slice(...inputRange);
2928

30-
const filename = `${getFilename(context)}.stylus`;
29+
const filename = `${context.filename}.stylus`;
3130
try {
3231
let output: string | undefined;
3332

packages/eslint-plugin-svelte/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export type RuleContext = {
149149

150150
getDeclaredVariables(node: TSESTree.Node): Variable[];
151151

152-
getFilename(): string;
152+
filename: string;
153153

154154
getScope(): Scope;
155155

@@ -161,8 +161,8 @@ export type RuleContext = {
161161

162162
// eslint@6 does not have this method.
163163
getCwd?: () => string;
164-
// eslint@<7.11.0 does not have this method.
165-
getPhysicalFilename?: () => string;
164+
165+
physicalFilename: string;
166166
};
167167

168168
export type NodeOrToken = {

0 commit comments

Comments
 (0)