diff --git a/apps/oxlint/src-js/plugins/context.ts b/apps/oxlint/src-js/plugins/context.ts index 14ef77d5dfd6c..15d802e072bb9 100644 --- a/apps/oxlint/src-js/plugins/context.ts +++ b/apps/oxlint/src-js/plugins/context.ts @@ -1,7 +1,6 @@ import { getFixes } from './fix.js'; import type { Fix, FixFn } from './fix.ts'; -import type { RuleMeta } from './types.ts'; // Diagnostic in form passed by user to `Context#report()` export interface Diagnostic { @@ -70,8 +69,8 @@ export interface InternalContext { filePath: string; // Options options: unknown[]; - // Rule metadata - meta: RuleMeta; + // `true` if rule can provide fixes (`meta.fixable` in `RuleMeta` is 'code' or 'whitespace') + isFixable: boolean; } /** @@ -88,13 +87,13 @@ export class Context { * @class * @param fullRuleName - Rule name, in form `/` */ - constructor(fullRuleName: string, meta: RuleMeta) { + constructor(fullRuleName: string, isFixable: boolean) { this.#internal = { id: fullRuleName, filePath: '', ruleIndex: -1, options: [], - meta, + isFixable, }; } diff --git a/apps/oxlint/src-js/plugins/fix.ts b/apps/oxlint/src-js/plugins/fix.ts index 088183c93a748..081076e2cc144 100644 --- a/apps/oxlint/src-js/plugins/fix.ts +++ b/apps/oxlint/src-js/plugins/fix.ts @@ -144,7 +144,7 @@ export function getFixes(diagnostic: Diagnostic, internal: InternalContext): Fix // ESLint does not throw this error if `fix` function returns only falsy values. // We've already exited if that is the case, so we're reproducing that behavior. - if (internal.meta.fixable === null) { + if (internal.isFixable === false) { throw new Error('Fixable rules must set the `meta.fixable` property to "code" or "whitespace".'); } diff --git a/apps/oxlint/src-js/plugins/load.ts b/apps/oxlint/src-js/plugins/load.ts index 0994f7c0d7318..e3045436ad44a 100644 --- a/apps/oxlint/src-js/plugins/load.ts +++ b/apps/oxlint/src-js/plugins/load.ts @@ -68,11 +68,6 @@ interface PluginDetails { ruleNames: string[]; } -// Default rule metadata, used if `rule.meta` property is empty. -const emptyRuleMeta: RuleMeta = { - fixable: null, -}; - /** * Load a plugin. * @@ -120,27 +115,22 @@ async function loadPluginImpl(path: string): Promise { const ruleName = ruleNames[i], rule = rules[ruleName]; - // Validate `rule.meta` and convert to object with standardized shape - // (all properties defined with default values if not supplied) + // Validate `rule.meta` and convert to vars with standardized shape + let isFixable = false; let ruleMeta = rule.meta; - if (ruleMeta == null) { - ruleMeta = emptyRuleMeta; - } else { + if (ruleMeta != null) { if (typeof ruleMeta !== 'object') throw new TypeError('Invalid `meta`'); - let { fixable } = ruleMeta; - if (fixable === void 0) { - fixable = null; - } else if (fixable !== null && fixable !== 'code' && fixable !== 'whitespace') { - throw new TypeError('Invalid `meta.fixable`'); + const { fixable } = ruleMeta; + if (fixable != null) { + if (fixable !== 'code' && fixable !== 'whitespace') throw new TypeError('Invalid `meta.fixable`'); + isFixable = true; } - - ruleMeta = { fixable }; } // Create `Context` object for rule. This will be re-used for every file. // It's updated with file-specific data before linting each file with `setupContextForFile`. - const context = new Context(`${pluginName}/${ruleName}`, ruleMeta); + const context = new Context(`${pluginName}/${ruleName}`, isFixable); let ruleAndContext; if ('createOnce' in rule) {