Skip to content

Commit dd319f8

Browse files
committed
replace old path to rulesConverter
1 parent 2830122 commit dd319f8

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/cli/runCli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const runCli = async (
2525
.option("--tslint [tslint]", "tslint configuration file to convert using")
2626
.option("--typescript [typescript]", "typescript configuration file to convert using")
2727
.option("--editor [editor]", "editor configuration file to convert")
28-
.option("-c --convertComments", "convert all tslint:disable comments into eslint-disable")
28+
.option("-C --convertComments", "convert all tslint:disable comments into eslint-disable")
2929
.option("-V --version", "output the package version");
3030

3131
const parsedArgv = {

src/rules/convertComments.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FileSystem } from "../adapters/fileSystem";
22
import { isError } from "../utils";
33
import * as utils from "tsutils";
44
import ts from "typescript";
5-
import { converters } from "./converters";
5+
import { rulesConverters } from "./rulesConverters";
66
import { formatRawTslintRule } from "./formatRawTslintRule";
77
import { ConversionError } from "../errors/conversionError";
88

@@ -13,7 +13,7 @@ export type ConvertCommentsResultsDependencies = {
1313
fileSystem: Pick<FileSystem, "readDir" | "readFile" | "writeFile" | "writeFileSync">;
1414
};
1515

16-
const tslintRegex: RegExp = new RegExp(/\s*tslint:(enable|disable)(?:-(line|next-line))?(:|\s|$)/g);
16+
const tslintRegex = new RegExp(/\s*tslint:(enable|disable)(?:-(line|next-line))?(:|\s|$)/g);
1717

1818
export const convertComments = async (dependencies: ConvertCommentsResultsDependencies) => {
1919
// TODO: Remove console logs
@@ -36,9 +36,8 @@ export const convertComments = async (dependencies: ConvertCommentsResultsDepend
3636
}
3737
}
3838
return undefined;
39-
} else {
40-
return Error("Failed to convert file comments");
4139
}
40+
return Error("Failed to convert file comments");
4241
};
4342

4443
type Modifier = "line" | "next-line" | undefined;
@@ -58,7 +57,7 @@ function parseComment(
5857
// nothing to do here: an explicit separator was specified but no rules to switch
5958
return undefined;
6059
}
61-
if (rulesList.length === 0 || rulesList.indexOf("all") !== -1) {
60+
if (rulesList.length === 0 || rulesList.includes("all")) {
6261
// if list is empty we default to all enabled rules
6362
// if `all` is specified we ignore the other rules and take all enabled rules
6463
rulesList = "all";
@@ -71,11 +70,11 @@ function splitOnSpaces(str: string): string[] {
7170
return str.split(/\s+/).filter(s => s !== "");
7271
}
7372

74-
interface IReplacement {
73+
type IReplacement = {
7574
start: number;
7675
end: number;
7776
replacementText: string;
78-
}
77+
};
7978

8079
const replaceComments = async (
8180
_dependencies: ConvertCommentsResultsDependencies,
@@ -103,16 +102,17 @@ const replaceComments = async (
103102
const { rulesList, modifier } = parsed;
104103
const switchRange = getSwitchRange(modifier, comment, sourceFile);
105104
if (switchRange !== undefined) {
106-
console.log("---------- COMMENT TEXT -----------");
105+
// Extra log to check what is going on
106+
console.log("----------- COMMENT TEXT -----------");
107107
console.log(commentText);
108-
console.log("PARSED DATA");
108+
console.log("----------- PARSED DATA -----------");
109109
console.log(parsed);
110-
console.log("SWITCH RANGE");
110+
console.log("----------- SWITCH RANGE -----------");
111111
console.log(switchRange);
112112
const rulesToSwitch =
113113
rulesList === "all"
114-
? Array.from(converters.keys())
115-
: rulesList.filter(ruleKey => converters.has(ruleKey));
114+
? Array.from(rulesConverters.keys())
115+
: rulesList.filter(ruleKey => rulesConverters.has(ruleKey));
116116
for (const ruleToSwitch of rulesToSwitch) {
117117
const transformedRules = switchRule(ruleToSwitch);
118118
if (transformedRules) {
@@ -129,9 +129,13 @@ const replaceComments = async (
129129
replacements.reverse();
130130

131131
const newText = getNewText(fileContent, replacements);
132+
// Check the output before writing to file.
133+
console.log("");
132134
console.log("************** NEW FILE BEING WRITTEN ! **************");
133135
console.log(newText);
134-
// dependencies.fileSystem.writeFileSync(fileName, newText);
136+
// Write the file with the changes.
137+
// At the moment,
138+
_dependencies.fileSystem.writeFileSync(fileName, newText);
135139
});
136140
return true;
137141
};
@@ -145,7 +149,7 @@ function getNewText(sourceText: string, replacementsInReverse: IReplacement[]) {
145149
}
146150

147151
function switchRule(ruleName: string): string[] | null {
148-
const tslintRuleConverter = converters.get(ruleName);
152+
const tslintRuleConverter = rulesConverters.get(ruleName);
149153
if (tslintRuleConverter) {
150154
const tslintRule = formatRawTslintRule(ruleName, { ruleName });
151155
const conversion = tslintRuleConverter(tslintRule);

0 commit comments

Comments
 (0)