Skip to content

Commit

Permalink
added safeguards against too many fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iisaduan committed Jul 30, 2021
1 parent 47395c1 commit 26bb5c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25,416 deletions.
1 change: 0 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export function makeOptions(cwd: string, args: string[]): Options {
// changedFiles: [ ... ]
if (!module.parent) {
const opt = makeOptions(process.cwd(), process.argv.slice(2));

console.log(opt);
codefixProject(opt, new CLIHost(process.cwd()));

Expand Down
17 changes: 14 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export interface Options {
}

export async function codefixProject(opt:Options, host: Host) {
if (opt.errorCode.length === 0 && opt.fixName.length === 0) {
host.log("Warning! Not specifying either code fix names or error codes often results in unwanted changes.");
process.exit(0);
}

const allChangedFiles = new Map<string, ChangedFile>();
let passCount = -1;
while (++passCount < 2) {
Expand Down Expand Up @@ -281,8 +286,11 @@ export function getTextChangeDict(codefixes: readonly CodeFixAction[], opt: Opti

for (let j = 0; j < changes.length; j++) {
let change = changes[j];
let [key, value] = getFileNameAndTextChangesFromCodeFix(change);

let validChanges = getFileNameAndTextChangesFromCodeFix(change);
if (validChanges === undefined){
continue
}
let [key, value] = validChanges;
const prevVal = textChangeDict.get(key);
if (prevVal === undefined) {
textChangeDict.set(key, value);
Expand Down Expand Up @@ -330,7 +338,10 @@ export function filterCodeFixesByFixName(codefixes: readonly CodeFixAction[], fi
return [filteredFixes, out];
}

function getFileNameAndTextChangesFromCodeFix(ftchanges: FileTextChanges): [string, TextChange[]] {
function getFileNameAndTextChangesFromCodeFix(ftchanges: FileTextChanges): [string, TextChange[]]|undefined {
if (/[\\/]node_modules[\\/]/.test(ftchanges.fileName)){
return undefined;
}
return [ftchanges.fileName, [...ftchanges.textChanges]];
}

Expand Down
Loading

0 comments on commit 26bb5c6

Please sign in to comment.