com.google.javascript.jscomp.MapDiagnosticToSuppression Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of closure-compiler-unshaded Show documentation
Show all versions of closure-compiler-unshaded Show documentation
Closure Compiler is a JavaScript optimizing compiler. It parses your
JavaScript, analyzes it, removes dead code and rewrites and minimizes
what's left. It also checks syntax, variable references, and types, and
warns about common JavaScript pitfalls. It is used in many of Google's
JavaScript apps, including Gmail, Google Web Search, Google Maps, and
Google Docs.
/*
* Copyright 2019 The Closure Compiler Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.javascript.jscomp;
import com.google.common.annotations.GwtIncompatible;
import com.google.javascript.jscomp.DiagnosticToSuppressionMapper.OutputFormat;
import com.google.javascript.jscomp.parsing.ParserRunner;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
/**
* Prints out a map from diagnostic id to suppression.
*
* This can be used by tooling to automatically suppress errors given a list of diagnostics or to
* generate documentation.
*
*
A few potentially confusing aspects of this class:
*
*
* - Some diagnostic ids are not suppressible, and so are not included in the map.
*
- Some diagnostics have multiple possible suppressions. We arbitrarily choose one
* suppression, with two exceptions: use visibility over accessControls, and use anything over
* missingSourcesWarnings. TODO(lharker): we could also make this configurable from the
* command line.
*
- Some suppression groups are not usable in at-suppress annotations, as configured in the
* Parser, and are not included in the map.
*
*/
@GwtIncompatible
public final class MapDiagnosticToSuppression {
@Option(
name = "--output",
usage = "Sets the desired output format.\n" + "Options: md, json" + "Default: json")
private OutputFormat output = OutputFormat.JSON;
@Option(name = "--help", usage = "Usage")
private boolean help = false;
private MapDiagnosticToSuppression() {}
public static void main(String[] args) {
new MapDiagnosticToSuppression().printSuppressions(args);
}
private static void printHelp() {
System.out.println("Usage: MapDiagnosticToSuppression --output={json,md}");
}
private void printSuppressions(String[] args) {
CmdLineParser parser = new CmdLineParser(this);
try {
parser.parseArgument(args);
} catch (CmdLineException ex) {
System.err.println("Could not parse arguments: " + ex);
printHelp();
return;
}
if (help) {
printHelp();
return;
}
new DiagnosticToSuppressionMapper(
ParserRunner.getSuppressionNames(), DiagnosticGroups.getRegisteredGroups())
.printSuppressions(output);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy