Skip to content
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

implemented treat warning as errors commandline option. #966

Merged
merged 6 commits into from
Nov 17, 2014

Conversation

DickvdBrink
Copy link
Contributor

Same name as csc.exe uses: msdn
Issue #828

Feedback appreciated but feel free to close when you don't want this functionality at this point :)

@@ -1092,6 +1092,7 @@ module ts {
sourceRoot?: string;
target?: ScriptTarget;
version?: boolean;
warnaserror?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Please camelCase this

@CyrusNajmabadi
Copy link
Contributor

I"m not sure what the purpose of this is. Do we have any actual warnings in typescript today?

@DickvdBrink
Copy link
Contributor Author

@CyrusNajmabadi Not real warnings but when would type this:

var foo: number = "test";

It would still create a file with output with valid JavaScript. I added this piece of code because the issue I linked to is having the label "Accepting PR".
DanQuirk is right about the EmitReturnStatus enum so this code might not be really needed but than I think that issue should be closed as well?

@mhegazy
Copy link
Contributor

mhegazy commented Oct 26, 2014

I think we need that for some scenarios. Incremental build with errors for instance does not work wiper simthing like this.

I do not like the name of the flag; users will have the same reaction as @CyrusNajmabadi. I can not find a good name though, may be suppressEmitWithErrors or early..

@DanielRosenwasser
Copy link
Member

I'm also not big on the name, but I'm at a loss for significantly better ones.

  • emitOnCleanBuild
  • emitCleanBuildsOnly
  • noEmitOnAnyErrors

@RyanCavanaugh
Copy link
Member

I like (or at least tolerate better) noEmitOnError[s] or emitCleanOnly. We're consistent in terminology about type errors being "errors" and not "warnings".

@danquirk
Copy link
Member

yeah I think noEmitOnErrors is sufficiently clear and concise

@@ -364,6 +364,7 @@ module ts {
Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." },
Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." },
Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
Do_not_emit_JavaScript_on_error: { code: 6007, category: DiagnosticCategory.Message, key: "Do not emit JavaScript on error." },
Copy link
Contributor

Choose a reason for hiding this comment

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

I would change this to: "Do not emit outputs if any type checking errors were reported"

Copy link
Contributor

Choose a reason for hiding this comment

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

“type checking” is a very compiler-team specific term. Really, all we’re trying to say is “Do not emit any outputs if any errors were reported.”

       -- Cyrus

From: Mohamed Hegazy [mailto:notifications@github.com]
Sent: Monday, October 27, 2014 3:38 PM
To: Microsoft/TypeScript
Cc: Cyrus Najmabadi
Subject: Re: [TypeScript] implemented treat warning as errors commandline option. (#966)

In src/compiler/diagnosticInformationMap.generated.ts:

@@ -364,6 +364,7 @@ module ts {

     Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: { code: 6004, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate TypeScript files instead of source locations." },

     Watch_input_files: { code: 6005, category: DiagnosticCategory.Message, key: "Watch input files." },

     Redirect_output_structure_to_the_directory: { code: 6006, category: DiagnosticCategory.Message, key: "Redirect output structure to the directory." },
  •    Do_not_emit_JavaScript_on_error: { code: 6007, category: DiagnosticCategory.Message, key: "Do not emit JavaScript on error." },
    

I would change this to: "Do not emit outputs if any type checking errors were reported"


Reply to this email directly or view it on GitHubhttps://github.com//pull/966/files#r19442813.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 28, 2014

The logic on whether to emit or not is used in three places, 1. tsc.ts (batch compiler), and you got that, 2. emitter.ts (used by compile on save), and 3. harness.ts (used by the tests to mimic the batch compiler behavior). we need to ensure that all 3 do the same thing.
I would change the name of hasEarlyError to isEmitBlocked and add the check for the option and the error as well. i would also check global errors and syntax errors (program.getDiagnostics().length === 0) to be safe.

something like this:

function isEmitBlocked(sourceFile?: SourceFile): boolean {
    return program.getDiagnostics(sourceFile).length !== 0 ||
        hasEarlyErrors(sourceFile) ||
        (compilerOptions.noEmitOnError  && getDiagnostics(sourceFile));
}

Note: sourceFile is needed here, but it is optional. in case of batch compiler, sourceFile is not specified, as we want to do the check globally. but for compile on save, we want to do the check on one file only.

One more thing, we will need a unit test for this. Unit tests use reads "// @: value" from the beginning of the file, and uses them to set compilation settings. look at the switch statement in: https://github.com/Microsoft/TypeScript/blob/master/src/harness/harness.ts#L672

Then add a test that has "// @noEmitOnErrors: true" and ensure that there are no outputs. i would also add a @sourcemap and @declaration

@DickvdBrink
Copy link
Contributor Author

Added some new commits.
Also renamed the hasEarlyErrors method in the interface to is isEmitBlocked (which is what you meant right? or does this break things with VS maybe?)
Changed some things in harness.ts to make it work.

For future reference the link to harness with SHA in the url harness.ts. (You can create this url by clicking on a line number and press 'y' and it will always be the right one)

@@ -175,7 +175,11 @@ class CompilerBaselineRunner extends RunnerBase {
it('Correct sourcemap content for ' + fileName, () => {
if (options.sourceMap) {
Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => {
return result.getSourceMapRecord();
var record = result.getSourceMapRecord();
if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a situation in which record can be undefined but the condition options.noEmitOnError && result.errors.length !== 0 evaluates to false? Perhaps a || is more appropriate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if || is more appropriate here, when for example noEmitOnError is true and there are errors and record is not undefined (because getSourceMapRecord returned a sourcemap).. then it should actually try to compare them right?

Copy link
Member

Choose a reason for hiding this comment

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

I'm curious, do you actually get an empty sourcemap file if you don't perform this check?

Sorry, I'm personally not familiar enough with the harness code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it did, runBaseline calls generateActual: https://github.com/Microsoft/TypeScript/blob/5ce3baf339e0424263069c70f0ea239bc3cea96a/src/harness/harness.ts#L1307 which creates the file when it is something different than null. It throws an error when it is undefined.

@yuit
Copy link
Contributor

yuit commented Oct 29, 2014

Comments for isEarly and hasEarlyError will make it clearer.

@DickvdBrink
Copy link
Contributor Author

Thanks for feedback everyone. Will add some comments in compilerRunner.ts
@yuit Comments for isEarly and hasEarlyError will make it clearer
Sorry, don't know what you mean here (where do you want such comments?)

@yuit
Copy link
Contributor

yuit commented Oct 29, 2014

For some reasons I can't see where you defined hasEarlyError in the change list. However, what I mean is that could you add comment at the when you declare function hasEarlyError and property isEarly in the Diagnostics. I am not sure what is the property is for

@DickvdBrink
Copy link
Contributor Author

hasEarlyError was already there, the messages which have isEarly are in diagnosticMessages.json
I'm actually not really sure why those have isEarly so I can't really add a comment for it.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 30, 2014

👍

@mhegazy
Copy link
Contributor

mhegazy commented Nov 16, 2014

@DickvdBrink extremely sorry for the delay. This totally fell off my radar. The PR is ready to go, can you refresh the PR by merging from main.

Conflicts:
	src/compiler/diagnosticInformationMap.generated.ts
	src/compiler/diagnosticMessages.json
	src/compiler/types.ts
	src/harness/harness.ts
@DickvdBrink
Copy link
Contributor Author

@mhegazy no problem, better late than never right ;)
Updated PR and after the merge I ran the tests again and noticed that my baseline had changed so fixed that in another commit

mhegazy added a commit that referenced this pull request Nov 17, 2014
implemented treat warning as errors commandline option.
@mhegazy mhegazy merged commit d5cfceb into microsoft:master Nov 17, 2014
@mhegazy
Copy link
Contributor

mhegazy commented Nov 17, 2014

thanks, and sorry again for the delay.

@DickvdBrink DickvdBrink deleted the warnaserror branch November 23, 2014 23:49
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants