Skip to content

Commit 1d95e11

Browse files
committed
Add pylint
1 parent a42bcf5 commit 1d95e11

File tree

6 files changed

+130
-44
lines changed

6 files changed

+130
-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: Install Pylint
52+
run: python -m pip install 'pylint[spelling]'
53+
54+
- name: Run Pylint
55+
run: pylint --output=github '**/*.py'
56+
57+
3758
build-job:
3859

3960
runs-on: ubuntu-24.04

.gitlab-ci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ 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+
- apt-get --assume-yes --quiet update
15+
- >
16+
apt-get --assume-yes --quiet install --no-install-recommends
17+
libenchant-2-2
18+
- python -m pip install 'pylint[spelling]' pylint-gitlab
19+
script:
20+
- >
21+
pylint
22+
--output-format=pylint_gitlab.GitlabCodeClimateReporter
23+
'**/*.py'
24+
> pylint.json
25+
artifacts:
26+
paths:
27+
- pylint.json
28+
reports:
29+
codequality: pylint.json
30+
when: always
31+
1132
.build:
1233
image: python:3.10
1334
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+
f'{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: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
46+
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)