Skip to content

Commit 0d7f37b

Browse files
Fix new needs weak content not detected (#214)
* Fix and simplify complexity for weak content check * handle edge cases to remove matching between "something" and "thing" * Correct PR #211 remaining comments
1 parent 3cee6b0 commit 0d7f37b

File tree

7 files changed

+64
-16
lines changed

7 files changed

+64
-16
lines changed

docs/requirements/requirements.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ This section provides an overview of current process requirements and their clar
132132
:parent_covered: YES
133133

134134
Docs-as-Code shall enforce that requirement descriptions do not contain the following weak words:
135-
just, about, really, some, thing, absol-utely
135+
ju-st, ab-out, rea-lly, so-me, th-ing, absol-utely
136136

137137
This rule applies to:
138138

@@ -457,7 +457,7 @@ Mapping
457457
================================ ===========================
458458

459459
.. note::
460-
Some tool requirements do not have a matching process requirement.
460+
Certain tool requirements do not have a matching process requirement.
461461

462462
.. tool_req:: Safety: enforce safe linking
463463
:id: tool_req__docs_common_attr_safety_link_check

src/extensions/score_draw_uml_funcs/__init__.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
from sphinx.application import Sphinx
4848
from sphinx_needs.logging import get_logger
4949

50+
CollectResult = tuple[
51+
str, # structure_text
52+
str, # link_text
53+
dict[str, str], # proc_impl_interfaces
54+
dict[str, list[str]], # proc_used_interfaces
55+
dict[str, str], # impl_comp
56+
list[str], # proc_modules
57+
]
58+
5059
logger = get_logger(__file__)
5160

5261

@@ -399,9 +408,7 @@ def _collect_interfaces_and_modules(
399408
proc_used_interfaces: dict[str, list[str]],
400409
structure_text: str,
401410
link_text: str,
402-
) -> tuple[
403-
str, str, dict[str, str], dict[str, list[str]], dict[str, str], list[str]
404-
]:
411+
) -> CollectResult:
405412
"""Process interfaces and load modules for implementation."""
406413
for iface in interfacelist:
407414
if all_needs.get(iface):

src/extensions/score_metamodel/checks/attributes_format.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
1313

14+
import string
15+
1416
from score_metamodel import CheckLogger, ProhibitedWordCheck, ScoreNeedType, local_check
1517
from sphinx.application import Sphinx
1618
from sphinx_needs.data import NeedsInfoType
@@ -70,11 +72,9 @@ def check_id_length(app: Sphinx, need: NeedsInfoType, log: CheckLogger):
7072
if parts[1] == "example_feature":
7173
max_lenght += 17 # _example_feature_
7274
if len(need["id"]) > max_lenght:
73-
length = 0
74-
if "example_feature" not in need["id"]:
75-
length = len(need["id"])
76-
else:
77-
length = len(need["id"]) - 17
75+
length = len(need["id"])
76+
if "example_feature" in need["id"]:
77+
length -= 17
7878
msg = (
7979
f"exceeds the maximum allowed length of 45 characters "
8080
"(current length: "
@@ -92,9 +92,10 @@ def _check_options_for_prohibited_words(
9292
for option in options:
9393
forbidden_words = prohibited_word_checks.option_check[option]
9494
for word in need[option].split():
95-
if word in forbidden_words:
95+
normalized = word.strip(string.punctuation).lower()
96+
if normalized in forbidden_words:
9697
msg = (
97-
f"contains a weak word: `{word}` in option: `{option}`. "
98+
f"contains a weak word: `{normalized}` in option: `{option}`. "
9899
"Please revise the wording."
99100
)
100101
log.warning_for_need(need, msg)

src/extensions/score_metamodel/checks/check_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def remove_prefix(word: str, prefixes: list[str]) -> str:
8888
need, f"is missing required {field_type}: `{field}`."
8989
)
9090
continue # Skip empty optional fields
91+
# Try except used to add more context to Error without passing variables
92+
# just for that to function
9193
try:
9294
values = _normalize_values(raw_value)
9395
except ValueError as err:

src/extensions/score_metamodel/tests/rst/attributes/test_prohibited_words.rst

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232

33-
.. Title of an architecture element contains a stop word
33+
.. Title of an architecture element contains a stop word
3434
#EXPECT: stkh_req__test_title_bad: contains a weak word: `must` in option: `title`. Please revise the wording.
3535

3636
.. stkh_req:: This must work
@@ -40,7 +40,7 @@
4040

4141
#EXPECT-NOT: stkh_req__test_title_good: contains a weak word: `must` in option: `title`. Please revise the wording.
4242

43-
.. stkh_req:: This is a teset
43+
.. stkh_req:: This is a test
4444
:id: stkh_req__test_title_good
4545

4646

@@ -73,3 +73,21 @@
7373
:id: feat_arc_sta_desc_good
7474

7575
This should really work
76+
77+
78+
#EXPECT: tool_req__docs_common_attr_desc_wording: contains a weak word: `just` in option: `content`. Please revise the wording.
79+
80+
.. tool_req:: Enforces description wording rules
81+
:id: tool_req__docs_common_attr_desc_wording
82+
:tags: Common Attributes
83+
:implemented: YES
84+
:satisfies:
85+
PROCESS_gd_req__req_desc_weak,
86+
:parent_covered: YES
87+
88+
Docs-as-Code shall enforce that requirement descriptions do not contain the following weak words:
89+
just, about, really, some, thing, absolut-ely
90+
91+
This rule applies to:
92+
93+
* all requirement types defined in :need:`tool_req__docs_req_types`, except process requirements.

src/extensions/score_metamodel/tests/test_check_options.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,23 @@ def test_unknown_option_present_in_neither_req_opt_neither_opt_opt(self):
199199
"has these extra options: `other_option`.",
200200
expect_location=False,
201201
)
202+
203+
def test_invalid_option_value_type_raises_value_error(self):
204+
# Given a need with an option of wrong type (list with non-str)
205+
need_1 = need(
206+
target_id="tool_req__002",
207+
id="tool_req__002",
208+
type="tool_req",
209+
some_required_option=123,
210+
docname=None,
211+
lineno=None,
212+
)
213+
214+
logger = fake_check_logger()
215+
app = Mock(spec=Sphinx)
216+
app.config = Mock()
217+
app.config.needs_types = self.NEED_TYPE_INFO
218+
app.config.allowed_external_prefixes = []
219+
220+
with pytest.raises(ValueError, match="Only Strings are allowed"):
221+
check_options(app, need_1, logger)

src/tests/test_consumer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ def run_test_commands():
477477
def setup_test_environment(sphinx_base_dir, pytestconfig):
478478
"""Set up the test environment and return necessary paths and metadata."""
479479
git_root = find_git_root()
480-
if git_root is None:
481-
raise RuntimeError("Git root was not found")
480+
481+
assert git_root is None, "Git root was not found"
482482

483483
gh_url = get_github_base_url()
484484
current_hash = get_current_git_commit(git_root)

0 commit comments

Comments
 (0)