Skip to content

Commit ba1778f

Browse files
committed
Add pylint
1 parent a42bcf5 commit ba1778f

File tree

6 files changed

+123
-44
lines changed

6 files changed

+123
-44
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[spelling]'
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: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
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-
#
108
# General
11-
#
9+
# =======
1210

1311
extensions = [
1412
'sphinx.ext.graphviz',
1513
]
1614

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

1917
suppress_warnings = [
2018
'download.not_readable',
@@ -24,23 +22,20 @@
2422
'src/_templates',
2523
]
2624

27-
#
2825
# Project
29-
#
26+
# =======
3027

31-
project = TITLE
28+
project = TITLE # pylint: disable=invalid-name
3229

33-
#
3430
# HTML
35-
#
31+
# ====
3632

37-
html_show_copyright = False
38-
html_show_sphinx = False
33+
html_show_copyright = False # pylint: disable=invalid-name
34+
html_show_sphinx = False # pylint: disable=invalid-name
3935

4036
html_sidebars = {
41-
# 'about.html' provided by 'alabaster' theme
4237
'**': [
43-
'about.html',
38+
'about.html', # Provided by 'alabaster' theme
4439
'globaltoc.html',
4540
'searchbox.html',
4641
],
@@ -50,19 +45,18 @@
5045
'description': SUBTITLE,
5146
}
5247

53-
html_title = TITLE
48+
html_title = TITLE # pylint: disable=invalid-name
5449

55-
html_use_modindex = False
56-
html_use_index = False
50+
html_use_modindex = False # pylint: disable=invalid-name
51+
html_use_index = False # pylint: disable=invalid-name
5752

58-
#
5953
# Latex
60-
#
54+
# =====
6155

6256
latex_documents = [
6357
(
6458
MASTER_DOCUMENT,
65-
'{}.tex'.format(TITLE.lower().replace(' ', '')),
59+
f'{TITLE.lower().replace(" ", "")}.tex',
6660
TITLE,
6761
AUTHOR,
6862
'manual',
@@ -73,9 +67,7 @@
7367
'papersize': 'a4paper',
7468
}
7569

76-
latex_show_pagerefs = True
77-
latex_show_urls = 'footnote'
70+
latex_show_pagerefs = True # pylint: disable=invalid-name
71+
latex_show_urls = 'footnote' # pylint: disable=invalid-name
7872

79-
latex_toplevel_sectioning = 'part'
80-
81-
# EOF
73+
latex_toplevel_sectioning = 'part' # pylint: disable=invalid-name

pylintrc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[MASTER]
2+
3+
jobs = 0
4+
5+
load-plugins =
6+
pylint.extensions.bad_builtin,
7+
pylint.extensions.broad_try_clause,
8+
pylint.extensions.check_elif,
9+
pylint.extensions.code_style,
10+
pylint.extensions.comparison_placement,
11+
pylint.extensions.confusing_elif,
12+
pylint.extensions.consider_refactoring_into_while_condition,
13+
pylint.extensions.consider_ternary_expression,
14+
pylint.extensions.dict_init_mutate,
15+
pylint.extensions.docparams,
16+
pylint.extensions.docstyle,
17+
pylint.extensions.dunder,
18+
pylint.extensions.empty_comment,
19+
pylint.extensions.eq_without_hash,
20+
pylint.extensions.for_any_all,
21+
pylint.extensions.magic_value,
22+
pylint.extensions.mccabe,
23+
pylint.extensions.no_self_use,
24+
pylint.extensions.overlapping_exceptions,
25+
pylint.extensions.private_import,
26+
pylint.extensions.redefined_variable_type,
27+
pylint.extensions.redefined_loop_name,
28+
pylint.extensions.set_membership,
29+
pylint.extensions.typing,
30+
pylint.extensions.while_used,
31+
32+
33+
[MESSAGES CONTROL]
34+
35+
disable =
36+
37+
enable =
38+
use-symbolic-message-instead,
39+
useless-suppression,
40+
41+
42+
[SPELLING]
43+
44+
spelling-dict = en_US
45+
spelling-private-dict-file = spelling-dict.txt

spelling-dict.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
initializer

src/python/fizz_buzz.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
#!/usr/bin/env python3
22

3+
"""Fizz buzz."""
34

4-
class Injector:
5+
import sys
56

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

10-
def __call__(self, value):
16+
def __call__(self, value: int):
17+
"""Callable."""
1118
result = None
1219
if value % self._multiple == 0:
1320
result = self._output
1421
return result
1522

1623

17-
def fizz_buzz(start, end):
24+
def fizz_buzz(start: int, end: int) -> None:
25+
"""Fizz buzz."""
1826
injectors = [
1927
Injector(3, 'Fizz'),
2028
Injector(5, 'Buzz'),
2129
]
22-
#
30+
2331
for i in range(start, end + 1):
2432
items = []
2533
output = None
26-
#
34+
2735
for injector in injectors:
28-
item = injector(i)
29-
if item:
36+
if (item := injector(i)):
3037
items.append(item)
31-
#
32-
if items:
33-
output = ' '.join(items)
34-
else:
35-
output = str(i)
36-
#
38+
39+
output = ' '.join(items) if items else str(i)
40+
3741
print(output)
3842

3943

40-
def main():
44+
def _main() -> int:
4145
fizz_buzz(1, 50)
46+
return 0
4247

4348

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

0 commit comments

Comments
 (0)