Skip to content

Commit bafbf5f

Browse files
authored
chore: use context.cwd instead of compat utils (#1176)
1 parent b696ef3 commit bafbf5f

File tree

8 files changed

+11
-21
lines changed

8 files changed

+11
-21
lines changed

Diff for: .changeset/tired-bugs-remain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
chore: switch to `context.cwd` rather than using a compat helper.

Diff for: packages/eslint-plugin-svelte/eslint.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const config = [
7777
property: 'getPhysicalFilename',
7878
message: 'Use `context.physicalFilename`'
7979
},
80-
{ object: 'context', property: 'getCwd', message: 'Use src/utils/compat.ts' },
80+
{ object: 'context', property: 'getCwd', message: 'Use `context.cwd`' },
8181
{ object: 'context', property: 'getScope', message: 'Use src/utils/compat.ts' },
8282
{ object: 'context', property: 'parserServices', message: 'Use src/utils/compat.ts' }
8383
]

Diff for: packages/eslint-plugin-svelte/src/rules/valid-style-parse.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createRule } from '../utils/index.js';
2-
import { getCwd } from '../utils/compat.js';
32

43
export default createRule('valid-style-parse', {
54
meta: {
@@ -17,7 +16,7 @@ export default createRule('valid-style-parse', {
1716
if (!sourceCode.parserServices.isSvelte) {
1817
return {};
1918
}
20-
const cwd = `${getCwd(context)}/`;
19+
const cwd = `${context.cwd ?? process.cwd()}/`;
2120

2221
return {
2322
SvelteStyleElement(node) {

Diff for: packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/babel.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type babelCore from '@babel/core';
33
import type { RuleContext } from '../../../types.js';
44
import type { TransformResult } from './types.js';
55
import { loadModule } from '../../../utils/load-module.js';
6-
import { getCwd } from '../../../utils/compat.js';
76

87
type BabelCore = typeof babelCore;
98
/**
@@ -33,7 +32,7 @@ export function transform(
3332
minified: false,
3433
ast: false,
3534
code: true,
36-
cwd: getCwd(context)
35+
cwd: context.cwd ?? process.cwd()
3736
});
3837
if (!output) {
3938
return null;

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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 } from '../../../utils/compat.js';
76

87
/**
98
* Transform with postcss
@@ -31,7 +30,7 @@ export function transform(
3130

3231
const config = postcssLoadConfig.sync(
3332
{
34-
cwd: getCwd(context),
33+
cwd: context.cwd ?? process.cwd(),
3534
from: filename
3635
},
3736
typeof configFilePath === 'string' ? configFilePath : undefined

Diff for: packages/eslint-plugin-svelte/src/types.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ export type RuleContext = {
159159

160160
report(descriptor: ReportDescriptor): void;
161161

162-
// eslint@6 does not have this method.
163-
getCwd?: () => string;
162+
cwd?: string;
164163

165164
physicalFilename: string;
166165
};

Diff for: packages/eslint-plugin-svelte/src/utils/compat.ts

-10
This file was deleted.

Diff for: packages/eslint-plugin-svelte/src/utils/load-module.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { AST } from 'svelte-eslint-parser';
22
import Module from 'module';
33
import path from 'path';
44
import type { RuleContext } from '../types.js';
5-
import { getCwd } from './compat.js';
65
const cache = new WeakMap<AST.SvelteProgram, Record<string, unknown>>();
76
const cache4b = new Map<string, unknown>();
87
/**
@@ -19,7 +18,7 @@ export function loadModule<R>(context: RuleContext, name: string): R | null {
1918
if (mod) return mod as R;
2019
try {
2120
// load from cwd
22-
const cwd = getCwd(context);
21+
const cwd = context.cwd ?? process.cwd();
2322
const relativeTo = path.join(cwd, '__placeholder__.js');
2423
return (modules[name] = Module.createRequire(relativeTo)(name) as R);
2524
} catch {

0 commit comments

Comments
 (0)