Debian Codegraph @

src/com/google/javascript/jscomp/WarningLevel.java

raw symbols SCIP
1 /*
2 * Copyright 2009 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp;
18
19 import com.google.javascript.jscomp.CheckLevel;
20 import com.google.javascript.jscomp.CompilerOptions;
21
22 /**
23 * Convert the warnings level to an Options object.
24 *
25 */
26 public enum WarningLevel {
27 QUIET,
28
29 DEFAULT,
30
31 VERBOSE;
32
33 public void setOptionsForWarningLevel(CompilerOptions options) {
34 switch (this) {
35 case QUIET:
36 silenceAllWarnings(options);
37 break;
38 case DEFAULT:
39 addDefaultWarnings(options);
40 break;
41 case VERBOSE:
42 addVerboseWarnings(options);
43 break;
44 default:
45 throw new RuntimeException("Unknown warning level.");
46 }
47 }
48
49 /**
50 * Silence all non-essential warnings.
51 */
52 private static void silenceAllWarnings(CompilerOptions options) {
53 // Just use a ShowByPath warnings guard, so that we don't have
54 // to maintain a separate class of warnings guards for silencing warnings.
55 options.addWarningsGuard(
56 new ShowByPathWarningsGuard(
57 "the_longest_path_that_cannot_be_expressed_as_a_string"));
58
59 // Allow passes that aren't going to report anything to be skipped.
60
61 options.checkRequires = CheckLevel.OFF;
62 options.checkProvides = CheckLevel.OFF;
63 options.checkMissingGetCssNameLevel = CheckLevel.OFF;
64 options.aggressiveVarCheck = CheckLevel.OFF;
65 options.checkTypes = false;
66 options.setWarningLevel(DiagnosticGroups.CHECK_TYPES, CheckLevel.OFF);
67 options.checkUnreachableCode = CheckLevel.OFF;
68 options.checkMissingReturn = CheckLevel.OFF;
69 options.setWarningLevel(DiagnosticGroups.ACCESS_CONTROLS, CheckLevel.OFF);
70 options.setWarningLevel(DiagnosticGroups.CONST, CheckLevel.OFF);
71 options.setWarningLevel(DiagnosticGroups.CONSTANT_PROPERTY, CheckLevel.OFF);
72 options.checkGlobalNamesLevel = CheckLevel.OFF;
73 options.checkSuspiciousCode = false;
74 options.checkGlobalThisLevel = CheckLevel.OFF;
75 options.setWarningLevel(DiagnosticGroups.GLOBAL_THIS, CheckLevel.OFF);
76 options.setWarningLevel(DiagnosticGroups.ES5_STRICT, CheckLevel.OFF);
77 options.checkCaja = false;
78
79 // Allows annotations that are not standard.
80 options.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC,
81 CheckLevel.OFF);
82 }
83
84 /**
85 * Add the default checking pass to the compilation options.
86 * @param options The CompilerOptions object to set the options on.
87 */
88 private static void addDefaultWarnings(CompilerOptions options) {
89 options.checkSuspiciousCode = true;
90 options.checkUnreachableCode = CheckLevel.WARNING;
91 options.checkControlStructures = true;
92
93 // Allows annotations that are not standard.
94 options.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC,
95 CheckLevel.OFF);
96 }
97
98 /**
99 * Add all the check pass that are possibly relevant to a non-googler.
100 * @param options The CompilerOptions object to set the options on.
101 */
102 private static void addVerboseWarnings(CompilerOptions options) {
103 addDefaultWarnings(options);
104
105 // checkSuspiciousCode needs to be enabled for CheckGlobalThis to get run.
106 options.checkSuspiciousCode = true;
107 options.checkGlobalThisLevel = CheckLevel.WARNING;
108 options.checkSymbols = true;
109 options.checkMissingReturn = CheckLevel.WARNING;
110
111 // checkTypes has the side-effect of asserting that the
112 // correct number of arguments are passed to a function.
113 // Because the CodingConvention used with the web service does not provide a
114 // way for optional arguments to be specified, these warnings may result in
115 // false positives.
116 options.checkTypes = true;
117 options.checkGlobalNamesLevel = CheckLevel.WARNING;
118 options.aggressiveVarCheck = CheckLevel.WARNING;
119 options.setWarningLevel(
120 DiagnosticGroups.MISSING_PROPERTIES, CheckLevel.WARNING);
121 options.setWarningLevel(
122 DiagnosticGroups.DEPRECATED, CheckLevel.WARNING);
123 options.setWarningLevel(
124 DiagnosticGroups.ES5_STRICT, CheckLevel.WARNING);
125 options.setWarningLevel(
126 DiagnosticGroups.VISIBILITY, CheckLevel.WARNING);
127 options.setWarningLevel(
128 DiagnosticGroups.CONST, CheckLevel.WARNING);
129 options.setWarningLevel(
130 DiagnosticGroups.CHECK_REGEXP, CheckLevel.WARNING);
131
132 // Kindly tell the user that they have JsDocs that we don't understand.
133 options.setWarningLevel(DiagnosticGroups.NON_STANDARD_JSDOC,
134 CheckLevel.WARNING);
135 }
136 }