Skip to content

Commit 0536fd8

Browse files
committed
Add pylint-3.1 code back in.
This re-adds the pylintrc and the `run lint` command so that we can still run `pylint` (in addition to being able to run `ruff check`.
1 parent 46cebf6 commit 0536fd8

File tree

4 files changed

+85
-8
lines changed

4 files changed

+85
-8
lines changed

json5/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def dictify(pairs):
122122
if not allow_duplicate_keys:
123123
_orig_dictify = dictify
124124

125-
def dictify(pairs):
125+
def dictify(pairs): # pylint: disable=function-redefined
126126
return _reject_duplicate_keys(pairs, _orig_dictify)
127127

128128
parse_float = parse_float or float

pylintrc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2014 Google Inc. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This file is taken from the suggested pylint configuration in
16+
# Google's Python Style Guide, specifically
17+
# https://github.com/google/styleguide/blob/28d10d1/pylintrc
18+
# The only changes are to comment out the disabling of no-self-use, to
19+
# get rid of the "useless option value" warning from pylint, and to
20+
# turn off the score message.
21+
[MAIN]
22+
23+
persistent=yes
24+
25+
[MESSAGES CONTROL]
26+
27+
disable=
28+
broad-except,
29+
global-statement,
30+
locally-disabled,
31+
missing-docstring,
32+
# no-self-use, # Pylint generates a 'useless option value' warning for this
33+
too-many-arguments,
34+
too-few-public-methods,
35+
too-many-branches,
36+
too-many-instance-attributes,
37+
too-many-locals,
38+
too-many-public-methods,
39+
too-many-return-statements,
40+
unidiomatic-typecheck,
41+
42+
[REPORTS]
43+
44+
reports=no
45+
46+
[SCORE]
47+
48+
score=no # Suppress the "score" message in the output.
49+
50+
[BASIC]
51+
52+
# By default, pylint wants method names to be at most 31 chars long,
53+
# but we want to allow up to 49 to allow for longer test names.
54+
method-rgx=[a-zA-Z_][a-zA-Z0-9_]{0,48}$
55+
56+
# By default, pylint only allows UPPER_CASE constants, but we want to
57+
# allow snake_case as well in some situations.
58+
const-rgx=[a-zA-Z_][a-zA-Z0-9_]{0,30}$
59+
60+
# By default, pylint wants all parameter names to be at least two chars long,
61+
# but we want to allow single-char parameter names as well.
62+
argument-rgx=[a-z_][a-z0-9_]{0,30}$
63+
64+
# By default, pylint wants all variable names to be at least two chars long,
65+
# but we want to allow single-char variable names as well.
66+
variable-rgx=[a-z_][a-z0-9_]{0,30}$

run

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def main(argv):
2424
subp = subps.add_parser('build', help='Build the package.')
2525
subp.set_defaults(func=run_build)
2626

27-
subp = subps.add_parser('check', help='Lint the source code.')
27+
subp = subps.add_parser('check', help='Lint the source code w/ ruff.')
2828
subp.set_defaults(func=run_check)
2929

3030
subp = subps.add_parser('clean', help='Remove any local files.')
@@ -60,6 +60,9 @@ def main(argv):
6060
),
6161
)
6262

63+
subp = subps.add_parser('lint', help='Lint the source code w/ pylint.')
64+
subp.set_defaults(func=run_lint)
65+
6366
subp = subps.add_parser('tests', help='run the tests')
6467
subp.set_defaults(func=run_tests)
6568

@@ -123,6 +126,11 @@ def run_install(args):
123126
call([sys.executable, 'setup.py', 'install'] + argv)
124127

125128

129+
def run_lint(args):
130+
del args
131+
call(sys.executable + ' -m pylint run */*.py', shell=True)
132+
133+
126134
def run_tests(args):
127135
del args
128136
call([sys.executable, '-m', 'unittest', 'discover', '-p', '*_test.py'])

tests/lib_test.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,17 @@ def test_identifiers_unicode(self):
135135
self.check('{\xc3: 1}', {'\xc3': 1})
136136

137137
# Latin small A with Ring above, category Ll (lowercase letter)
138-
self.check('{\u00E5: 1}', {'\u00E5': 1})
138+
self.check('{\u00e5: 1}', {'\u00e5': 1})
139139

140140
# Modifier Letter small H, category Lm (modifier letter)
141-
self.check('{\u02B0: 1}', {'\u02B0': 1})
141+
self.check('{\u02b0: 1}', {'\u02b0': 1})
142142

143143
# Latin Letter Two with Stroke, category Lo (other letter)
144-
self.check('{\u01BB: 1}', {'\u01BB': 1})
144+
self.check('{\u01bb: 1}', {'\u01bb': 1})
145145

146146
# Latin Capital Letter L with Small Letter J
147147
# (category Lt, titlecase letter)
148-
self.check('{\u01C8: 1}', {'\u01C8': 1})
148+
self.check('{\u01c8: 1}', {'\u01c8': 1})
149149

150150
# Roman Numeral One (category Nl, letter number)
151151
self.check('{\u2160: 1}', {'\u2160': 1})
@@ -154,13 +154,13 @@ def test_identifiers_unicode(self):
154154
self.check('{a\u0308o: 1}', {'a\u0308o': 1})
155155

156156
# Rejang Virama (category Mc, spacing mark)
157-
self.check('{a\uA953o: 1}', {'a\uA953o': 1})
157+
self.check('{a\ua953o: 1}', {'a\ua953o': 1})
158158

159159
# Arabic-Indic Digit Zero (category Nd, decimal number)
160160
self.check('{a\u0660: 1}', {'a\u0660': 1})
161161

162162
# Undertie (category Pc, connector punctuation)
163-
self.check('{a\u203Fb: 1}', {'a\u203Fb': 1})
163+
self.check('{a\u203fb: 1}', {'a\u203fb': 1})
164164

165165
def test_null(self):
166166
self.check('null', None)
@@ -412,17 +412,20 @@ def test_custom_numbers(self):
412412
# float.__repr__ in order to get legal JSON values when
413413
# people have custom subclasses with customer __repr__ methods.
414414
# (This is what JSON does and we want to match it).
415+
# pylint: disable=no-self-argument
415416
class MyInt(int):
416417
def __repr__(other): # pragma: no cover
417418
del other
418419
self.fail()
420+
return ''
419421

420422
self.assertEqual(json5.dumps(MyInt(5)), '5')
421423

422424
class MyFloat(float):
423425
def __repr__(other): # pragma: no cover
424426
del other
425427
self.fail()
428+
return ''
426429

427430
self.assertEqual(json5.dumps(MyFloat(0.5)), '0.5')
428431

0 commit comments

Comments
 (0)