Skip to content
Open
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
7 changes: 3 additions & 4 deletions src/env_globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,9 @@ export const transformEnvAndGlobals = (
eslintConfig.languageOptions.parser.meta?.name
)
) {
options?.reporter?.report(
'special parser detected: ' +
// @ts-ignore
eslintConfig.languageOptions.parser.meta?.name
options?.reporter?.specialParserDetected(
// @ts-ignore
eslintConfig.languageOptions.parser.meta?.name
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ignorePatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const transformIgnorePatterns = (
}

if ('files' in targetConfig) {
options?.reporter?.report('ignore list inside overrides is not supported');
options?.reporter?.ignoreListInsideOverrides();
return;
}

Expand Down
12 changes: 4 additions & 8 deletions src/plugins_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,12 @@ export const transformRuleEntry = (

if (allRules.includes(rule)) {
if (!options?.withNursery && rules.nurseryRules.includes(rule)) {
options?.reporter?.report(
`unsupported rule, but in development: ${rule}`
);
options?.reporter?.unsupportedRuleInDevelopment(rule);
continue;
}

if (!options?.typeAware && typescriptTypeAwareRules.includes(rule)) {
options?.reporter?.report(
`type-aware rule detected, but \`--type-aware\` is not enabled: ${rule}`
);
options?.reporter?.typeAwareRuleNotEnabled(rule);
continue;
}
if (options?.merge) {
Expand All @@ -105,7 +101,7 @@ export const transformRuleEntry = (
} else {
// ToDo: maybe use a force flag when some enabled rules are detected?
if (isActiveValue(config)) {
options?.reporter?.report(`unsupported rule: ${rule}`);
options?.reporter?.unsupportedRule(rule);
}
}
}
Expand Down Expand Up @@ -141,7 +137,7 @@ export const detectNeededRulesPlugins = (
}

if (!found) {
options?.reporter?.report(`unsupported plugin for rule: ${rule}`);
options?.reporter?.unsupportedRuleForPlugin(rule);
}
}

Expand Down
47 changes: 46 additions & 1 deletion src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,61 @@ export class DefaultReporter implements Reporter {
this.reports.add(message);
}

public failedToParse(filePath: string): void {
this.reports.add(`${filePath}: failed to parse`);
}
public unsupportedRule(rule: string): void {
this.reports.add(`unsupported rule: ${rule}`);
}
public unsupportedRuleInDevelopment(rule: string): void {
this.reports.add(`unsupported rule, but in development: ${rule}`);
}
public unsupportedRuleForPlugin(rule: string): void {
this.reports.add(`unsupported plugin for rule: ${rule}`);
}
public typeAwareRuleNotEnabled(rule: string): void {
this.reports.add(
`type-aware rule detected, but \`--type-aware\` is not enabled: ${rule}`
);
}
public ignoreListInsideOverrides(): void {
this.reports.add(`ignore list inside overrides is not supported`);
}

public specialParserDetected(parserName: string): void {
this.reports.add(`special parser detected: ${parserName}`);
}

public getReports(): string[] {
return Array.from(this.reports);
}
}

export class SilentReporter implements Reporter {
public failedToParse(_filePath: string): void {
// Do nothing
}
public unsupportedRule(_rule: string): void {
// Do nothing
}
public unsupportedRuleInDevelopment(_rule: string): void {
// Do nothing
}
public unsupportedRuleForPlugin(_rule: string): void {
// Do nothing
}
public typeAwareRuleNotEnabled(_rule: string): void {
// Do nothing
}
public ignoreListInsideOverrides(): void {
// Do nothing
}
public specialParserDetected(_parserName: string): void {
// Do nothing
}
public report(_message: string): void {
// Do nothing
}

public getReports(): string[] {
return [];
}
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export type OxlintConfigOrOverride = OxlintConfig | OxlintConfigOverride;

export type Reporter = {
report(message: string): void;
unsupportedRule(rule: string): void;
unsupportedRuleInDevelopment(rule: string): void;
unsupportedRuleForPlugin(rule: string): void;
failedToParse(filePath: string): void;
typeAwareRuleNotEnabled(rule: string): void;
ignoreListInsideOverrides(): void;
specialParserDetected(parserName: string): void;
getReports(): string[];
};

Expand Down
3 changes: 2 additions & 1 deletion src/walker/replaceCommentsInFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const getComments = (
);

if (parserResult.errors.length > 0) {
options.reporter?.report(`${absoluteFilePath}: failed to parse`);
options.reporter?.failedToParse(absoluteFilePath);
return [];
}

return parserResult.comments;
Expand Down