Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
91571f0
Add support for handeling .js file correctelly in fixAddMissingMember…
mhegazy Feb 23, 2017
0b1fff7
Add `--checkJsFiles`
mhegazy Jan 7, 2017
9f0c5ce
Add support for `//@check` directives
mhegazy Jan 7, 2017
0b247b1
Add tests
mhegazy Mar 6, 2017
1f9bb69
Add --noEmit to tests
mhegazy Mar 7, 2017
b015c1d
Allow @check directives to switch on/off checking in a file
mhegazy Mar 7, 2017
9305d4d
Change flag name to `checkJs`
mhegazy Mar 7, 2017
fb218b7
Error if `--checkJs` is used without `--allowJs`
mhegazy Mar 7, 2017
e9f8214
Code review comments
mhegazy Mar 8, 2017
a202fa4
add es6 to buildProtocol
mhegazy Mar 9, 2017
3d03f8d
Merge branch 'fixBuildBreak' into checkJSFiles
mhegazy Mar 9, 2017
fe7719f
Disable check diagnostics per line
mhegazy Mar 8, 2017
706acdf
Add quick fix to disable error checking in a .js file
mhegazy Mar 7, 2017
13e80b9
Fix building webTestServer
mhegazy Mar 7, 2017
936a91d
Add comment
mhegazy Mar 10, 2017
cc6affa
Merge remote-tracking branch 'origin/updateCodeFixForAddMissingMember…
mhegazy Mar 14, 2017
6e86596
Add debugging utilities
mhegazy Mar 14, 2017
fd9fb8f
Support static properties
mhegazy Mar 14, 2017
509b2dc
Add disableJsDiagnostics codefixes to harnes
mhegazy Mar 14, 2017
1fbbead
Merge pull request #14568 from Microsoft/checkJSFiles_QuickFixes
mhegazy Mar 14, 2017
7980629
Code review comments
mhegazy Mar 15, 2017
0dac29f
Merge branch 'master' into checkJSFiles
mhegazy Mar 15, 2017
3b57b5d
Refactor checking for checkJs value in a common helper
mhegazy Mar 15, 2017
e408cad
Merge branch 'master' into checkJSFiles
mhegazy Mar 22, 2017
db6c969
Change ingore diagonstic comment to `// @ts-ignore`
mhegazy Mar 22, 2017
3378f5c
Merge branch 'master' into checkJSFiles
mhegazy Mar 27, 2017
e630ab1
Report semantic errors for JS files if checkJs is enabled
mhegazy Mar 27, 2017
0637f24
Merge remote-tracking branch 'origin/master' into checkJSFiles
mhegazy Mar 28, 2017
8ea9617
Merge remote-tracking branch 'origin/master' into checkJSFiles
mhegazy Mar 28, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change ingore diagonstic comment to // @ts-ignore
  • Loading branch information
mhegazy committed Mar 22, 2017
commit db6c96967cb856c6eeadae5b87ca34178664aca2
2 changes: 1 addition & 1 deletion src/compiler/core.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path="types.ts"/>
/// <reference path="types.ts"/>
/// <reference path="performance.ts" />

namespace ts {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3484,7 +3484,7 @@
"category": "Message",
"code": 90018
},
"Suppress this error message.": {
"Ignore this error message.": {
"category": "Message",
"code": 90019
},
Expand Down
10 changes: 5 additions & 5 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// <reference path="sys.ts" />
/// <reference path="sys.ts" />
/// <reference path="emitter.ts" />
/// <reference path="core.ts" />

namespace ts {
const emptyArray: any[] = [];
const suppressDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-suppress)?)/;
const ignoreDiagnosticCommentRegEx = /(^\s*$)|(^\s*\/\/\/?\s*(@ts-ignore)?)/;

