Skip to content

fix: reformat groups.json and add --fix to linter#5638

Merged
renecannao merged 1 commit intov3.0from
fix/lint-groups-json-format
Apr 16, 2026
Merged

fix: reformat groups.json and add --fix to linter#5638
renecannao merged 1 commit intov3.0from
fix/lint-groups-json-format

Conversation

@renecannao
Copy link
Copy Markdown
Contributor

@renecannao renecannao commented Apr 16, 2026

Summary

Recent merges (e.g., #5625) reformatted groups.json with multi-line arrays, breaking the one-line-per-test convention documented in test/tap/groups/README.md. This caused merge conflicts and CI lint failures on branches that added new entries in the correct format.

Changes

  • test/tap/groups/groups.json: Reformat to canonical format — one line per test, compact arrays, sorted keys, space before colon.
  • test/tap/groups/lint_groups_json.py: Add --fix mode that auto-reformats the file in-place. Usage: python3 test/tap/groups/lint_groups_json.py --fix. The linter now also prints a hint suggesting --fix when it finds errors.

Test plan

  • python3 test/tap/groups/lint_groups_json.py passes (385 entries, sorted, compact)
  • python3 test/tap/groups/lint_groups_json.py --fix is idempotent (no-op on already-correct file)
  • CI-lint-groups-json passes

Summary by CodeRabbit

Release Notes

  • New Features

    • Added --fix command-line flag to automatically reformat and fix configuration files to canonical format with proper key ordering and consistent formatting.
    • Improved error messages with helpful hints for resolving detected issues.
  • Bug Fixes

    • Corrected exit code behavior to properly reflect successful auto-fixes.

groups.json was reformatted with multi-line arrays by a recent merge,
breaking the one-line-per-test convention documented in README.md.

Changes:
- Reformat groups.json to canonical format (one line per test, compact
  arrays, sorted keys, space before colon).
- Add --fix mode to lint_groups_json.py that auto-reformats the file
  in-place, preventing this class of issue in the future.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fa836975-9a59-499c-8576-cc344208c404

📥 Commits

Reviewing files that changed from the base of the PR and between 13ff9d7 and a0f685b.

📒 Files selected for processing (2)
  • test/tap/groups/groups.json
  • test/tap/groups/lint_groups_json.py

📝 Walkthrough

Walkthrough

The script now supports command-line arguments via argparse, including an optional path positional argument and a --fix flag. A new reformat_groups() function writes canonical formatting to groups.json. Linting logic was refactored into lint_groups() returning both exit code and error count, with main() conditionally reformatting and re-linting before exit.

Changes

Cohort / File(s) Summary
Linting Script Refactor
test/tap/groups/lint_groups_json.py
Added argparse CLI support with --fix flag; introduced reformat_groups() to canonically format groups.json with sorted keys and entries; refactored lint_groups() to return (exit_code, error_count) tuple; updated main() to parse arguments and optionally auto-fix before re-linting; added user hints on lint failures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A linting script hops to new heights,
With --fix flags and reformatted might,
Groups sorted clean, one entry per line,
Args parsed smooth—oh, how they shine!
Canonical JSON, now perfectly fine! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/lint-groups-json-format

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

@renecannao renecannao merged commit aecac96 into v3.0 Apr 16, 2026
8 of 9 checks passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the lint_groups_json.py script by introducing an auto-fix feature via a new --fix command-line argument and refactoring the logic into modular functions. The changes include a new reformat_groups function to canonicalize the JSON format and updates to the linting logic to return error counts. Feedback was provided to improve the robustness of the reformat_groups function by adding error handling for file access, JSON parsing, and data type validation.

Comment on lines +29 to +42
def reformat_groups(groups_path):
"""Read groups.json and rewrite it in the canonical one-line-per-entry format."""
with open(groups_path, "r") as f:
data = json.load(f)

if not isinstance(data, dict):
print(f"ERROR: Top-level value must be a JSON object", file=sys.stderr)
return False

sorted_keys = sorted(data.keys())
lines = ["{"]
for i, key in enumerate(sorted_keys):
groups = data[key]
# Sort groups for determinism, but keep special strings like @proxysql_min_version at end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The reformat_groups function lacks error handling for missing files or invalid JSON, and it doesn't verify that the values in the dictionary are lists of strings. This can lead to unhandled exceptions (e.g., FileNotFoundError, JSONDecodeError, or TypeError during sorting). Adding these checks ensures the script fails gracefully with informative error messages, consistent with the behavior of lint_groups.

def reformat_groups(groups_path):
    """Read groups.json and rewrite it in the canonical one-line-per-entry format."""
    if not os.path.isfile(groups_path):
        print(f"ERROR: {groups_path} not found", file=sys.stderr)
        return False

    try:
        with open(groups_path, "r") as f:
            data = json.load(f)
    except json.JSONDecodeError as e:
        print(f"ERROR: Invalid JSON in {groups_path}: {e}", file=sys.stderr)
        return False

    if not isinstance(data, dict):
        print(f"ERROR: Top-level value must be a JSON object", file=sys.stderr)
        return False

    sorted_keys = sorted(data.keys())
    lines = ["{"]
    for i, key in enumerate(sorted_keys):
        groups = data[key]
        if not isinstance(groups, list) or not all(isinstance(g, str) for g in groups):
            print(f"ERROR: Value for '{key}' must be a list of strings", file=sys.stderr)
            return False
        # Sort groups for determinism, but keep special strings like @proxysql_min_version at end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant