8000 Fix/sonarcloud quality gate issues by sathyapramod · Pull Request #4657 · ansible/molecule · GitHub
[go: up one dir, main page]

Skip to content

Fix/sonarcloud quality gate issues - #4657

Merged
sathyapramod merged 6 commits into
mainfrom
fix/sonarcloud-quality-gate-issues
Jul 7, 2026
Merged

sathyapramod merged 6 commits into
mainfrom
fix/sonarcloud-quality-gate-issues

Conversation

@sathyapramod
@sathyapramod sathyapramod commented Jul 7, 2026 •
Copy link
Copy Markdown
Contributor

Summary

This PR addresses several SonarQube issues and includes small refactors to reduce complexity while preserving existing behavior.

Fixes

Rule File Changes
S3776 (3) ansi_output.py Reduced cognitive complexity by extracting helper methods:
- format_scenario_recap → _format_recap_line(), _count_states()
- BorderedStream.write → _write_single_line(), _write_wrapped_line(), _split_to_width()
- print_matrix → _get_subcommand(), _resolve_playbook_path(), _format_matrix_action()
S5886 (5) click_cfg.py Added cast("CliOption", ...) around dataclasses.replace() calls to explicitly declare the return type.
S3626 driver/base.py Removed the redundant return from reset() and added # noqa: B027 to suppress Ruff's empty-method warning.
S1700 config.py Renamed self.config to self.config_data to avoid a field-name collision with the class name. Updated all references across ~30 files.

Verification

  • Ruff
  • MyPy
  • Pydoclint
  • Pylint
  • Codespell
  • CSpell
  • All 823 unit tests pass (6 skipped as expected)

- Enhanced error logging in `api.py` to use `LOG.exception` for better traceability.
- Simplified the `get_line_style` function in `ansi_output.py` by removing redundant regex patterns.
- Refactored the `run_scenarios_parallel` function in `worker.py` to improve readability and maintainability by extracting helper functions for prerun steps and future result processing.
- Consolidated variable writing logic in `ansible.py` to a dedicated method for better organization.
- Updated schema validation logic in `schema_v3.py` to improve clarity and maintainability.

These changes aim to enhance code quality and maintainability across the project.
…r handling

- Modified assertions in `test_click_command_ex_with_immediate_exit_failure` to check for exceptions with `exc_info=False` in non-debug mode.
- Updated `test_click_command_ex_with_immediate_exit_failure_debug_mode` to assert exceptions with `exc_info=True` in debug mode.
- Adjusted `test_click_command_ex_failure_no_context` to verify non-debug behavior with exceptions instead of errors.

These changes enhance the accuracy of error handling tests in the click command functionality.
- Introduced `_group_command_parts` method to logically group command parts before wrapping.
- Added `_wrap_lines` method to handle line wrapping and indentation, improving readability.
- Simplified the logic for constructing command lines, ensuring better handling of flags and values.

These changes improve the clarity and maintainability of command output formatting.
- Added tests to ensure that drivers and verifiers log exceptions when they fail to initialize.
- Implemented `_BrokenDriver` and `_BrokenVerifier` classes to simulate failures and verify logging behavior.
- Updated assertions to confirm that the appropriate exceptions are logged and that the system behaves as expected when encountering plugin failures.

These changes improve the robustness of error handling in the testing framework.
- Updated instances of `config` to `config_data` across multiple modules for improved clarity and consistency.
- Adjusted related logic in classes such as `Config`, `Platforms`, `Scenario`, and various dependencies to reflect the new attribute name.
- Ensured that all references in tests were also updated to maintain functionality.

These changes enhance code readability and maintainability by providing a clearer distinction between configuration data and other attributes.
@Hrithik-Gavankar Hrithik-Gavankar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM!

@sathyapramod
sathyapramod merged commit d781118 into main Jul 7, 2026
22 checks passed
@sathyapramod
sathyapramod deleted the fix/sonarcloud-quality-gate-issues branch July 7, 2026 12:30
@github-project-automation github-project-automation Bot moved this from Review to Done in 🧰 devtools project board Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants

0