Skip to content

Commit fa16143

Browse files
committed
Add pylint
1 parent a42bcf5 commit fa16143

File tree

5 files changed

+132
-45
lines changed

5 files changed

+132
-45
lines changed

.github/workflows/main.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,27 @@ jobs:
3434
- name: Check with pre-commit
3535
run: pre-commit run --all-files --show-diff-on-failure
3636

37+
pylint:
38+
39+
runs-on: ubuntu-24.04
40+
41+
steps:
42+
43+
- name: Setup Python
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: '3.10'
47+
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
51+
- name: Pylint
52+
run: >
53+
python -m pip install pylint
54+
55+
pylint '**/*.py'
56+
57+
3758
build-job:
3859

3960
runs-on: ubuntu-24.04

.gitlab-ci.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ pre-commit:
88
script:
99
- pre-commit run --all-files --show-diff-on-failure
1010

11+
pylint:
12+
image: python:3.10
13+
before_script:
14+
- python -m pip install pylint-gitlab
15+
script:
16+
- >
17+
pylint
18+
--output-format=pylint_gitlab.GitlabCodeClimateReporter
19+
'**/*.py'
20+
> pylint.json
21+
artifacts:
22+
paths:
23+
- pylint.json
24+
reports:
25+
codequality: pylint.json
26+
when: always
27+
1128
.build:
1229
image: python:3.10
1330
before_script:

conf.py

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
""" Sphinx documentation generator configuration
2-
"""
1+
"""Sphinx documentation generator configuration."""
32

43
AUTHOR = 'sinoroc'
54
MASTER_DOCUMENT = 'contents'
65
SUBTITLE = 'Bits of knowledge'
76
TITLE = 'Sinoroc KB'
87

9-
#
8+
foo = "bar"
9+
1010
# General
11-
#
11+
# =======
1212

1313
extensions = [
1414
'sphinx.ext.graphviz',
1515
]
1616

17-
master_doc = MASTER_DOCUMENT
17+
master_doc = MASTER_DOCUMENT # pylint: disable=invalid-name
1818

1919
suppress_warnings = [
2020
'download.not_readable',
@@ -24,23 +24,20 @@
2424
'src/_templates',
2525
]
2626

27-
#
2827
# Project
29-
#
28+
# =======
3029

31-
project = TITLE
30+
project = TITLE # pylint: disable=invalid-name
3231

33-
#
3432
# HTML
35-
#
33+
# ====
3634

37-
html_show_copyright = False
38-
html_show_sphinx = False
35+
html_show_copyright = False # pylint: disable=invalid-name
36+
html_show_sphinx = False # pylint: disable=invalid-name
3937

4038
html_sidebars = {
41-
# 'about.html' provided by 'alabaster' theme
4239
'**': [
43-
'about.html',
40+
'about.html', # Provided by 'alabaster' theme
4441
'globaltoc.html',
4542
'searchbox.html',
4643
],
@@ -50,19 +47,18 @@
5047
'description': SUBTITLE,
5148
}
5249

53-
html_title = TITLE
50+
html_title = TITLE # pylint: disable=invalid-name
5451

55-
html_use_modindex = False
56-
html_use_index = False
52+
html_use_modindex = False # pylint: disable=invalid-name
53+
html_use_index = False # pylint: disable=invalid-name
5754

58-
#
5955
# Latex
60-
#
56+
# =====
6157

