Python Patch - Ignore Some Of Google-Closure-JSLinter (GJSLint) Errors

By Running From Command-Line:

gjslint.exe --strict C:\work\trunk\someJSFile.js

I'm getting some important notes like:

:: Line 9, E:0010: Missing semicolon at end of line

some less interesting but still important to keep the GClosure parser happy

:: Line 6, E:0220: No docs found for member '........'
:: Line 44, E:0240: @param descriptions must end with valid punctuation such as a period.

some are just for conventions, but still important to keep our code unified in format:

:: Line 7, E:0131: Single-quoted string preferred over double-quoted string.
:: Line 10, E:0001: Extra space after "......"

but some are completely rubbish like:

:: Line 17, E:0006: Wrong indentation: expected any of {2, 14} but got 4
:: Line 73, E:0110: Line too long (89 characters).
:: Line 142, E:0233: Optional parameter name ..... must be prefixed with opt_.

I especially dislike the long-line notice and the opt_ prefix needed,
since I work in camelCase, I keep underscore to very few and specific cases.

and as long I am using "=" suffix in the annotation to mark the parameter optional

--->   *   @param {number=} myNumber

its ok!

 

Python Patch:

well, Python files are text based-on, but the Windows-Installation of GJSLinter
is compiling an executable file named gjslint.exe

1. download the latest version of the GJSLinter.

2. apply the following patch

Left file: \closure_linter\errorrules_original.py
Right file: \closure_linter\errorrules_patched.py

22 from closure_linter import errors = 22 from closure_linter import errors
23 23
24 24
25 FLAGS = flags.FLAGS 25 FLAGS = flags.FLAGS
26 flags.DEFINE_boolean('jsdoc', True, 26 flags.DEFINE_boolean('jsdoc', True,
27                      'Whether to report errors for missing JsDoc.') 27                      'Whether to report errors for missing JsDoc.')
28 <> 28 flags.DEFINE_list('ignore_errors', [], 'List of error codes to ignore.')
29 = 29
30 def ShouldReportError(error): 30 def ShouldReportError(error):
31   """Whether the given error should be reported. 31   """Whether the given error should be reported.
32 32
33   Returns: 33   Returns:
34     True for all errors except missing documentation errors.  For these, 34     True for all errors except missing documentation errors.  For these,
35     it returns the value of the jsdoc flag. 35     it returns the value of the jsdoc flag.
36   """ 36   """
37   return FLAGS.jsdoc or error not in ( <> 37   return (FLAGS.jsdoc or error not in (
38       errors.MISSING_PARAMETER_DOCUMENTATION, = 38       errors.MISSING_PARAMETER_DOCUMENTATION,
39       errors.MISSING_RETURN_DOCUMENTATION, 39       errors.MISSING_RETURN_DOCUMENTATION,
40       errors.MISSING_MEMBER_DOCUMENTATION, 40       errors.MISSING_MEMBER_DOCUMENTATION,
41       errors.MISSING_PRIVATE, 41       errors.MISSING_PRIVATE,
42       errors.MISSING_JSDOC_TAG_THIS) <> 42       errors.MISSING_JSDOC_TAG_THIS)) and str(error) not in FLAGS.ignore_errors

 

or:

Before

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
#
# Copyright 2010 The Closure Linter Authors. All Rights Reserved.
#
# 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.
 
"""Linter error rules class for Closure Linter."""
 
__author__ = 'rob...@google.com (Robert Walker)'
 
import gflags as flags
from closure_linter import errors
 
FLAGS = flags.FLAGS
flags.DEFINE_boolean('jsdoc', True,
                     'Whether to report errors for missing JsDoc.')
 
def ShouldReportError(error):
  """Whether the given error should be reported.
 
  Returns:
    True for all errors except missing documentation errors.  For these,
    it returns the value of the jsdoc flag.
  """
  return FLAGS.jsdoc or error not in (
      errors.MISSING_PARAMETER_DOCUMENTATION,
      errors.MISSING_RETURN_DOCUMENTATION,
      errors.MISSING_MEMBER_DOCUMENTATION,
      errors.MISSING_PRIVATE,
      errors.MISSING_JSDOC_TAG_THIS)

and
after:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
#
# Copyright 2010 The Closure Linter Authors. All Rights Reserved.
#
# 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.
 
"""Linter error rules class for Closure Linter."""
 
__author__ = 'rob...@google.com (Robert Walker)'
 
import gflags as flags
from closure_linter import errors
 
FLAGS = flags.FLAGS
flags.DEFINE_boolean('jsdoc', True,
                     'Whether to report errors for missing JsDoc.')
flags.DEFINE_list('ignore_errors', [], 'List of error codes to ignore.')
 
def ShouldReportError(error):
  """Whether the given error should be reported.
 
  Returns:
    True for all errors except missing documentation errors.  For these,
    it returns the value of the jsdoc flag.
  """
  return (FLAGS.jsdoc or error not in (
      errors.MISSING_PARAMETER_DOCUMENTATION,
      errors.MISSING_RETURN_DOCUMENTATION,
      errors.MISSING_MEMBER_DOCUMENTATION,
      errors.MISSING_PRIVATE,
      errors.MISSING_JSDOC_TAG_THIS)) and str(error) not in FLAGS.ignore_errors

View Changes Side-By-Side in Google-Code (By Great Ilia Mirkin)

Use it:
without:

gjslint.exe --strict C:\work\trunk\myFile.js

with:

gjslint.exe --strict --ignore_errors 6,110,233 C:\work\trunk\myFile.js

:: disable:
::         6:    Wrong indentation
::         110:  Line too long (the max is 80chars).
::         233:  Optional parameter name ..... must be prefixed with opt_.

Note:
it takes comma-separated list of the integer error numbers
for example "line too long" is marked as "E0110" so you should use integer value of: 110.

also!
put the --ignore_errors switch before the files path,
just as the example, you can combine all switches you would like to, even ones you'll ignore,
it works nicely... :)

This will also works with JetBrains WebStorm IDE,
here is my CONFIG FILE:

1
2
3
4
5
6
7
8
9
10
11
12
--strict
--jslint_error=braces_around_type 
--jslint_error=unused_private_members
--jslint_error=optional_type_marker
--jslint_error=well_formed_author
--jsdoc
--summary
--beep
--check_html
--multiprocess
--debug_indentation
--time

you should add the switch to it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--strict
--ignore_errors=6
--ignore_errors=110
--ignore_errors=233
--jslint_error=braces_around_type 
--jslint_error=unused_private_members
--jslint_error=optional_type_marker
--jslint_error=well_formed_author
--jsdoc
--nosummary
--nobeep
--nocheck_html
--multiprocess
--nodebug_indentation
--notime

 

Download a Ready To Use Patched Version


closure_linter_2_3_9_with_patch.rar

published in April 1, 2013.
it's a 121.77 kB rar file.
with 65 Downloads so far.


closure_linter_2_3_9_with_patch.zip

published in April 2, 2013.
it's a 127.54 kB zip file.
with 35 Downloads so far.


closure_linter-latest_with_patch.tar.gz

published in April 2, 2013.
it's a 85.72 kB gz file.
with 108 Downloads so far.