@@ -20,16 +20,23 @@ namespace ts.codefix {
20
20
let { line } = getLineAndCharacterOfPosition ( sourceFile , position ) ;
21
21
const lineStartPosition = getStartPositionOfLine ( line , sourceFile ) ;
22
22
const startPosition = getFirstNonSpaceCharacterPosition ( sourceFile . text , lineStartPosition ) ;
23
+
24
+ // First try to see if we can put the '// @ts-suppress' on the previous line.
25
+ // We need to make sure that we are not in the middle of a string literal or a comment.
26
+ // We also want to check if the previous line holds a comment for a node on the next line
27
+ // if so, we do not want to separate the node from its comment if we can.
23
28
if ( ! isInComment ( sourceFile , startPosition ) && ! isInString ( sourceFile , startPosition ) && ! isInTemplateString ( sourceFile , startPosition ) ) {
24
29
const token = getTouchingToken ( sourceFile , startPosition ) ;
25
- const tokenLeadingCommnets = getLeadingCommentRangesOfNode ( token , sourceFile )
30
+ const tokenLeadingCommnets = getLeadingCommentRangesOfNode ( token , sourceFile ) ;
26
31
if ( ! tokenLeadingCommnets || ! tokenLeadingCommnets . length || tokenLeadingCommnets [ 0 ] . pos >= startPosition ) {
27
32
return {
28
33
span : { start : startPosition , length : 0 } ,
29
34
newText : `// @ts-suppress${ newLineCharacter } `
30
35
} ;
31
36
}
32
37
}
38
+
39
+ // If all fails, add an extra new line immediatlly before the error span.
33
40
return {
34
41
span : { start : position , length : 0 } ,
35
42
newText : `${ position === startPosition ? "" : newLineCharacter } // @ts-suppress${ newLineCharacter } `
0 commit comments