Skip to content
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
9 changes: 9 additions & 0 deletions apps/oxlint/src-js/plugins/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ export interface InternalContext {
messages: Record<string, string> | null;
}

// Cached current working directory.
let cachedCwd: string | null = null;

/**
* Context class.
*
Expand Down Expand Up @@ -132,6 +135,12 @@ export class Context {
return getInternal(this, 'access `context.physicalFilename`').filePath;
}

// Getter for current working directory.
get cwd() {
getInternal(this, 'access `context.cwd`');
return cachedCwd ??= process.cwd();
}

// Getter for options for file being linted.
get options() {
return getInternal(this, 'access `context.options`').options;
Expand Down
8 changes: 8 additions & 0 deletions apps/oxlint/test/fixtures/context_properties/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ const rule: Rule = {
node: SPAN,
});

if (context.cwd.length === 0) {
context.report({ message: 'cwd.length === 0', node: SPAN });
}

if (context.cwd !== process.cwd()) {
context.report({ message: 'cwd !== process.cwd()', node: SPAN });
}

if (this !== rule) context.report({ message: 'this !== rule', node: SPAN });

return {
Expand Down
Loading