@@ -2,7 +2,7 @@ import { FileSystem } from "../adapters/fileSystem";
2
2
import { isError } from "../utils" ;
3
3
import * as utils from "tsutils" ;
4
4
import ts from "typescript" ;
5
- import { converters } from "./converters " ;
5
+ import { rulesConverters } from "./rulesConverters " ;
6
6
import { formatRawTslintRule } from "./formatRawTslintRule" ;
7
7
import { ConversionError } from "../errors/conversionError" ;
8
8
@@ -13,7 +13,7 @@ export type ConvertCommentsResultsDependencies = {
13
13
fileSystem : Pick < FileSystem , "readDir" | "readFile" | "writeFile" | "writeFileSync" > ;
14
14
} ;
15
15
16
- const tslintRegex : RegExp = new RegExp ( / \s * t s l i n t : ( e n a b l e | d i s a b l e ) (?: - ( l i n e | n e x t - l i n e ) ) ? ( : | \s | $ ) / g) ;
16
+ const tslintRegex = new RegExp ( / \s * t s l i n t : ( e n a b l e | d i s a b l e ) (?: - ( l i n e | n e x t - l i n e ) ) ? ( : | \s | $ ) / g) ;
17
17
18
18
export const convertComments = async ( dependencies : ConvertCommentsResultsDependencies ) => {
19
19
// TODO: Remove console logs
@@ -36,9 +36,8 @@ export const convertComments = async (dependencies: ConvertCommentsResultsDepend
36
36
}
37
37
}
38
38
return undefined ;
39
- } else {
40
- return Error ( "Failed to convert file comments" ) ;
41
39
}
40
+ return Error ( "Failed to convert file comments" ) ;
42
41
} ;
43
42
44
43
type Modifier = "line" | "next-line" | undefined ;
@@ -58,7 +57,7 @@ function parseComment(
58
57
// nothing to do here: an explicit separator was specified but no rules to switch
59
58
return undefined ;
60
59
}
61
- if ( rulesList . length === 0 || rulesList . indexOf ( "all" ) !== - 1 ) {
60
+ if ( rulesList . length === 0 || rulesList . includes ( "all" ) ) {
62
61
// if list is empty we default to all enabled rules
63
62
// if `all` is specified we ignore the other rules and take all enabled rules
64
63
rulesList = "all" ;
@@ -71,11 +70,11 @@ function splitOnSpaces(str: string): string[] {
71
70
return str . split ( / \s + / ) . filter ( s => s !== "" ) ;
72
71
}
73
72
74
- interface IReplacement {
73
+ type IReplacement = {
75
74
start : number ;
76
75
end : number ;
77
76
replacementText : string ;
78
- }
77
+ } ;
79
78
80
79
const replaceComments = async (
81
80
_dependencies : ConvertCommentsResultsDependencies ,
@@ -103,16 +102,17 @@ const replaceComments = async (
103
102
const { rulesList, modifier } = parsed ;
104
103
const switchRange = getSwitchRange ( modifier , comment , sourceFile ) ;
105
104
if ( switchRange !== undefined ) {
106
- console . log ( "---------- COMMENT TEXT -----------" ) ;
105
+ // Extra log to check what is going on
106
+ console . log ( "----------- COMMENT TEXT -----------" ) ;
107
107
console . log ( commentText ) ;
108
- console . log ( "PARSED DATA" ) ;
108
+ console . log ( "----------- PARSED DATA ----------- " ) ;
109
109
console . log ( parsed ) ;
110
- console . log ( "SWITCH RANGE" ) ;
110
+ console . log ( "----------- SWITCH RANGE ----------- " ) ;
111
111
console . log ( switchRange ) ;
112
112
const rulesToSwitch =
113
113
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 ) ) ;
116
116
for ( const ruleToSwitch of rulesToSwitch ) {
117
117
const transformedRules = switchRule ( ruleToSwitch ) ;
118
118
if ( transformedRules ) {
@@ -129,9 +129,13 @@ const replaceComments = async (
129
129
replacements . reverse ( ) ;
130
130
131
131
const newText = getNewText ( fileContent , replacements ) ;
132
+ // Check the output before writing to file.
133
+ console . log ( "" ) ;
132
134
console . log ( "************** NEW FILE BEING WRITTEN ! **************" ) ;
133
135
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 ) ;
135
139
} ) ;
136
140
return true ;
137
141
} ;
@@ -145,7 +149,7 @@ function getNewText(sourceText: string, replacementsInReverse: IReplacement[]) {
145
149
}
146
150
147
151
function switchRule ( ruleName : string ) : string [ ] | null {
148
- const tslintRuleConverter = converters . get ( ruleName ) ;
152
+ const tslintRuleConverter = rulesConverters . get ( ruleName ) ;
149
153
if ( tslintRuleConverter ) {
150
154
const tslintRule = formatRawTslintRule ( ruleName , { ruleName } ) ;
151
155
const conversion = tslintRuleConverter ( tslintRule ) ;
0 commit comments