Skip to content

Commit ecf6e0d

Browse files
authored
Merge pull request #2160 from strictdoc-project/stanislaw/lint_d
Code climate: lint/ruff: activate many checks from the D group
2 parents 6dbfcab + f304213 commit ecf6e0d

File tree

12 files changed

+128
-44
lines changed

12 files changed

+128
-44
lines changed

ruff.toml

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ select = [
1414
# Not clear if this check is useful. Too many commas everywhere.
1515
# "COM",
1616

17-
# "D",
17+
"D",
18+
1819
# "DTZ",
1920
# "E",
2021
"EXE",
@@ -54,7 +55,61 @@ ignore = [
5455
# X is too complex
5556
"C901",
5657

57-
"E501", # (line length violations).
58+
# FIXME: Would be great to enable these at some point.
59+
# Missing docstring in public module
60+
"D100",
61+
# Missing docstring in public class
62+
"D101",
63+
# Missing docstring in public method
64+
"D102",
65+
# Missing docstring in public function
66+
"D103",
67+
# Missing docstring in public package
68+
"D104",
69+
# Missing docstring in magic method
70+
"D105",
71+
# Missing docstring in public nested class
72+
"D106",
73+
# Missing docstring in `__init__`
74+
"D107",
75+
76+
# One-line docstring should fit on one line
77+
"D200",
78+
79+
# No blank lines allowed after function docstring (found {num_lines})
80+
"D202",
81+
82+
# 1 blank line required before class docstring
83+
"D203",
84+
85+
# FIXME: 1 blank line required between summary line and description
86+
"D205",
87+
88+
# Multi-line docstring summary should start at the first line
89+
"D212",
90+
91+
# FIXME: This is nice to enable but some test fixtures will need to be fixed.
92+
# First line should end with a period
93+
"D400",
94+
95+
# FIXME: First line of docstring should be in imperative mood: "Some text."
96+
"D401",
97+
98+
# FIXME: Enable at some point: First word of the docstring should not be "This"
99+
"D404",
100+
101+
# No blank lines allowed between a section header and its content
102+
"D412",
103+
104+
# Missing blank line after last section ("Examples")
105+
"D413",
106+
107+
# FIXME: This is nice to enable but some test fixtures will need to be fixed.
108+
# First line should end with a period, question mark, or exclamation point
109+
"D415",
110+
111+
# Line length violations. This is handled by Ruff format.
112+
"E501",
58113

59114
# A warning by ruff format:
60115
# warning: The following rules may cause conflicts when used with the formatter: `ISC001`.
@@ -75,7 +130,7 @@ ignore = [
75130
# Too many statements
76131
"PLR0915",
77132

78-
# TBD: Enable: Use `sys.exit()` instead of `exit`
133+
# FIXME: Enable: Use `sys.exit()` instead of `exit`
79134
"PLR1722",
80135

81136
# Magic value used in comparison

strictdoc/backend/excel/import_/excel_sheet_proxy.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, file: str):
3535

3636
@property
3737
def name(self) -> str:
38-
"""returns the name of the first sheet"""
38+
"""Returns the name of the first sheet"""
3939
if self.lib == ExcelLibType.OPENPYXL:
4040
return str(self.sheet.title)
4141
elif self.lib == ExcelLibType.XLRD:
@@ -44,7 +44,7 @@ def name(self) -> str:
4444

4545
@property
4646
def ncols(self) -> int:
47-
"""the number of columns"""
47+
"""The number of columns"""
4848
ncols: int = 0
4949
if self.lib == ExcelLibType.OPENPYXL:
5050
ncols = self.sheet.max_column
@@ -54,7 +54,7 @@ def ncols(self) -> int:
5454

5555
@property
5656
def nrows(self) -> int:
57-
"""the number of rows"""
57+
"""The number of rows"""
5858
nrows: int = 0
5959
if self.lib == ExcelLibType.OPENPYXL:
6060
nrows = self.sheet.max_row
@@ -63,7 +63,7 @@ def nrows(self) -> int:
6363
return nrows
6464

6565
def get_cell_value(self, row: int, col: int) -> str:
66-
"""returns the value at row/col as string"""
66+
"""Returns the value at row/col as string"""
6767
cell_value: str = ""
6868
if self.lib == ExcelLibType.OPENPYXL:
6969
cell_value = (
@@ -74,7 +74,7 @@ def get_cell_value(self, row: int, col: int) -> str:
7474
return cell_value
7575

7676
def row_values(self, row: int) -> List[str]:
77-
"""returns a full row as list"""
77+
"""Returns a full row as list"""
7878
row_values: List[str] = []
7979
if self.lib == ExcelLibType.OPENPYXL:
8080
row_values = [(cell.value or "") for cell in self.sheet[row + 1]]

strictdoc/helpers/ordered_set.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77

88
class OrderedSet(t.MutableSet[T]):
9-
"""A set that preserves insertion order by internally using a dict.
9+
"""
10+
A set that preserves insertion order by internally using a dict.
1011
1112
>>> OrderedSet([1, 2, "foo"])
1213

tests/end2end/helpers/components/node/document_root.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,29 @@ def assert_is_root_node(self) -> None:
2020
)
2121

2222
def assert_root_node_is_editable(self) -> None:
23-
"""For the root node.
23+
"""
24+
For the root node.
25+
2426
Should have the attribute and the menu button (may be invisible).
2527
"""
28+
2629
# should have the attribute
2730
self.test_case.assert_attribute(
2831
f"{self.node_xpath}",
2932
"data-editable_node",
3033
"on",
3134
by=By.XPATH,
3235
)
36+
3337
# should have the menu button (may be invisible)
3438
self.test_case.assert_element_present(
3539
f"{self.node_xpath}//*[@data-testid='document-edit-config-action']",
3640
by=By.XPATH,
3741
)
3842

39-
# Assert fields content: named methods
40-
43+
#
44+
# Assert fields content: named methods.
45+
#
4146
def assert_document_title_contains(self, text: str) -> None:
4247
assert isinstance(text, str)
4348
self.test_case.assert_element(

tests/end2end/helpers/components/node/node.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def create_from_node_number(test_case: BaseCase, node_order: int = 2):
3030
return Node(test_case=test_case, node_xpath=xpath)
3131

3232
def assert_node_is_editable(self) -> None:
33-
"""It makes sense for section & requirements nodes.
33+
"""
34+
It makes sense for section & requirements nodes.
3435
Should have the attribute and the menu button (may be invisible).
3536
3637
The root node has its own method from DocumentRoot(Node):
@@ -50,7 +51,8 @@ def assert_node_is_editable(self) -> None:
5051
)
5152

5253
def assert_node_is_not_editable(self) -> None:
53-
"""It makes sense for section & requirements nodes (due to 'testid').
54+
"""
55+
It makes sense for section & requirements nodes (due to 'testid').
5456
Should not have the menu button (might be invisible).
5557
"""
5658
self.test_case.assert_element_not_present(
@@ -59,7 +61,8 @@ def assert_node_is_not_editable(self) -> None:
5961
)
6062

6163
def assert_node_is_deletable(self) -> None:
62-
"""It makes sense for section & requirements nodes.
64+
"""
65+
It makes sense for section & requirements nodes.
6366
Should have the menu delete button (may be invisible).
6467
"""
6568
self.test_case.assert_element_present(
@@ -68,7 +71,8 @@ def assert_node_is_deletable(self) -> None:
6871
)
6972

7073
def assert_node_is_not_deletable(self) -> None:
71-
"""It makes sense for all nodes.
74+
"""
75+
It makes sense for all nodes.
7276
Should not have the menu delete button (may be invisible).
7377
"""
7478
self.test_case.assert_element_not_present(
@@ -77,7 +81,8 @@ def assert_node_is_not_deletable(self) -> None:
7781
)
7882

7983
def assert_node_has_menu(self) -> None:
80-
"""It makes sense for all nodes.
84+
"""
85+
It makes sense for all nodes.
8186
Should have the menu add button (may be invisible).
8287
"""
8388
self.test_case.assert_element_present(
@@ -86,7 +91,8 @@ def assert_node_has_menu(self) -> None:
8691
)
8792

8893
def assert_node_has_not_menu(self) -> None:
89-
"""It makes sense for all nodes.
94+
"""
95+
It makes sense for all nodes.
9096
Should not have the menu add button (may be invisible).
9197
"""
9298
self.test_case.assert_element_not_present(
@@ -103,7 +109,8 @@ def assert_node_does_not_contain(self, text: str) -> None:
103109
# Node delete
104110

105111
def _get_node_delete_confirm(self) -> Confirm:
106-
"""Need to be confirmed. For full confirmed action, use do_delete_node.
112+
"""
113+
Need to be confirmed. For full confirmed action, use do_delete_node.
107114
108115
Returns:
109116
Confirm.
@@ -167,14 +174,17 @@ def do_open_form_edit_included_document(self) -> Form_EditIncludedDocument:
167174
self._do_node_edit()
168175
return Form_EditIncludedDocument(self.test_case)
169176

170-
# title string pattern
171-
177+
#
178+
# Title string pattern.
179+
#
172180
def create_node_title_string(
173181
self,
174182
node_title: str,
175183
node_level: str = "",
176184
) -> str:
177-
"""title pattern: "1.2.3.&nbsp:Title".
185+
"""
186+
Title pattern: "1.2.3.&nbsp:Title".
187+
178188
To check in numbered nodes: sections and requirements.
179189
180190
Args:

tests/end2end/helpers/components/node/requirement.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@ def assert_is_requirement(self) -> None:
4848
by=By.XPATH,
4949
)
5050

51-
# requirement style
52-
51+
#
52+
# Requirement style.
53+
#
5354
def assert_requirement_style_simple(self) -> None:
54-
"""Make sure that the normal (not table-based) requirement
55-
is rendered."""
55+
"""
56+
Make sure that the normal (not table-based) requirement
57+
is rendered.
58+
"""
5659
self.test_case.assert_element(
5760
f"{self.node_xpath}"
5861
'//sdoc-requirement[@data-testid="requirement-style-simple"]',

tests/end2end/helpers/screens/screen.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,16 @@ def get_requirement(self, node_order: int = 1) -> Requirement:
8888
return self.get_node(node_order)
8989

9090
def get_node(self, node_order: int = 1) -> Requirement:
91-
"""Based on "//sdoc-node[@data-testid='node-requirement']" """
91+
"""
92+
Based on "//sdoc-node[@data-testid='node-requirement']"
93+
"""
9294
requirement = Requirement.with_node(self.test_case, node_order)
9395
requirement.assert_is_requirement()
9496
return requirement
9597

9698
def get_requirement_modal(self, node_order: int = -1) -> Requirement:
97-
"""Based on "//sdoc-requirement". Searches for an <sdoc-requirement>
99+
"""
100+
Based on "//sdoc-requirement". Searches for an <sdoc-requirement>
98101
without taking the node <sdoc-node> into account.
99102
100103
Args:
@@ -110,7 +113,9 @@ def get_requirement_modal(self, node_order: int = -1) -> Requirement:
110113
requirement.assert_is_requirement()
111114
return requirement
112115

116+
#
113117
# TOC
118+
#
114119
def get_toc(self) -> TOC:
115120
TOC(self.test_case).assert_is_toc()
116121
return TOC(self.test_case)
@@ -121,7 +126,9 @@ def assert_toc_contains(self, string: str) -> None:
121126
def assert_toc_contains_not(self, string: str) -> None:
122127
TOC(self.test_case).assert_toc_contains_not(string)
123128

129+
#
124130
# CollapsibleList
131+
#
125132
def get_collapsible_list(self) -> CollapsibleList:
126133
CollapsibleList(self.test_case).assert_is_collapsible()
127134
return CollapsibleList(self.test_case)

tests/integration/features/file_traceability/_language_parsers/python/05_python_class/file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ class Foo:
22
"""
33
@relation(REQ-1, scope=class)
44
"""
5+
56
def hello_world(self):
67
print("hello world") # noqa: T201
78
print("hello world") # noqa: T201

tests/integration/features/file_traceability/_language_parsers/python/05_python_class/test.itest

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ CHECK: Published: Hello world doc
66
RUN: %check_exists --file "%S/Output/html/_source_files/file.py.html"
77

88
RUN: %cat %S/Output/html/%THIS_TEST_FOLDER/input.html | filecheck %s --check-prefix CHECK-HTML
9-
CHECK-HTML: <a{{.*}}href="../_source_files/file.py.html#REQ-1#1#8">
10-
CHECK-HTML: <a{{.*}}href="../_source_files/file.py.html#REQ-2#1#8">
9+
CHECK-HTML: <a{{.*}}href="../_source_files/file.py.html#REQ-1#1#9">
10+
CHECK-HTML: <a{{.*}}href="../_source_files/file.py.html#REQ-2#1#9">
1111

1212
RUN: %cat %S/Output/html/_source_files/file.py.html | filecheck %s --check-prefix CHECK-SOURCE-FILE
13-
CHECK-SOURCE-FILE: href="../_source_files/file.py.html#REQ-1#1#8"
14-
CHECK-SOURCE-FILE: <b>[ 1-8 ]</b>
13+
CHECK-SOURCE-FILE: href="../_source_files/file.py.html#REQ-1#1#9"
14+
CHECK-SOURCE-FILE: <b>[ 1-9 ]</b>
1515
CHECK-SOURCE-FILE: file.py, class Foo
1616

17-
CHECK-SOURCE-FILE: href="../_source_files/file.py.html#REQ-2#1#8"
18-
CHECK-SOURCE-FILE: <b>[ 1-8 ]</b>
17+
CHECK-SOURCE-FILE: href="../_source_files/file.py.html#REQ-2#1#9"
18+
CHECK-SOURCE-FILE: <b>[ 1-9 ]</b>
1919
CHECK-SOURCE-FILE: file.py, class Foo
2020

2121
RUN: %cat %S/Output/html/source_coverage.html | filecheck %s --check-prefix CHECK-SOURCE-COVERAGE

tests/integration/features/file_traceability/file_roles/01_relations_with_role/file.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
class Foo:
22
"""@relation(REQ-001, scope=class, role=Implementation)"""
3+
34
pass
45

56

67
def foo():
78
"""@relation(REQ-001, scope=function, role=Implementation)"""
9+
810
pass
911

1012

0 commit comments

Comments
 (0)