Skip to content

Option to fail on warnings #3451

@l1bbcsg

Description

@l1bbcsg

I would like to propose an option that could make the compiler fail if at least one warning is encountered, regardless of errors and exit with a non-zero exit code.

This could be a simple flags such as --fail-on-warnings or a more sophisticated setting like --error-level that could introduce more granular control, i.e. still exit with 0 if compilation failed with errors.

Use case for this is either a purist approach when no warnings are tolerated or code quality control CI job that verifies new code with --checks-only.

Activity

brad4d

brad4d commented on Aug 13, 2019

@brad4d
Contributor

I believe this option already exists. The magic words are --jscomp_error=* to say "treat all diagnostic groups as errors".

l1bbcsg

l1bbcsg commented on Aug 14, 2019

@l1bbcsg
Author

I don't think this is quite the right option. It seems to change behaviour much more elevating a lot of other warnings that are not normally reported to errors.

This example:

/**
 * @type {number}
 */
let a = 10;

a = 'foo'

Produces a warning:

google-closure-compiler a.js --checks_only --warning_level verbose
a.js:6: WARNING - [JSC_TYPE_MISMATCH] assignment
found   : string
required: number
a = 'foo'
^^^^^^^^^

0 error(s), 1 warning(s), 100.0% typed

But with --jscomp_error=* there are now two errors:

google-closure-compiler a.js --checks_only --warning_level verbose --jscomp_error=*
a.js:6: ERROR - [JSC_MISSING_SEMICOLON] Missing semicolon
a = 'foo'
^^^^^^^^^

a.js:6: ERROR - [JSC_TYPE_MISMATCH] assignment
found   : string
required: number
a = 'foo'
^^^^^^^^^

2 error(s), 0 warning(s), 100.0% typed

On a large code base I encountered many more new errors and compiler actually crashed with java.lang.RuntimeException: INTERNAL COMPILER ERROR.

brad4d

brad4d commented on Aug 14, 2019

@brad4d
Contributor

Created internal issue
http://b/139437890

reopened this on Aug 14, 2019
brad4d

brad4d commented on Aug 14, 2019

@brad4d
Contributor

This is looking harder to do than I'd wish, but I think the gist is that the proposed option would need to trigger doing options.addWarningsGuard(new StrictWarningsGuard()) when the compiler options are created in CommandLineRunner#createOptions().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedinternal-issue-createdAn internal Google issue has been created to track this GitHub issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @l1bbcsg@brad4d

        Issue actions

          Option to fail on warnings · Issue #3451 · google/closure-compiler