Skip to content

Commit 5822cb4

Browse files
committed
feat(linter/plugins): add extend method to FILE_CONTEXT (#15477)
`extend` method exists on ESLint's `FileContext` type. Replicate it here (copying impl from ESLint).
1 parent eeed5de commit 5822cb4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

apps/oxlint/src-js/plugins/context.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import type { RuleAndContext } from './load.ts';
3636
import type { SourceCode } from './source_code.ts';
3737
import type { Location, Ranged } from './types.ts';
3838

39-
const { hasOwn, keys: ObjectKeys, freeze } = Object;
39+
const { hasOwn, keys: ObjectKeys, freeze, assign: ObjectAssign, create: ObjectCreate } = Object;
4040

4141
// Diagnostic in form passed by user to `Context#report()`
4242
export type Diagnostic = DiagnosticWithNode | DiagnosticWithLoc;
@@ -134,6 +134,17 @@ const FILE_CONTEXT = freeze({
134134
if (settings === null) initSettings();
135135
return settings;
136136
},
137+
138+
/**
139+
* Create a new object with the current object as the prototype and
140+
* the specified properties as its own properties.
141+
* @param extension - The properties to add to the new object.
142+
* @returns A new object with the current object as the prototype
143+
* and the specified properties as its own properties.
144+
*/
145+
extend(this: FileContext, extension: Record<string | number | symbol, unknown>): FileContext {
146+
return freeze(ObjectAssign(ObjectCreate(this), extension));
147+
},
137148
});
138149

139150
type FileContext = typeof FILE_CONTEXT;

0 commit comments

Comments
 (0)