1#!/usr/bin/env python
2#
3# Copyright 2007 The Closure Linter Authors. All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS-IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Error codes for JavaScript style checker."""
18
19__author__ = ('robbyw@google.com (Robert Walker)',
20              'ajp@google.com (Andy Perelson)')
21
22
23def ByName(name):
24  """Get the error code for the given error name.
25
26  Args:
27    name: The name of the error
28
29  Returns:
30    The error code
31  """
32  return globals()[name]
33
34
35# "File-fatal" errors - these errors stop further parsing of a single file
36FILE_NOT_FOUND = -1
37FILE_DOES_NOT_PARSE = -2
38
39# Spacing
40EXTRA_SPACE = 1
41MISSING_SPACE = 2
42EXTRA_LINE = 3
43MISSING_LINE = 4
44ILLEGAL_TAB = 5
45WRONG_INDENTATION = 6
46WRONG_BLANK_LINE_COUNT = 7
47
48# Semicolons
49MISSING_SEMICOLON = 10
50MISSING_SEMICOLON_AFTER_FUNCTION = 11
51ILLEGAL_SEMICOLON_AFTER_FUNCTION = 12
52REDUNDANT_SEMICOLON = 13
53
54# Miscellaneous
55ILLEGAL_PROTOTYPE_MEMBER_VALUE = 100
56LINE_TOO_LONG = 110
57LINE_STARTS_WITH_OPERATOR = 120
58COMMA_AT_END_OF_LITERAL = 121
59MULTI_LINE_STRING = 130
60UNNECESSARY_DOUBLE_QUOTED_STRING = 131
61UNUSED_PRIVATE_MEMBER = 132
62
63# Requires, provides
64GOOG_REQUIRES_NOT_ALPHABETIZED = 140
65GOOG_PROVIDES_NOT_ALPHABETIZED = 141
66MISSING_GOOG_REQUIRE = 142
67MISSING_GOOG_PROVIDE = 143
68EXTRA_GOOG_REQUIRE = 144
69EXTRA_GOOG_PROVIDE = 145
70
71# JsDoc
72INVALID_JSDOC_TAG = 200
73INVALID_USE_OF_DESC_TAG = 201
74NO_BUG_NUMBER_AFTER_BUG_TAG = 202
75MISSING_PARAMETER_DOCUMENTATION = 210
76EXTRA_PARAMETER_DOCUMENTATION = 211
77WRONG_PARAMETER_DOCUMENTATION = 212
78MISSING_JSDOC_TAG_TYPE = 213
79MISSING_JSDOC_TAG_DESCRIPTION = 214
80MISSING_JSDOC_PARAM_NAME = 215
81OUT_OF_ORDER_JSDOC_TAG_TYPE = 216
82MISSING_RETURN_DOCUMENTATION = 217
83UNNECESSARY_RETURN_DOCUMENTATION = 218
84MISSING_BRACES_AROUND_TYPE = 219
85MISSING_MEMBER_DOCUMENTATION = 220
86MISSING_PRIVATE = 221
87EXTRA_PRIVATE = 222
88INVALID_OVERRIDE_PRIVATE = 223
89INVALID_INHERIT_DOC_PRIVATE = 224
90MISSING_JSDOC_TAG_THIS = 225
91UNNECESSARY_BRACES_AROUND_INHERIT_DOC = 226
92INVALID_AUTHOR_TAG_DESCRIPTION = 227
93JSDOC_PREFER_QUESTION_TO_PIPE_NULL = 230
94JSDOC_ILLEGAL_QUESTION_WITH_PIPE = 231
95JSDOC_MISSING_OPTIONAL_TYPE = 232
96JSDOC_MISSING_OPTIONAL_PREFIX = 233
97JSDOC_TAG_DESCRIPTION_ENDS_WITH_INVALID_CHARACTER = 240
98# TODO(robbyw): Split this in to more specific syntax problems.
99INCORRECT_SUPPRESS_SYNTAX = 250
100INVALID_SUPPRESS_TYPE = 251
101UNNECESSARY_SUPPRESS = 252
102
103# File ending
104FILE_MISSING_NEWLINE = 300
105FILE_IN_BLOCK = 301
106
107# Interfaces
108INTERFACE_CONSTRUCTOR_CANNOT_HAVE_PARAMS = 400
109INTERFACE_METHOD_CANNOT_HAVE_CODE = 401
110
111# Comments
112MISSING_END_OF_SCOPE_COMMENT = 500
113MALFORMED_END_OF_SCOPE_COMMENT = 501
114
115# ActionScript specific errors:
116# TODO(user): move these errors to their own file and move all JavaScript
117# specific errors to their own file as well.
118# All ActionScript specific errors should have error number at least 1000.
119FUNCTION_MISSING_RETURN_TYPE = 1132
120PARAMETER_MISSING_TYPE = 1133
121VAR_MISSING_TYPE = 1134
122PARAMETER_MISSING_DEFAULT_VALUE = 1135
123IMPORTS_NOT_ALPHABETIZED = 1140
124IMPORT_CONTAINS_WILDCARD = 1141
125UNUSED_IMPORT = 1142
126INVALID_TRACE_SEVERITY_LEVEL = 1250
127MISSING_TRACE_SEVERITY_LEVEL = 1251
128MISSING_TRACE_MESSAGE = 1252
129REMOVE_TRACE_BEFORE_SUBMIT = 1253
130REMOVE_COMMENT_BEFORE_SUBMIT = 1254
131# End of list of ActionScript specific errors.
132
133NEW_ERRORS = frozenset([
134    # Errors added after 2.0.2:
135    WRONG_INDENTATION,
136    MISSING_SEMICOLON,
137    # Errors added after 2.3.4:
138    MISSING_END_OF_SCOPE_COMMENT,
139    MALFORMED_END_OF_SCOPE_COMMENT,
140    UNUSED_PRIVATE_MEMBER,
141    # Errors added after 2.3.5:
142    ])
143