diff --git a/.changeset/tired-bugs-remain.md b/.changeset/tired-bugs-remain.md new file mode 100644 index 000000000..1a6b595a9 --- /dev/null +++ b/.changeset/tired-bugs-remain.md @@ -0,0 +1,5 @@ +--- +'eslint-plugin-svelte': patch +--- + +chore: switch to `context.cwd` rather than using a compat helper. diff --git a/packages/eslint-plugin-svelte/eslint.config.mjs b/packages/eslint-plugin-svelte/eslint.config.mjs index a0c8bc00e..7205893bf 100644 --- a/packages/eslint-plugin-svelte/eslint.config.mjs +++ b/packages/eslint-plugin-svelte/eslint.config.mjs @@ -77,7 +77,7 @@ const config = [ property: 'getPhysicalFilename', message: 'Use `context.physicalFilename`' }, - { object: 'context', property: 'getCwd', message: 'Use src/utils/compat.ts' }, + { object: 'context', property: 'getCwd', message: 'Use `context.cwd`' }, { object: 'context', property: 'getScope', message: 'Use src/utils/compat.ts' }, { object: 'context', property: 'parserServices', message: 'Use src/utils/compat.ts' } ] diff --git a/packages/eslint-plugin-svelte/src/rules/valid-style-parse.ts b/packages/eslint-plugin-svelte/src/rules/valid-style-parse.ts index e5f403898..f92b76cdb 100644 --- a/packages/eslint-plugin-svelte/src/rules/valid-style-parse.ts +++ b/packages/eslint-plugin-svelte/src/rules/valid-style-parse.ts @@ -1,5 +1,4 @@ import { createRule } from '../utils/index.js'; -import { getCwd } from '../utils/compat.js'; export default createRule('valid-style-parse', { meta: { @@ -17,7 +16,7 @@ export default createRule('valid-style-parse', { if (!sourceCode.parserServices.isSvelte) { return {}; } - const cwd = `${getCwd(context)}/`; + const cwd = `${context.cwd ?? process.cwd()}/`; return { SvelteStyleElement(node) { diff --git a/packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/babel.ts b/packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/babel.ts index 55c41edfa..42b7cc1b8 100644 --- a/packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/babel.ts +++ b/packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/babel.ts @@ -3,7 +3,6 @@ import type babelCore from '@babel/core'; import type { RuleContext } from '../../../types.js'; import type { TransformResult } from './types.js'; import { loadModule } from '../../../utils/load-module.js'; -import { getCwd } from '../../../utils/compat.js'; type BabelCore = typeof babelCore; /** @@ -33,7 +32,7 @@ export function transform( minified: false, ast: false, code: true, - cwd: getCwd(context) + cwd: context.cwd ?? process.cwd() }); if (!output) { return null; diff --git a/packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/postcss.ts b/packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/postcss.ts index 9647bedf0..7c068bc23 100644 --- a/packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/postcss.ts +++ b/packages/eslint-plugin-svelte/src/shared/svelte-compile-warns/transform/postcss.ts @@ -3,7 +3,6 @@ import postcss from 'postcss'; import postcssLoadConfig from 'postcss-load-config'; import type { RuleContext } from '../../../types.js'; import type { TransformResult } from './types.js'; -import { getCwd } from '../../../utils/compat.js'; /** * Transform with postcss @@ -31,7 +30,7 @@ export function transform( const config = postcssLoadConfig.sync( { - cwd: getCwd(context), + cwd: context.cwd ?? process.cwd(), from: filename }, typeof configFilePath === 'string' ? configFilePath : undefined diff --git a/packages/eslint-plugin-svelte/src/types.ts b/packages/eslint-plugin-svelte/src/types.ts index 45a6a8b26..1fd9fce27 100644 --- a/packages/eslint-plugin-svelte/src/types.ts +++ b/packages/eslint-plugin-svelte/src/types.ts @@ -159,8 +159,7 @@ export type RuleContext = { report(descriptor: ReportDescriptor): void; - // eslint@6 does not have this method. - getCwd?: () => string; + cwd?: string; physicalFilename: string; }; diff --git a/packages/eslint-plugin-svelte/src/utils/compat.ts b/packages/eslint-plugin-svelte/src/utils/compat.ts deleted file mode 100644 index 74a173b59..000000000 --- a/packages/eslint-plugin-svelte/src/utils/compat.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { getCwd as getCwdBase } from 'eslint-compat-utils'; -import type { RuleContext } from '../types.js'; - -/** - * Gets the value of `context.cwd`, but for older ESLint it returns the result of `context.getCwd()`. - * Versions older than v6.6.0 return a value from the result of `process.cwd()`. - */ -export function getCwd(context: RuleContext): string { - return getCwdBase(context as never); -} diff --git a/packages/eslint-plugin-svelte/src/utils/load-module.ts b/packages/eslint-plugin-svelte/src/utils/load-module.ts index a44de7bf9..97c766c52 100644 --- a/packages/eslint-plugin-svelte/src/utils/load-module.ts +++ b/packages/eslint-plugin-svelte/src/utils/load-module.ts @@ -2,7 +2,6 @@ import type { AST } from 'svelte-eslint-parser'; import Module from 'module'; import path from 'path'; import type { RuleContext } from '../types.js'; -import { getCwd } from './compat.js'; const cache = new WeakMap>(); const cache4b = new Map(); /** @@ -19,7 +18,7 @@ export function loadModule(context: RuleContext, name: string): R | null { if (mod) return mod as R; try { // load from cwd - const cwd = getCwd(context); + const cwd = context.cwd ?? process.cwd(); const relativeTo = path.join(cwd, '__placeholder__.js'); return (modules[name] = Module.createRequire(relativeTo)(name) as R); } catch {