Skip to content

chore: use context.cwd #1176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tired-bugs-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': patch
---

chore: switch to `context.cwd` rather than using a compat helper.
2 changes: 1 addition & 1 deletion packages/eslint-plugin-svelte/eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
]
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin-svelte/src/rules/valid-style-parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createRule } from '../utils/index.js';
import { getCwd } from '../utils/compat.js';

export default createRule('valid-style-parse', {
meta: {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/eslint-plugin-svelte/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ export type RuleContext = {

report(descriptor: ReportDescriptor): void;

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

physicalFilename: string;
};
Expand Down
10 changes: 0 additions & 10 deletions packages/eslint-plugin-svelte/src/utils/compat.ts

This file was deleted.

3 changes: 1 addition & 2 deletions packages/eslint-plugin-svelte/src/utils/load-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AST.SvelteProgram, Record<string, unknown>>();
const cache4b = new Map<string, unknown>();
/**
Expand All @@ -19,7 +18,7 @@ export function loadModule<R>(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 {
Expand Down
Loading