3 # Copyright 2010 The Closure Linter Authors. All Rights Reserved.
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 """Linter error rules class for Closure Linter."""
19 __author__ = 'robbyw@google.com (Robert Walker)'
21 import gflags as flags
22 from closure_linter import errors
26 flags.DEFINE_boolean('jsdoc', True,
27 'Whether to report errors for missing JsDoc.')
28 flags.DEFINE_list('disable', None,
29 'Disable specific error. Usage Ex.: gjslint --disable 1,'
31 flags.DEFINE_integer('max_line_length', 80, 'Maximum line length allowed '
32 'without warning.', lower_bound=1)
34 disabled_error_nums = None
37 def GetMaxLineLength():
38 """Returns allowed maximum length of line.
41 Length of line allowed without any warning.
43 return FLAGS.max_line_length
46 def ShouldReportError(error):
47 """Whether the given error should be reported.
50 True for all errors except missing documentation errors and disabled
51 errors. For missing documentation, it returns the value of the
54 global disabled_error_nums
55 if disabled_error_nums is None:
56 disabled_error_nums = []
58 for error_str in FLAGS.disable:
61 error_num = int(error_str)
64 disabled_error_nums.append(error_num)
66 return ((FLAGS.jsdoc or error not in (
67 errors.MISSING_PARAMETER_DOCUMENTATION,
68 errors.MISSING_RETURN_DOCUMENTATION,
69 errors.MISSING_MEMBER_DOCUMENTATION,
70 errors.MISSING_PRIVATE,
71 errors.MISSING_JSDOC_TAG_THIS)) and
72 (not FLAGS.disable or error not in disabled_error_nums))