Fix linting errors part 2#211
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run //src:license-checkStatus: ✅ Passed Click to expand output |
|
The created documentation from the pull request is available at: docu-html |
| return [raw_value] | ||
| if isinstance(raw_value, list) and all(isinstance(v, str) for v in raw_value): | ||
| return raw_value | ||
| return [str(raw_value)] |
There was a problem hiding this comment.
Not sure about that last part here... how about
| return [str(raw_value)] | |
| raise ValueError("unexpected types") |
There was a problem hiding this comment.
Fixed. Please resolve.
|
@MaximilianSoerenPollak as you also have another huge PR: which one should we merge first? |
There was a problem hiding this comment.
Pull Request Overview
This PR addresses linting errors and improves code quality by fixing various style and maintainability issues. The changes focus on eliminating redundant code constructs, improving error handling, and reducing cyclomatic complexity while maintaining functionality.
- Removed redundant f-string prefixes, unnecessary else blocks after return/continue statements
- Replaced generic exception handling with specific exception types and improved error messages
- Refactored complex functions to reduce cyclomatic complexity through helper function extraction
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/test_consumer.py | Removes redundant else blocks, f-string prefixes, file mode arguments, and improves error handling |
| src/find_runfiles/test_find_runfiles.py | Fixes line length violations by breaking long assertion statements |
| src/extensions/score_source_code_linker/tests/test_source_link.py | Improves exception handling with contextlib.suppress and removes f-string prefix |
| src/extensions/score_source_code_linker/tests/test_requirement_links.py | Replaces generic Exception with specific subprocess.CalledProcessError and removes unused variable |
| src/extensions/score_source_code_linker/init.py | Moves default parameter values into function body and simplifies conditional logic |
| src/extensions/score_metamodel/checks/check_options.py | Reduces cyclomatic complexity by extracting helper functions |
| src/extensions/score_metamodel/checks/attributes_format.py | Simplifies complex conditional expressions and removes dictionary keys() call |
| src/extensions/score_metamodel/init.py | Removes unused import |
| src/extensions/score_draw_uml_funcs/init.py | Significantly reduces cyclomatic complexity by extracting multiple helper functions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
I will finish up the Lib PR #207 , I think that should be merged first as to not delay it any further with big merge issues. |
0b2de82 to
9d092cb
Compare
|
|
||
| need_as_dict["source_code_link"] = ", ".join( | ||
| f"{get_github_link(n)}<>{n.file}:{n.line}" for n in needlinks | ||
| f"{get_github_link(None, n)}<>{n.file}:{n.line}" for n in needlinks |
There was a problem hiding this comment.
No, this takes only one argument. No 2nd one.
There was a problem hiding this comment.
Take a look at helper_lib/__init__.py where this function is defined.
There was a problem hiding this comment.
This what was making the build failed we are using the function get_github_link defined in the same file in line 207 it takes 2 arguments as you see
There was a problem hiding this comment.
As said.
The one in helper_lib is the right one/ fixed one. Use that, delete the other definition.
But take over your changes that fix linter warnings to the helper_lib functions
There was a problem hiding this comment.
I used the same function as in the main now, and no more errors related to it are there in the build docs or in tests
|
PR Updates: All problems are solved, and documentation and test builds are running with no issues. PR can be merged. |
| ) -> tuple[ | ||
| str, str, dict[str, str], dict[str, list[str]], dict[str, str], list[str] | ||
| ]: |
There was a problem hiding this comment.
Nit (fix in new PR's):
This return type is absolutley abysmal.
Truly helps noone. Should have a custom type here
| length = 0 | ||
| if "example_feature" not in need["id"]: | ||
| length = len(need["id"]) | ||
| else: | ||
| length = len(need["id"]) - 17 |
There was a problem hiding this comment.
Nit fix in next pr:
| length = 0 | |
| if "example_feature" not in need["id"]: | |
| length = len(need["id"]) | |
| else: | |
| length = len(need["id"]) - 17 | |
| length = len(need["id"]) | |
| if "example_feature" in need["id"]: | |
| length -= 17 |
| try: | ||
| values = _normalize_values(raw_value) | ||
| except ValueError as err: | ||
| raise ValueError( | ||
| f"An Attribute inside need {need['id']} is " | ||
| "not of type str. Only Strings are allowed" | ||
| ) from err |
There was a problem hiding this comment.
Nit (fix in next PR):
Add comment explaining why we did this.
| try: | |
| values = _normalize_values(raw_value) | |
| except ValueError as err: | |
| raise ValueError( | |
| f"An Attribute inside need {need['id']} is " | |
| "not of type str. Only Strings are allowed" | |
| ) from err | |
| # Try except used to add more context to Error without passing variables just for that to function | |
| try: | |
| values = _normalize_values(raw_value) | |
| except ValueError as err: | |
| raise ValueError( | |
| f"An Attribute inside need {need['id']} is " | |
| "not of type str. Only Strings are allowed" | |
| ) from err |
| @@ -156,7 +156,7 @@ def test_invalid_option_type(self): | |||
| target_id="wf_req__001", | |||
There was a problem hiding this comment.
Nit (fix in next PR):
Add a test that now tests the new 'value error' path we have introduced
| # This fixes the "no such file or directory" error in Bazel | ||
| original_cwd = None | ||
| try: | ||
| with contextlib.suppress(FileNotFoundError): |
There was a problem hiding this comment.
Nit (fix in next PR):
Comment what this does briefly as people might not be familliar with this.
There was a problem hiding this comment.
I kind of disagree. We should not explain standard python functionality. Python programmers must know python.
(But we should explain why we ignore the exception)
There was a problem hiding this comment.
That does make more sense, true. Let's do that.
| if git_root is None: | ||
| assert False, "Git root was none" | ||
| raise RuntimeError("Git root was not found") |
There was a problem hiding this comment.
Nit (fix enxt pr):
| if git_root is None: | |
| assert False, "Git root was none" | |
| raise RuntimeError("Git root was not found") | |
| assert git_root is None, "Git root was not found" |
90a126e
into
eclipse-score:main
* Fix and simplify complexity for weak content check * handle edge cases to remove matching between "something" and "thing" * Correct PR #211 remaining comments
* Solve most of the linting errors * Reduce complexities of functions * Remove unused and repeated function from source code linker and fix tests
* Fix and simplify complexity for weak content check * handle edge cases to remove matching between "something" and "thing" * Correct PR eclipse-score#211 remaining comments

This PR resolves a total of 32 remaining linting errors, addressing various code quality and style improvements. The following changes were made:
fprefix from strings where no interpolation occurs (e.g.,f"hello"→"hello").elseblocks following areturnstatement."r"when opening files (e.g.,open("module.bazel", "r")→open("module.bazel")).assert Falsestatements with more descriptive and proper error handling.elseaftercontinuestatements.contextlib.suppress(FileNotFoundError)instead oftry/except/passfor cleaner exception handling.assert Exceptionusage by specifying explicit exception types.Note 1: All builds, documentation generation, and tests run successfully after these changes. Note 2: We got a new list of 66 different errors and warnings after solving the initial first list .
close: #205