export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string {
while (true) {
Expand Down Expand Up @@ -926,21 +926,21 @@ namespace ts {
}

/**
* Skip errors if previous line start with '// @ts-suppress' comment, not counting non-empty non-comment lines
* Skip errors if previous line start with '// @ts-ignore' comment, not counting non-empty non-comment lines
*/
function shouldReportDiagnostic(diagnostic: Diagnostic) {
const { file, start } = diagnostic;
const lineStarts = getLineStarts(file);
let { line } = computeLineAndCharacterOfPosition(lineStarts, start);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • can line have more than one error where only one should be suppresed
  • seems that ts-suppress should be located immediately before the line to be suppressed so if user will put a comment between ts-suppress and target line it will stop working. Is it intended?

while (line > 0) {
const previousLineText = file.text.slice(lineStarts[line - 1], lineStarts[line]);
const result = suppressDiagnosticCommentRegEx.exec(previousLineText);
const result = ignoreDiagnosticCommentRegEx.exec(previousLineText);
if (!result) {
// non-empty line
return true;
}
if (result[3]) {
// @ts-suppress
// @ts-ignore
return false;
}
line--;
Expand Down
2 changes: 1 addition & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
16 changes: 8 additions & 8 deletions src/services/codefixes/disableJsDiagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @internal */
/* @internal */
namespace ts.codefix {
registerCodeFix({
errorCodes: getApplicableDiagnosticCodes(),
Expand All @@ -12,12 +12,12 @@ namespace ts.codefix {
.map(d => allDiagnostcs[d].code);
}

function getSuppressCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string) {
let { line } = getLineAndCharacterOfPosition(sourceFile, position);
function getIgnoreCommentLocationForLocation(sourceFile: SourceFile, position: number, newLineCharacter: string) {
const { line } = getLineAndCharacterOfPosition(sourceFile, position);
const lineStartPosition = getStartPositionOfLine(line, sourceFile);
const startPosition = getFirstNonSpaceCharacterPosition(sourceFile.text, lineStartPosition);

// First try to see if we can put the '// @ts-suppress' on the previous line.
// First try to see if we can put the '// @ts-ignore' on the previous line.
// We need to make sure that we are not in the middle of a string literal or a comment.
// We also want to check if the previous line holds a comment for a node on the next line
// if so, we do not want to separate the node from its comment if we can.
Expand All @@ -27,15 +27,15 @@ namespace ts.codefix {
if (!tokenLeadingCommnets || !tokenLeadingCommnets.length || tokenLeadingCommnets[0].pos >= startPosition) {
return {
span: { start: startPosition, length: 0 },
newText: `// @ts-suppress${newLineCharacter}`
newText: `// @ts-ignore${newLineCharacter}`
};
}
}

// If all fails, add an extra new line immediatlly before the error span.
return {
span: { start: position, length: 0 },
newText: `${position === startPosition ? "" : newLineCharacter}// @ts-suppress${newLineCharacter}`
newText: `${position === startPosition ? "" : newLineCharacter}// @ts-ignore${newLineCharacter}`
};
}

Expand All @@ -47,10 +47,10 @@ namespace ts.codefix {
}

return [{
description: getLocaleSpecificMessage(Diagnostics.Suppress_this_error_message),
description: getLocaleSpecificMessage(Diagnostics.Ignore_this_error_message),
changes: [{
fileName: sourceFile.fileName,
textChanges: [getSuppressCommentLocationForLocation(sourceFile, span.start, newLineCharacter)]
textChanges: [getIgnoreCommentLocationForLocation(sourceFile, span.start, newLineCharacter)]
}]
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/services/codefixes/fixAddMissingMember.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @internal */
/* @internal */
namespace ts.codefix {
registerCodeFix({
errorCodes: [Diagnostics.Property_0_does_not_exist_on_type_1.code],
Expand Down
10 changes: 5 additions & 5 deletions tests/baselines/reference/checkJsFiles_skipDiagnostics.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ var x = 0;
>x : Symbol(x, Decl(a.js, 1, 3))


/// @ts-suppress
/// @ts-ignore
x();
>x : Symbol(x, Decl(a.js, 1, 3))

/// @ts-suppress
/// @ts-ignore
x();
>x : Symbol(x, Decl(a.js, 1, 3))

/// @ts-suppress
/// @ts-ignore
x(
>x : Symbol(x, Decl(a.js, 1, 3))

Expand All @@ -21,7 +21,7 @@ x(



// @ts-suppress
// @ts-ignore
// come comment
// some other comment

Expand All @@ -32,7 +32,7 @@ x();



// @ts-suppress: no call signature
// @ts-ignore: no call signature
x();
>x : Symbol(x, Decl(a.js, 1, 3))

10 changes: 5 additions & 5 deletions tests/baselines/reference/checkJsFiles_skipDiagnostics.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ var x = 0;
>0 : 0


/// @ts-suppress
/// @ts-ignore
x();
>x() : any
>x : number

/// @ts-suppress
/// @ts-ignore
x();
>x() : any
>x : number

/// @ts-suppress
/// @ts-ignore
x(
>x( 2, 3) : any
>x : number
Expand All @@ -28,7 +28,7 @@ x(



// @ts-suppress
// @ts-ignore
// come comment
// some other comment

Expand All @@ -40,7 +40,7 @@ x();



// @ts-suppress: no call signature
// @ts-ignore: no call signature
x();
>x() : any
>x : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
// "lib": [], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
// "lib": [], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
// "lib": [], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
// "lib": [], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
"lib": ["es5","es2015.promise"], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
// "lib": [], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
"lib": ["es5","es2015.core"], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */
// "lib": [], /* Specify library files to be included in the compilation: */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
Expand Down
10 changes: 5 additions & 5 deletions tests/cases/compiler/checkJsFiles_skipDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
var x = 0;


/// @ts-suppress
/// @ts-ignore
x();

/// @ts-suppress
/// @ts-ignore
x();

/// @ts-suppress
/// @ts-ignore
x(
2,
3);



// @ts-suppress
// @ts-ignore
// come comment
// some other comment

Expand All @@ -29,5 +29,5 @@ x();



// @ts-suppress: no call signature
// @ts-ignore: no call signature
x();
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

// Disable checking for next line
verify.rangeAfterCodeFix(`var x = "";
// @ts-suppress
// @ts-ignore
x = 1;`, /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0);
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
// Disable checking for next line
verify.rangeAfterCodeFix(`"test \\
";
// @ts-suppress
// @ts-ignore
x = 1;`, /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0);

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

// Disable checking for next line
verify.rangeAfterCodeFix(`/** comment */
// @ts-suppress
// @ts-ignore
x = 1;`, /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0);

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
////}

// Disable checking for next line
verify.rangeAfterCodeFix(`// @ts-suppress
verify.rangeAfterCodeFix(`// @ts-ignore
f(x());`, /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0);

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
////}

// Disable checking for next line
verify.rangeAfterCodeFix(`// @ts-suppress
verify.rangeAfterCodeFix(`// @ts-ignore
x();`, /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0);

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

// Disable checking for next line
verify.rangeAfterCodeFix(`f(
// @ts-suppress
// @ts-ignore
x());`, /*includeWhiteSpace*/ false, /*errorCode*/ undefined, /*index*/ 0);