Supress specific warnings/errors

334 Views Asked by At

1. Summary

I couldn’t find, how I can get all warnings for all files except specific warnings (not suppression tags).

In my case, I can’t suppress WARNING - [JSC_VAR] Using var (prefer const or let).

2. MCVE

2.1. Data

  1. KiraVar.js:

    var KiraVariable = 4147;
    
  2. CLI command:

    google-closure-compiler --js KiraVar.js --language_out ECMASCRIPT_NEXT --warning_level VERBOSE  --jscomp_warning *
    

2.2. Behavior

2.2.1. Expected

No warnings.

2.2.2. Current
KiraVar.js:1:0: WARNING - [JSC_VAR] Using `var` (prefer `const` or `let`).
  1| var KiraVariable = 4147;
     ^^^^^^^^^^^^^^^^^^^^^^^^

0 error(s), 1 warning(s), 100.0% typed
'use strict';var KiraVariable=4147;

3. Reason for suppression

I use CoffeeScript, that not support let and const.

  1. the official CoffeeScript documentation — Unsupported ECMAScript features: let and const;
  2. the official CoffeeScript issue tracker — Allow const keyword.

4. Not helped

  1. I couldn’t find any tool, that can automatically correctly replace var to const or let in JavaScript files. eslint --fix with no-var option doesn’t do it.
  2. I tried --jscomp_off option with values from ParserConfig.java and DiagnosticGroups.java files.
  3. I couldn’t find how I can solve my problem in Google, Stack Overflow and closure-compiler GitHub repository.

5. Don’t offer

  1. Please don’t tell me that I shouldn’t be using CoffeeScript.
  2. I don’t need suppress warnings in specific files. I use var in many files; it would be nice suppress this warning for all files one time. For the same reason, please don’t suggest that I add annotations every time I use var.
  3. --jscomp_off lintChecks works for me, but it will disable 40 errors. I need solely suppress [JSC_VAR], not all of these 40 errors of the supression tag.
1

There are 1 best solutions below

0
John On

The compiler doesn't allow for the suppression of individual lint warnings. If you are willing to create a custom build of the compiler, you can:

  • added a suppression group or
  • remove the check

Removing the check is likely easier to merge with future versions.