@rehearsal/plugins
Advanced tools
Comparing version 1.0.6-beta to 1.0.7-beta
@@ -1,2 +0,2 @@ | ||
import { type DiagnosticWithLocation } from 'typescript'; | ||
import { CodeFixAction, type DiagnosticWithLocation } from 'typescript'; | ||
import { type DiagnosticWithContext } from '@rehearsal/codefixes'; | ||
@@ -14,2 +14,3 @@ import { Plugin, PluginOptions, type PluginResult, PluginsRunnerContext, RehearsalService } from '@rehearsal/service'; | ||
prioritizedCodes: number[]; | ||
attemptedToFix: string[]; | ||
run(fileName: string, context: PluginsRunnerContext, options: DiagnosticFixPluginOptions): PluginResult; | ||
@@ -27,3 +28,9 @@ /** | ||
sort(diagnostics: DiagnosticWithLocation[], prioritizedCodes: number[]): void; | ||
/** | ||
* Returns a code fix that expected to fix provided diagnostic | ||
*/ | ||
getCodeFix(diagnostic: DiagnosticWithContext, options: DiagnosticFixPluginOptions): CodeFixAction | undefined; | ||
private resetAttemptedToFix; | ||
private wasAttemptedToFix; | ||
} | ||
//# sourceMappingURL=diagnostic-fix.plugin.d.ts.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.DiagnosticFixPlugin = void 0; | ||
const debug_1 = require("debug"); | ||
const object_hash_1 = __importDefault(require("object-hash")); | ||
const codefixes_1 = require("@rehearsal/codefixes"); | ||
@@ -29,2 +33,3 @@ const utils_1 = require("@rehearsal/utils"); | ||
]; | ||
this.attemptedToFix = []; | ||
} | ||
@@ -38,2 +43,3 @@ async run(fileName, context, options) { | ||
const allFixedFiles = new Set(); | ||
this.resetAttemptedToFix(); | ||
while (diagnostics.length > 0) { | ||
@@ -45,12 +51,7 @@ const diagnostic = diagnostics.shift(); | ||
} | ||
const fixes = codefixes_1.codefixes.getCodeFixes(diagnostic, { | ||
safeFixes: options.safeFixes, | ||
strictTyping: options.strictTyping, | ||
}); | ||
if (fixes.length === 0) { | ||
const fix = this.getCodeFix(diagnostic, options); | ||
if (!fix) { | ||
DEBUG_CALLBACK(` - TS${diagnostic.code} at ${diagnostic.start}:\t didn't fix`); | ||
continue; | ||
} | ||
// Use the first available codefix in automatic mode, | ||
// TODO: User should be able to choose one of the fixes form this list in interactive mode | ||
const fix = fixes.shift(); | ||
if ((0, codefixes_1.isInstallPackageCommand)(fix)) { | ||
@@ -130,4 +131,37 @@ await this.applyCommandAction(fix.commands, context); | ||
} | ||
/** | ||
* Returns a code fix that expected to fix provided diagnostic | ||
*/ | ||
getCodeFix(diagnostic, options) { | ||
const fixes = codefixes_1.codefixes.getCodeFixes(diagnostic, { | ||
safeFixes: options.safeFixes, | ||
strictTyping: options.strictTyping, | ||
}); | ||
if (fixes.length === 0) { | ||
return undefined; | ||
} | ||
// Use the first available codefix in automatic mode | ||
let fix = fixes.shift(); | ||
while (fix && this.wasAttemptedToFix(diagnostic, fix)) { | ||
// Try the next fix if we already tried the first one | ||
fix = fixes.shift(); | ||
} | ||
if (fix === undefined) { | ||
DEBUG_CALLBACK(` - TS${diagnostic.code} at ${diagnostic.start}:\t fixes didn't work`); | ||
} | ||
return fix; | ||
} | ||
resetAttemptedToFix() { | ||
this.attemptedToFix = []; | ||
} | ||
wasAttemptedToFix(diagnostic, fix) { | ||
const diagnosticFixHash = (0, object_hash_1.default)([diagnostic.code, diagnostic.start, fix]); | ||
if (!this.attemptedToFix.includes(diagnosticFixHash)) { | ||
this.attemptedToFix.push(diagnosticFixHash); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
exports.DiagnosticFixPlugin = DiagnosticFixPlugin; | ||
//# sourceMappingURL=diagnostic-fix.plugin.js.map |
{ | ||
"name": "@rehearsal/plugins", | ||
"version": "1.0.6-beta", | ||
"version": "1.0.7-beta", | ||
"description": "Rehearsal JavaScript to TypeScript Shared Libraries", | ||
@@ -23,8 +23,10 @@ "keywords": [ | ||
"dependencies": { | ||
"@rehearsal/codefixes": "1.0.6-beta", | ||
"@rehearsal/reporter": "1.0.6-beta", | ||
"@rehearsal/service": "1.0.6-beta", | ||
"@rehearsal/utils": "1.0.6-beta", | ||
"@types/object-hash": "^3.0.2", | ||
"debug": "^4.3.4", | ||
"eslint": "^8.33.0" | ||
"eslint": "^8.33.0", | ||
"object-hash": "^3.0.0", | ||
"@rehearsal/codefixes": "1.0.7-beta", | ||
"@rehearsal/reporter": "1.0.7-beta", | ||
"@rehearsal/utils": "1.0.7-beta", | ||
"@rehearsal/service": "1.0.7-beta" | ||
}, | ||
@@ -31,0 +33,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
95158
530
9
+ Added@types/object-hash@^3.0.2
+ Addedobject-hash@^3.0.0
+ Added@rehearsal/codefixes@1.0.7-beta(transitive)
+ Added@rehearsal/reporter@1.0.7-beta(transitive)
+ Added@rehearsal/service@1.0.7-beta(transitive)
+ Added@rehearsal/utils@1.0.7-beta(transitive)
+ Added@types/object-hash@3.0.6(transitive)
+ Addedobject-hash@3.0.0(transitive)
- Removed@rehearsal/codefixes@1.0.6-beta(transitive)
- Removed@rehearsal/reporter@1.0.6-beta(transitive)
- Removed@rehearsal/service@1.0.6-beta(transitive)
- Removed@rehearsal/utils@1.0.6-beta(transitive)
Updated@rehearsal/utils@1.0.7-beta