Skip to content

refactor: unify LintingResult and Formatter APIs #1568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2025

Conversation

gvozdvmozgu
Copy link
Collaborator

No description provided.

Copy link

github-actions bot commented May 1, 2025

Benchmark for 35acae2

Click to view benchmark
Test Base PR %
DepthMap::from_parent 39.7±0.31µs 39.6±0.28µs -0.25%
fix_complex_query 9.7±0.11ms 9.9±0.71ms +2.06%
fix_superlong 113.7±7.70ms 119.8±15.99ms +5.36%
parse_complex_query 2.8±0.05µs 2.9±0.03µs +3.57%
parse_expression_recursion 5.1±0.03µs 5.1±0.12µs 0.00%
parse_simple_query 802.3±15.14ns 837.3±69.96ns +4.36%

Copy link

github-actions bot commented May 1, 2025

Benchmark for f9cb68e

Click to view benchmark
Test Base PR %
DepthMap::from_parent 40.1±0.23µs 39.7±0.54µs -1.00%
fix_complex_query 9.3±0.13ms 9.7±0.79ms +4.30%
fix_superlong 91.8±6.71ms 101.7±14.49ms +10.78%
parse_complex_query 2.9±0.03µs 2.9±0.05µs 0.00%
parse_expression_recursion 5.1±0.06µs 5.0±0.07µs -1.96%
parse_simple_query 814.3±6.96ns 803.8±17.10ns -1.29%

@gvozdvmozgu gvozdvmozgu force-pushed the linting-result-formatter-api branch from 601bd51 to 28022fd Compare May 1, 2025 19:02
Copy link

github-actions bot commented May 1, 2025

Benchmark for 4655a09

Click to view benchmark
Test Base PR %
DepthMap::from_parent 40.7±0.44µs 40.0±0.26µs -1.72%
fix_complex_query 9.3±0.16ms 9.7±0.66ms +4.30%
fix_superlong 93.4±6.31ms 106.5±17.48ms +14.03%
parse_complex_query 2.8±0.04µs 2.9±0.06µs +3.57%
parse_expression_recursion 5.0±0.11µs 5.1±0.08µs +2.00%
parse_simple_query 794.6±8.96ns 801.8±20.25ns +0.91%

@gvozdvmozgu gvozdvmozgu force-pushed the linting-result-formatter-api branch from 28022fd to aed4fd3 Compare May 1, 2025 19:28
Copy link

github-actions bot commented May 1, 2025

Benchmark for de62ed4

Click to view benchmark
Test Base PR %
DepthMap::from_parent 39.7±0.29µs 40.0±0.54µs +0.76%
fix_complex_query 9.2±0.11ms 9.4±0.43ms +2.17%
fix_superlong 98.5±6.37ms 100.7±8.97ms +2.23%
parse_complex_query 2.8±0.03µs 2.8±0.03µs 0.00%
parse_expression_recursion 5.0±0.06µs 5.2±0.06µs +4.00%
parse_simple_query 789.6±11.16ns 813.5±12.11ns +3.03%

@gvozdvmozgu gvozdvmozgu force-pushed the linting-result-formatter-api branch 3 times, most recently from 4025609 to aa887f2 Compare May 1, 2025 20:35
Copy link

github-actions bot commented May 1, 2025

Benchmark for 50edd6a

Click to view benchmark
Test Base PR %
DepthMap::from_parent 40.3±0.38µs 40.4±1.11µs +0.25%
fix_complex_query 9.2±0.11ms 9.6±0.56ms +4.35%
fix_superlong 94.8±7.50ms 103.6±7.51ms +9.28%
parse_complex_query 2.9±0.04µs 3.0±0.03µs +3.45%
parse_expression_recursion 5.0±0.08µs 5.1±0.07µs +2.00%
parse_simple_query 810.9±14.45ns 813.8±8.89ns +0.36%

Copy link

github-actions bot commented May 1, 2025

Benchmark for cfcf121

Click to view benchmark
Test Base PR %
DepthMap::from_parent 39.7±0.30µs 39.6±0.25µs -0.25%
fix_complex_query 9.2±0.09ms 9.5±0.58ms +3.26%
fix_superlong 92.2±6.29ms 106.0±32.97ms +14.97%
parse_complex_query 2.9±0.03µs 2.8±0.03µs -3.45%
parse_expression_recursion 5.1±0.05µs 5.0±0.05µs -1.96%
parse_simple_query 811.7±9.25ns 807.8±14.26ns -0.48%

@gvozdvmozgu gvozdvmozgu force-pushed the linting-result-formatter-api branch 2 times, most recently from aa887f2 to 80a07e7 Compare May 1, 2025 21:48
Copy link

github-actions bot commented May 1, 2025

Benchmark for bea2fd3

Click to view benchmark
Test Base PR %
DepthMap::from_parent 40.6±0.22µs 40.0±0.28µs -1.48%
fix_complex_query 9.4±0.11ms 9.7±0.69ms +3.19%
fix_superlong 99.6±6.87ms 105.8±15.14ms +6.22%
parse_complex_query 2.8±0.04µs 3.0±0.03µs +7.14%
parse_expression_recursion 5.0±0.04µs 5.1±0.06µs +2.00%
parse_simple_query 784.5±12.87ns 793.4±15.30ns +1.13%

Copy link

github-actions bot commented May 1, 2025

Benchmark for 73afa82

Click to view benchmark
Test Base PR %
DepthMap::from_parent 40.2±1.09µs 39.7±0.28µs -1.24%
fix_complex_query 9.4±0.13ms 9.6±0.64ms +2.13%
fix_superlong 99.3±6.26ms 110.6±16.78ms +11.38%
parse_complex_query 2.9±0.03µs 2.8±0.05µs -3.45%
parse_expression_recursion 5.0±0.04µs 5.3±0.14µs +6.00%
parse_simple_query 796.1±9.71ns 799.8±29.49ns +0.46%

@gvozdvmozgu gvozdvmozgu requested a review from Copilot May 2, 2025 16:42
Copilot

This comment was marked as outdated.

@gvozdvmozgu gvozdvmozgu requested a review from benfdking May 4, 2025 10:39
@gvozdvmozgu gvozdvmozgu force-pushed the linting-result-formatter-api branch from 80a07e7 to a5b0784 Compare May 22, 2025 02:32
Copy link

Benchmark for 4171ecd

Click to view benchmark
Test Base PR %
DepthMap::from_parent 40.3±0.35µs 39.5±0.37µs -1.99%
fix_complex_query 9.2±0.11ms 9.7±0.13ms +5.43%
fix_superlong 94.9±6.46ms 100.4±7.06ms +5.80%
parse_complex_query 2.9±0.04µs 2.9±0.02µs 0.00%
parse_expression_recursion 5.1±0.05µs 5.2±0.19µs +1.96%
parse_simple_query 815.0±6.10ns 801.9±15.62ns -1.61%

Copy link

github-actions bot commented Jun 7, 2025

Benchmark for e745452

Click to view benchmark
Test Base PR %
DepthMap::from_parent 40.5±0.38µs 40.9±0.33µs +0.99%
fix_complex_query 9.4±0.12ms 9.4±0.13ms 0.00%
fix_superlong 93.1±4.99ms 96.6±7.09ms +3.76%
parse_complex_query 2.9±0.05µs 2.9±0.03µs 0.00%
parse_expression_recursion 5.1±0.06µs 5.0±0.04µs -1.96%
parse_simple_query 831.7±28.49ns 783.2±10.39ns -5.83%

Copy link

Benchmark for bffc66c

Click to view benchmark
Test Base PR %
DepthMap::from_parent 39.5±0.20µs 39.1±0.15µs -1.01%
fix_complex_query 9.2±0.03ms 9.3±0.25ms +1.09%
fix_superlong 89.1±4.90ms 92.1±6.08ms +3.37%
parse_complex_query 2.9±0.03µs 2.9±0.07µs 0.00%
parse_expression_recursion 5.2±0.06µs 5.1±0.05µs -1.92%
parse_simple_query 796.8±9.19ns 798.2±9.52ns +0.18%

@gvozdvmozgu gvozdvmozgu force-pushed the linting-result-formatter-api branch from f28d428 to 3dd2e24 Compare June 21, 2025 20:14
Copy link

Benchmark for a957ab8

Click to view benchmark
Test Base PR %
DepthMap::from_parent 61.4±0.84µs 60.1±1.25µs -2.12%
fix_complex_query 12.1±0.05ms 12.1±0.37ms 0.00%
fix_superlong 134.1±13.81ms 140.9±19.90ms +5.07%
parse_complex_query 4.1±0.03µs 4.2±0.05µs +2.44%
parse_expression_recursion 7.0±0.09µs 7.2±0.06µs +2.86%
parse_simple_query 1080.9±14.35ns 1132.8±11.07ns +4.80%

Copy link
Collaborator

@benfdking benfdking left a comment

Choose a reason for hiding this comment

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

Looks good! Just needs a rebase

@gvozdvmozgu gvozdvmozgu force-pushed the linting-result-formatter-api branch from 3dd2e24 to 953ca34 Compare July 8, 2025 11:44
Copy link

github-actions bot commented Jul 8, 2025

Benchmark for 20baa4e

Click to view benchmark
Test Base PR %
DepthMap::from_parent 61.0±1.37µs 60.6±0.48µs -0.66%
fix_complex_query 12.3±1.61ms 12.3±1.56ms 0.00%
fix_superlong 143.5±27.95ms 144.2±26.39ms +0.49%
parse_complex_query 4.1±0.02µs 4.1±0.05µs 0.00%
parse_expression_recursion 7.3±0.04µs 7.2±0.08µs -1.37%
parse_simple_query 1070.4±36.10ns 1070.3±77.04ns -0.01%

@gvozdvmozgu gvozdvmozgu requested a review from Copilot July 8, 2025 12:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the LintingResult and Formatter APIs by encapsulating fields, introducing iterator methods, and unifying formatter signatures.

  • Encapsulated LintingResult and LintedFile internals and added public accessors (violations(), len(), has_unfixable_violations(), into_violations(), IntoIterator).
  • Updated all call sites, tests, and formatters to use the new methods and updated Formatter trait to only two functions: dispatch_file_violations(&LintedFile) and completion_message(count: usize).
  • Adjusted CLI and WASM code to match new APIs and updated expected outputs in JSON test fixtures.

Reviewed Changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
crates/lsp/src/lib.rs Switched from .violations field to .into_violations()
crates/lib/tests/rules.rs Renamed result variables and replaced get_violations calls
crates/lib/src/core/rules/noqa.rs Replaced get_violations with violations() in tests
crates/lib/src/core/linter/linting_result.rs Made fields private, added new, len, has_*, and IntoIterator
crates/lib/src/core/linter/linted_file.rs Encapsulated fields, added constructors and getters
crates/lib/src/core/linter/core.rs Updated creation of LintingResult and removed header dispatch
crates/lib/src/cli/json.rs Updated imports and formatter method signatures
crates/lib/src/cli/github_annotation_native_formatter.rs Updated formatter signature and violation iteration
crates/lib/src/cli/formatters.rs Simplified Formatter trait and refactored implementations
crates/lib-wasm/src/lib.rs Updated WASM linter to use .violations() and clone messages
crates/cli/tests/json/*.stdout Updated expected JSON output ordering
crates/cli-python/tests/json/*.stdout Updated expected JSON output ordering
crates/cli-lib/src/commands_lint.rs Changed completion_message to accept file count
crates/cli-lib/src/commands_fix.rs Refactored run_fix to use new API methods
Comments suppressed due to low confidence (2)

crates/lib/tests/rules.rs:227

  • [nitpick] Variable file here refers to a linting result; consider renaming it to result or linted_file for consistency with the Pass case.
                    let file = linter.lint_string_wrapped(&fail_str, false);

crates/lib/src/core/linter/linted_file.rs:17

  • The attribute #[expect(dead_code)] is not a valid lint attribute; to allow dead code, use #[allow(dead_code)] instead.
    #[expect(dead_code)]

@benfdking benfdking merged commit d85ce6f into main Jul 8, 2025
41 checks passed
@benfdking benfdking deleted the linting-result-formatter-api branch July 8, 2025 12:58
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.

2 participants