Skip to content

Commit

Permalink
feat(eslint): save metadata in convertRule result
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 1, 2024
1 parent edb0280 commit 9cc9933
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/eslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ export function convertConfig(
}

export function convertRule(
rule: ESLint.Rule.RuleModule,
eslintRule: ESLint.Rule.RuleModule,
options: any[] = [],
severity: ts.DiagnosticCategory =
rule.meta?.type === 'problem' ? 1 satisfies ts.DiagnosticCategory.Error
: rule.meta?.type === 'suggestion' ? 0 satisfies ts.DiagnosticCategory.Warning
: rule.meta?.type === 'layout' ? 2 satisfies ts.DiagnosticCategory.Suggestion
eslintRule.meta?.type === 'problem' ? 1 satisfies ts.DiagnosticCategory.Error
: eslintRule.meta?.type === 'suggestion' ? 0 satisfies ts.DiagnosticCategory.Warning
: eslintRule.meta?.type === 'layout' ? 2 satisfies ts.DiagnosticCategory.Suggestion
: 3 satisfies ts.DiagnosticCategory.Message,
context: Partial<ESLint.Rule.RuleContext> = {}
): TSSLint.Rule {
return ({ typescript: ts, sourceFile, languageService, reportError, reportWarning, reportSuggestion }) => {
const tsslintRule: TSSLint.Rule = ({ typescript: ts, sourceFile, languageService, reportError, reportWarning, reportSuggestion }) => {
const report =
severity === ts.DiagnosticCategory.Error ? reportError
: severity === ts.DiagnosticCategory.Warning ? reportWarning
Expand All @@ -100,7 +100,7 @@ export function convertRule(
const emitter = createEmitter();

// @ts-expect-error
const ruleListeners = rule.create({
const ruleListeners = eslintRule.create({
settings: {},
languageOptions: {},
filename: sourceFile.fileName,
Expand Down Expand Up @@ -367,9 +367,11 @@ export function convertRule(
}

function getMessage(messageId: string) {
return rule.meta?.messages?.[messageId] ?? '';
return eslintRule.meta?.messages?.[messageId] ?? '';
}
};
(tsslintRule as any).meta = eslintRule.meta;
return tsslintRule;
}

function getEstree(sourceFile: ts.SourceFile, languageService: ts.LanguageService) {
Expand Down

0 comments on commit 9cc9933

Please sign in to comment.