6258
latex_documents = [
6359
(
6460
MASTER_DOCUMENT,
65-
'{}.tex'.format(TITLE.lower().replace(' ', '')),
61+
'{TITLE.lower().replace(" ", "")}.tex',
6662
TITLE,
6763
AUTHOR,
6864
'manual',
@@ -73,9 +69,7 @@
7369
'papersize': 'a4paper',
7470
}
7571

76-
latex_show_pagerefs = True
77-
latex_show_urls = 'footnote'
78-
79-
latex_toplevel_sectioning = 'part'
72+
latex_show_pagerefs = True # pylint: disable=invalid-name
73+
latex_show_urls = 'footnote' # pylint: disable=invalid-name
8074

81-
# EOF
75+
latex_toplevel_sectioning = 'part' # pylint: disable=invalid-name

pylintrc

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#
2+
3+
# TODO emptystring and comparetozero have been removed in pylint 3.0
4+
# TODO https://pylint.pycqa.org/en/latest/whatsnew/3/3.0/index.html#changes-requiring-user-actions
5+
6+
[MASTER]
7+
8+
jobs = 0
9+
10+
load-plugins =
11+
pylint.extensions.bad_builtin,
12+
pylint.extensions.broad_try_clause,
13+
pylint.extensions.check_elif,
14+
pylint.extensions.code_style,
15+
pylint.extensions.comparison_placement,
16+
pylint.extensions.confusing_elif,
17+
pylint.extensions.consider_refactoring_into_while_condition,
18+
pylint.extensions.consider_ternary_expression,
19+
pylint.extensions.dict_init_mutate,
20+
pylint.extensions.docparams,
21+
pylint.extensions.docstyle,
22+
pylint.extensions.dunder,
23+
pylint.extensions.empty_comment,
24+
pylint.extensions.eq_without_hash,
25+
pylint.extensions.for_any_all,
26+
pylint.extensions.magic_value,
27+
pylint.extensions.mccabe,
28+
pylint.extensions.no_self_use,
29+
pylint.extensions.overlapping_exceptions,
30+
pylint.extensions.private_import,
31+
pylint.extensions.redefined_variable_type,
32+
pylint.extensions.redefined_loop_name,
33+
pylint.extensions.set_membership,
34+
pylint.extensions.typing,
35+
pylint.extensions.while_used,
36+
37+
38+
[MESSAGES CONTROL]
39+
40+
disable =
41+
42+
enable =
43+
use-symbolic-message-instead,
44+
useless-suppression,
45+
46+
47+
[SPELLING]
48+
49+
spelling-dict = en
50+
spelling-private-dict-file = spelling-dict.txt
51+
52+
53+
# EOF

src/python/fizz_buzz.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
#!/usr/bin/env python3
1+
"""Fizz buzz."""
22

33

4-
class Injector:
4+
import sys
55

6-
def __init__(self, multiple, word):
6+
7+
class Injector: # pylint: disable=too-few-public-methods
8+
"""Callable to inject a word if value is a multiple."""
9+
10+
def __init__(self, multiple: int, word: str) -> None:
11+
"""Initializer."""
712
self._multiple = multiple
8-
self._output = '{}!'.format(word)
13+
self._output = f'{word}!'
914

10-
def __call__(self, value):
15+
def __call__(self, value: int):
16+
"""Callable."""
1117
result = None
1218
if value % self._multiple == 0:
1319
result = self._output
1420
return result
1521

1622

17-
def fizz_buzz(start, end):
23+
def fizz_buzz(start: int, end: int) -> None:
24+
"""Fizz buzz."""
1825
injectors = [
1926
Injector(3, 'Fizz'),
2027
Injector(5, 'Buzz'),
2128
]
22-
#
29+
2330
for i in range(start, end + 1):
2431
items = []
2532
output = None
26-
#
33+
2734
for injector in injectors:
28-
item = injector(i)
29-
if item:
35+
if (item := injector(i)):
3036
items.append(item)
31-
#
32-
if items:
33-
output = ' '.join(items)
34-
else:
35-
output = str(i)
36-
#
37+
38+
output = ' '.join(items) if items else str(i)
39+
3740
print(output)
3841

3942

40-
def main():
43+
def _main() -> int:
4144
fizz_buzz(1, 50)
45+
return 0
4246

4347

4448
if __name__ == '__main__':
45-
main()
46-
47-
# EOF
49+
sys.exit(_main())

0 commit comments

Comments
 (0)