in java/com/google/javascript/jscomp/JsCompilerWarnings.java [58:121]
public CheckLevel level(JSError error) {
// Closure Rules will always ignore these checks no matter what.
if (Diagnostics.IGNORE_ALWAYS.contains(error.getType())) {
return CheckLevel.OFF;
}
// Some checks, e.g. linting, are handled *exclusively* by JsChecker.
if (Diagnostics.JSCHECKER_ONLY_SUPPRESS_CODES.contains(error.getType().key)) {
return CheckLevel.OFF;
}
// Synthetic code is generated by compiler passes.
if (isInSyntheticCode(error)) {
// These are the checks we know synthetic code currently isn't very good at following.
if (Diagnostics.IGNORE_FOR_SYNTHETIC.contains(error.getType())) {
return CheckLevel.OFF;
}
// If there are any others, we'll display a warning, because it's impossible for the user to
// address these errors. We're not ignoring them entirely because we want to encourage users
// to file bugs so the compiler pass can be fixed.
return CheckLevel.WARNING;
}
// Some errors are independent of code, e.g. flag misuse.
if (error.getSourceName() == null) {
return CheckLevel.ERROR;
}
// We provide an escape hatch for situations in which it's not possible (or too burdensome) to
// add a suppress code to the closure_js_library() rule responsible for the error.
if (globalSuppressions.contains(error.getType())) {
return CheckLevel.OFF;
}
for (String module : convertPathToModuleName(error.getSourceName(), roots).asSet()) {
if (legacyModules.contains(module)) {
// Ignore it entirely if it's very noisy.
if (Diagnostics.IGNORE_FOR_LEGACY.contains(error.getType())) {
return CheckLevel.OFF;
}
// Otherwise downgrade to a warning, since it's not easily actionable.
return CheckLevel.WARNING;
} else if (suppressions.containsEntry(module, error.getType())) {
// If a closure_js_library() defined this source file, then check if that library rule
// defined a suppress code to make this error go away.
return CheckLevel.OFF;
}
}
switch (error.getDefaultLevel()) {
case OFF:
/**
* Treat any user invisible diagnostics as safe by default.
*
* <p>This lets new diagnostics be added to JSCompiler without immediately being errors,
* whcih is useful for staged rollouts.
*/
return CheckLevel.OFF;
default:
// Treat any user visible diagnostic as an error by default.
return CheckLevel.ERROR;
}
}