Skip to content

refactor(linter): reduce repeated code#13070

Merged
graphite-app[bot] merged 1 commit intomainfrom
08-13-refactor_linter_reduce_repeated_code
Aug 14, 2025
Merged

refactor(linter): reduce repeated code#13070
graphite-app[bot] merged 1 commit intomainfrom
08-13-refactor_linter_reduce_repeated_code

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 13, 2025

Refactor. Many branches of process_path return a default ProcessedModule. All branches return a ModuleProcessOutput with path field containing a clone of path param.

Move the duplicated logic into a separate function, to allow shortening and simplifying the logic.

There may be a small perf benefit of not repeating the same code in many places, but mainly the motivation is to shorten the code, which I find makes it a bit easier to understand.

@github-actions github-actions bot added A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Aug 13, 2025
Copy link
Member Author

overlookmotel commented Aug 13, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 13, 2025

CodSpeed Instrumentation Performance Report

Merging #13070 will not alter performance

Comparing 08-13-refactor_linter_reduce_repeated_code (74fb6c9) with main (5223562)1

Summary

✅ 34 untouched benchmarks

Footnotes

  1. No successful run was found on main (74fb6c9) during the generation of this report, so 5223562 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel marked this pull request as ready for review August 13, 2025 21:15
Copilot AI review requested due to automatic review settings August 13, 2025 21:15
@overlookmotel overlookmotel requested a review from camc314 as a code owner August 13, 2025 21:15
Copy link
Contributor

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 refactor simplifies the process_path method by extracting duplicated return logic into a separate helper function. The change eliminates multiple instances of creating default ModuleProcessOutput with cloned path values.

  • Extracted core processing logic into process_path_to_module helper function
  • Replaced multiple default_output() calls with early returns using ? operator
  • Simplified error handling flow by using Option<ProcessedModule> return type

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

camc314 commented Aug 14, 2025

Merge activity

graphite-app bot pushed a commit that referenced this pull request Aug 14, 2025
Refactor. Many branches of `process_path` return a default `ProcessedModule`. All branches return a `ModuleProcessOutput` with `path` field containing a clone of `path` param.

Move the duplicated logic into a separate function, to allow shortening and simplifying the logic.

There may be a small perf benefit of not repeating the same code in many places, but mainly the motivation is to shorten the code, which I find makes it a bit easier to understand.
@graphite-app graphite-app bot force-pushed the 08-13-refactor_linter_reduce_repeated_code branch from a0c16b9 to 103c51b Compare August 14, 2025 11:58
Refactor. Many branches of `process_path` return a default `ProcessedModule`. All branches return a `ModuleProcessOutput` with `path` field containing a clone of `path` param.

Move the duplicated logic into a separate function, to allow shortening and simplifying the logic.

There may be a small perf benefit of not repeating the same code in many places, but mainly the motivation is to shorten the code, which I find makes it a bit easier to understand.
@graphite-app graphite-app bot force-pushed the 08-13-refactor_linter_reduce_repeated_code branch from 103c51b to 74fb6c9 Compare August 14, 2025 12:00
@graphite-app graphite-app bot merged commit 74fb6c9 into main Aug 14, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 08-13-refactor_linter_reduce_repeated_code branch August 14, 2025 12:04
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 14, 2025
graphite-app bot pushed a commit that referenced this pull request Aug 14, 2025
Further refactor of `process_path`, continuing from #13070.

Avoid unnecessary pre-initialization of `records` and `module_content`, when mostly they're overwritten later. Instead, each branch of the `if` / `else` hold their own vars, and construct a `ProcessedModule`.

There may be some tiny perf benefit of skipping the initializations, but mainly motivation is to make it more explicit what each branch returns, which personally I find makes the logic easier to follow.

Also de-duplicate creation of `allocator_guard`, which was previously repeated in both branches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants