-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to report errors in js files #14496
Merged
Merged
Changes from 7 commits
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 0b1fff7
Add `--checkJsFiles`
mhegazy 9f0c5ce
Add support for `//@check` directives
mhegazy 0b247b1
Add tests
mhegazy 1f9bb69
Add --noEmit to tests
mhegazy b015c1d
Allow @check directives to switch on/off checking in a file
mhegazy 9305d4d
Change flag name to `checkJs`
mhegazy fb218b7
Error if `--checkJs` is used without `--allowJs`
mhegazy e9f8214
Code review comments
mhegazy a202fa4
add es6 to buildProtocol
mhegazy 3d03f8d
Merge branch 'fixBuildBreak' into checkJSFiles
mhegazy fe7719f
Disable check diagnostics per line
mhegazy 706acdf
Add quick fix to disable error checking in a .js file
mhegazy 13e80b9
Fix building webTestServer
mhegazy 936a91d
Add comment
mhegazy cc6affa
Merge remote-tracking branch 'origin/updateCodeFixForAddMissingMember…
mhegazy 6e86596
Add debugging utilities
mhegazy fd9fb8f
Support static properties
mhegazy 509b2dc
Add disableJsDiagnostics codefixes to harnes
mhegazy 1fbbead
Merge pull request #14568 from Microsoft/checkJSFiles_QuickFixes
mhegazy 7980629
Code review comments
mhegazy 0dac29f
Merge branch 'master' into checkJSFiles
mhegazy 3b57b5d
Refactor checking for checkJs value in a common helper
mhegazy e408cad
Merge branch 'master' into checkJSFiles
mhegazy db6c969
Change ingore diagonstic comment to `// @ts-ignore`
mhegazy 3378f5c
Merge branch 'master' into checkJSFiles
mhegazy e630ab1
Report semantic errors for JS files if checkJs is enabled
mhegazy 0637f24
Merge remote-tracking branch 'origin/master' into checkJSFiles
mhegazy 8ea9617
Merge remote-tracking branch 'origin/master' into checkJSFiles
mhegazy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -904,10 +904,10 @@ namespace ts { | |
|
||
Debug.assert(!!sourceFile.bindDiagnostics); | ||
const bindDiagnostics = sourceFile.bindDiagnostics; | ||
// For JavaScript files, we don't want to report semantic errors. | ||
// Instead, we'll report errors for using TypeScript-only constructs from within a | ||
// JavaScript file when we get syntactic diagnostics for the file. | ||
const checkDiagnostics = isSourceFileJavaScript(sourceFile) ? [] : typeChecker.getDiagnostics(sourceFile, cancellationToken); | ||
// For JavaScript files, we don't want to report semantic errors unless ecplicitlly requested. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spelling |
||
const includeCheckDiagnostics = !isSourceFileJavaScript(sourceFile) || | ||
(sourceFile.checkJsDirective ? sourceFile.checkJsDirective.enabled : options.checkJs); | ||
const checkDiagnostics = includeCheckDiagnostics ? typeChecker.getDiagnostics(sourceFile, cancellationToken) : []; | ||
const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); | ||
const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); | ||
|
||
|
@@ -1685,6 +1685,10 @@ namespace ts { | |
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration")); | ||
} | ||
|
||
if (options.checkJs && !options.allowJs) { | ||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs")); | ||
} | ||
|
||
if (options.emitDecoratorMetadata && | ||
!options.experimentalDecorators) { | ||
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "emitDecoratorMetadata", "experimentalDecorators")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
tests/cases/compiler/a.js(3,1): error TS2322: Type '0' is not assignable to type 'string'. | ||
|
||
|
||
==== tests/cases/compiler/a.js (1 errors) ==== | ||
|
||
var x = "string"; | ||
x = 0; | ||
~ | ||
!!! error TS2322: Type '0' is not assignable to type 'string'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tests/cases/compiler/a.js(4,1): error TS2322: Type '0' is not assignable to type 'string'. | ||
|
||
|
||
==== tests/cases/compiler/a.js (1 errors) ==== | ||
|
||
// @check | ||
var x = "string"; | ||
x = 0; | ||
~ | ||
!!! error TS2322: Type '0' is not assignable to type 'string'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tests/cases/compiler/a.js(4,1): error TS2322: Type '0' is not assignable to type 'string'. | ||
|
||
|
||
==== tests/cases/compiler/a.js (1 errors) ==== | ||
|
||
// @check | ||
var x = "string"; | ||
x = 0; | ||
~ | ||
!!! error TS2322: Type '0' is not assignable to type 'string'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
tests/cases/compiler/a.js(4,1): error TS2322: Type '0' is not assignable to type 'string'. | ||
|
||
|
||
==== tests/cases/compiler/a.js (1 errors) ==== | ||
|
||
// @check true | ||
var x = "string"; | ||
x = 0; | ||
~ | ||
!!! error TS2322: Type '0' is not assignable to type 'string'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
=== tests/cases/compiler/a.js === | ||
|
||
// @check false | ||
var x = "string"; | ||
>x : Symbol(x, Decl(a.js, 2, 3)) | ||
|
||
x = 0; | ||
>x : Symbol(x, Decl(a.js, 2, 3)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
=== tests/cases/compiler/a.js === | ||
|
||
// @check false | ||
var x = "string"; | ||
>x : string | ||
>"string" : "string" | ||
|
||
x = 0; | ||
>x = 0 : 0 | ||
>x : string | ||
>0 : 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error TS5052: Option 'checkJs' cannot be specified without specifying option 'allowJs'. | ||
error TS6054: File 'tests/cases/compiler/a.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. | ||
|
||
|
||
!!! error TS5052: Option 'checkJs' cannot be specified without specifying option 'allowJs'. | ||
!!! error TS6054: File 'tests/cases/compiler/a.js' has unsupported extension. The only supported extensions are '.ts', '.tsx', '.d.ts'. | ||
==== tests/cases/compiler/a.js (0 errors) ==== | ||
|
||
var x; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
|
||
// @fileName: a.js | ||
var x = "string"; | ||
x = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @allowJs: true | ||
// @checkJs: false | ||
// @noEmit: true | ||
|
||
// @fileName: a.js | ||
// @check | ||
var x = "string"; | ||
x = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// @allowJs: true | ||
// @noEmit: true | ||
|
||
// @fileName: a.js | ||
// @check | ||
var x = "string"; | ||
x = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @allowJs: true | ||
// @checkJs: false | ||
// @noEmit: true | ||
|
||
// @fileName: a.js | ||
// @check true | ||
var x = "string"; | ||
x = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
|
||
// @fileName: a.js | ||
// @check false | ||
var x = "string"; | ||
x = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// @allowJs: false | ||
// @checkJs: true | ||
// @noEmit: true | ||
|
||
// @fileName: a.js | ||
var x; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe an @nocheck directive?