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
refactor: move fixer to RuleCore #860
Conversation
WalkthroughThe overarching change involves refactoring the codebase to support more granular rule application, particularly for transforming lists of meta variables, like import statements, into individual elements. This includes altering how fixers are assigned and accessed, introducing a new Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (3)
- crates/config/src/rule_config.rs (3 hunks)
- crates/napi/src/doc.rs (1 hunks)
- crates/pyo3/src/py_node.rs (1 hunks)
Additional comments: 3
crates/napi/src/doc.rs (1)
- 43-43: The addition of the
fix
field with a default value ofNone
to theNapiConfig
struct aligns with the PR's objectives to support transformations.crates/pyo3/src/py_node.rs (1)
- 309-309: The addition of the
fix
argument to theconfig_from_rule
function is consistent with the PR's goal of enhancing transformation capabilities.crates/config/src/rule_config.rs (1)
- 56-56: The addition of the
fix
field to theSerializableRuleCore
struct and its removal from theSerializableRuleConfig
struct align with the PR's objectives. However, remember that thefixer
field inSerializableRuleConfig
is intended only forStrDoc
as an optimization, as noted in a previous learning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (2)
- crates/config/src/lib.rs (1 hunks)
- crates/config/src/rule_config.rs (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- crates/config/src/rule_config.rs
Additional comments: 2
crates/config/src/lib.rs (2)
- 7-7: The addition of the
rule_core
module is consistent with the PR's objectives to enhance transformation capabilities.- 1-10: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-50]
The removal of the
constraints
module suggests a refactoring. Verify that the functionality previously provided by this module is either no longer needed or has been appropriately integrated into other parts of the system.Verification successful
---
---
The 'rule_core' module contains functionality related to constraints, such as
SerializeConstraintsError
andRuleWithConstraint
, indicating that the responsibilities of the removed 'constraints' module have been integrated into the rule system.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the constraints functionality has been migrated or refactored. rg --type rust 'constraints::'Length of output: 30
Script:
#!/bin/bash # Since the direct search for 'constraints::' yielded no results, let's try to find if there are any files that might have contained the 'constraints' module or related functionality. # We'll look for files that might have been renamed or modified in a way that replaced 'constraints' with another term. rg --type rust --files-with-matches 'mod constraints'Length of output: 55
Script:
#!/bin/bash # Investigate the 'rule_core' module to see if it contains any functionality that might have been part of the 'constraints' module. # We will look for any references to constraint-like functionality within the 'rule_core' module. rg --type rust --files-with-matches 'rule_core'Length of output: 105
Script:
#!/bin/bash # Examine the contents of the 'rule_core' module to understand its functionality and to infer if it has taken over any responsibilities from the 'constraints' module. # We will look at the 'rule_core' related code in the files identified. rg --type rust -C 10 'mod rule_core' crates/config/src/rule_config.rs rg --type rust -C 10 'mod rule_core' crates/config/src/lib.rsLength of output: 507
Script:
#!/bin/bash # Attempt to retrieve the contents of the 'rule_core' module file to inspect its functionality. # We will use 'fd' to find the file and 'cat' to display its contents. fd 'rule_core.rs' --exec cat {}Length of output: 7023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- crates/config/src/rule/deserialize_env.rs (2 hunks)
- crates/config/src/rule_config.rs (5 hunks)
Files skipped from review as they are similar to previous changes (1)
- crates/config/src/rule_config.rs
Additional comments: 1
crates/config/src/rule/deserialize_env.rs (1)
- 147-147: The change in the
parse_global_utils
function parameter type fromSerializableRuleCore
toSerializableRuleCoreWithId
aligns with the PR's objective to support transformations by applying rules to sub-nodes.
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #860 +/- ##
==========================================
+ Coverage 71.31% 71.34% +0.03%
==========================================
Files 71 71
Lines 4594 4592 -2
==========================================
Hits 3276 3276
+ Misses 1318 1316 -2 ☔ View full report in Codecov by Sentry. |
BREAKING CHANGE: RuleConfig.fixer is not available now. Use RuleConfig.matcher.fixer instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (8)
- crates/cli/src/print/colored_print/test.rs (1 hunks)
- crates/cli/src/print/interactive_print.rs (1 hunks)
- crates/cli/src/scan.rs (2 hunks)
- crates/cli/src/verify/snapshot.rs (1 hunks)
- crates/config/src/combined.rs (2 hunks)
- crates/config/src/rule_config.rs (9 hunks)
- crates/config/src/rule_core.rs (4 hunks)
- crates/lsp/src/lib.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- crates/config/src/rule_config.rs
Additional comments: 15
crates/config/src/combined.rs (2)
- 22-22: The sorting logic has been updated to sort rules based on the presence of a
fix
instead of afixer
. This change aligns with the PR objectives and the rest of the changes in the codebase.- 88-88: The conditional check for excluding fixable rules during scanning has been updated to check for
rule.fix.is_some()
. This is consistent with the new structure where thefix
field is directly on theRuleConfig
rather than nested within afixer
.crates/cli/src/verify/snapshot.rs (1)
- 94-94: The reference to
fix
has been updated fromrule_config.fixer
torule_config.matcher.fixer
, which is consistent with the changes in the PR and the new structure of theRuleConfig
.crates/cli/src/print/colored_print/test.rs (1)
- 241-241: The assignment of the
fixer
variable has been updated to usematcher.fixer
instead ofrule.fixer
. This change is in line with the new structure where thefixer
is associated with thematcher
.crates/cli/src/print/interactive_print.rs (2)
- 288-295: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [251-251]
The logic for generating diffs has been updated to use
rule.matcher.fixer
instead ofrule.fixer
. This change is consistent with the new structure of theRuleConfig
and the PR's objectives.
- 288-295: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [269-269]
The logic for matching rules on files has been updated to use
rule.matcher.fixer
instead ofrule.fixer
. This change is consistent with the new structure of theRuleConfig
and the PR's objectives.crates/config/src/rule_core.rs (7)
- 70-79: The addition of the
RuleConfigError
enum and theRResult
type alias is a good practice for error handling and provides a clear way to handle different error types that may occur during rule configuration.- 85-101: The
SerializableRuleCore
struct has been added with a new optionalfix
field of typeSerializableFixer
. This change aligns with the PR objectives to support transformations and is consistent with the new feature of applying transformations to sub-nodes.- 115-120: The method
get_meta_var_matchers
has been added to deserialize meta variable matchers from their serializable form. This method is necessary for the new functionality and is correctly implemented.- 123-134: The method
get_fixer
has been added to obtain aFixer
from theSerializableFixer
. This method is necessary for the new functionality and is correctly implemented.- 136-149: The method
get_matcher
has been added to obtain aRuleWithConstraint
from theSerializableRuleCore
. This method is necessary for the new functionality and is correctly implemented.- 157-157: The
fixer
field has been added to theRuleWithConstraint
struct. This change is consistent with the PR objectives and the new structure of theRuleConfig
.- 188-191: The method
with_fixer
has been added to theRuleWithConstraint
struct to allow setting thefixer
. This change is consistent with the PR objectives and the new structure of theRuleConfig
.crates/cli/src/scan.rs (2)
- 251-251: The logic for generating diffs has been updated to use
rule.matcher.fixer
instead ofrule.fixer
. This change is consistent with the new structure of theRuleConfig
and the PR's objectives.- 269-269: The logic for matching rules on files has been updated to use
rule.matcher.fixer
instead ofrule.fixer
. This change is consistent with the new structure of theRuleConfig
and the PR's objectives.
BREAKING CHANGE: RuleCore is the new name of RuleWithConstraints. The renaming reflects RuleCore = Rule + trans + fix + constraints. fix #862
70d4cb4
to
da7010b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (7)
- crates/config/src/lib.rs (2 hunks)
- crates/config/src/rule/referent_rule.rs (6 hunks)
- crates/config/src/rule_config.rs (9 hunks)
- crates/config/src/rule_core.rs (4 hunks)
- crates/napi/src/doc.rs (2 hunks)
- crates/napi/src/lib.rs (3 hunks)
- crates/pyo3/src/py_node.rs (3 hunks)
Files skipped from review as they are similar to previous changes (4)
- crates/config/src/lib.rs
- crates/config/src/rule_config.rs
- crates/napi/src/doc.rs
- crates/pyo3/src/py_node.rs
Additional comments: 17
crates/config/src/rule/referent_rule.rs (8)
- 1-4: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [1-8]
The imports and module usage seem appropriate and there are no signs of unused imports or missing dependencies.
- 30-30: The type alias
GlobalRules
is correctly defined and uses the newRuleCore
type.- 27-36: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [33-42]
The
insert
method inGlobalRules
has been updated to useRuleCore
and includes proper error handling for duplicate and cyclic rules.
- 58-58: The
RuleRegistration
struct has been updated to useRuleCore
for theglobal
field, aligning with the changes in the PR objectives.- 64-70: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [67-76]
The
get_global
method correctly returns a read guard for the global rules hashmap.
- 110-110: The
RegistrationRef
struct has been updated to useRuleCore
for theglobal
field, which is consistent with the changes made in theRuleRegistration
struct.- 159-159: The
eval_global
method inReferentRule
has been updated to useRuleCore
, which is expected as per the changes in the PR.- 1-4: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [200-214]
The
Matcher
implementation forReferentRule
has been updated to work with the newRuleCore
type, ensuring that the matching process is consistent with the new rule structure.crates/napi/src/lib.rs (3)
- 7-7: The import of
RuleCore
is correct and replaces the previousRuleWithConstraint
, aligning with the changes described in the PR objectives.- 227-227: The type alias
FindInFiles
has been correctly updated to useRuleCore
instead ofRuleWithConstraint
.- 295-295: The
call_sg_node
function signature has been updated to useRuleCore
, which is consistent with the changes made throughout the file.crates/config/src/rule_core.rs (6)
- 1-15: The imports and module usage are correctly organized, and the new imports for
Fixer
and related types are necessary for the changes in this file.- 69-79: The new error type
RuleConfigError
is well-defined and covers all potential error cases that could arise from the rule configuration process.- 83-102: The new struct
SerializableRuleCore
is correctly defined with all necessary fields to support the serialization and deserialization of rule configurations, including the newfix
field.- 136-149: The
get_matcher
method inSerializableRuleCore
correctly constructs aRuleCore
instance, integrating the new fixer functionality as well as other matchers and transformations.- 66-165: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [152-191]
The
RuleCore
struct has been updated to include afixer
field, and the associated methods to manipulate theRuleCore
object are correctly implemented.
- 184-217: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [214-233]
The
Matcher
implementation forRuleCore
correctly uses the new fields and respects the potential kinds, matchers, and transformations, ensuring that the matching process is consistent with the new rule structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (7)
- crates/config/src/lib.rs (2 hunks)
- crates/config/src/rule/referent_rule.rs (6 hunks)
- crates/config/src/rule_config.rs (9 hunks)
- crates/config/src/rule_core.rs (4 hunks)
- crates/napi/src/doc.rs (2 hunks)
- crates/napi/src/lib.rs (3 hunks)
- crates/pyo3/src/py_node.rs (3 hunks)
Files skipped from review as they are similar to previous changes (6)
- crates/config/src/lib.rs
- crates/config/src/rule/referent_rule.rs
- crates/config/src/rule_config.rs
- crates/napi/src/doc.rs
- crates/napi/src/lib.rs
- crates/pyo3/src/py_node.rs
Additional comments: 9
crates/config/src/rule_core.rs (9)
- 1-15: The imports have been reorganized and new ones added to support the new features.
- 69-79: The new
RuleConfigError
enum has been added to encapsulate various error types that can occur in the rule configuration process.- 81-81: The
RResult
type alias is a standard way to simplify the result type throughout the codebase.- 84-101: The
SerializableRuleCore
struct has been introduced with fields that align with the PR objectives, including the newfix
field for transformations.- 104-150: The implementation of
SerializableRuleCore
includes methods for deserialization and fetching meta variable matchers, which are necessary for the new functionality.- 66-165: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [152-191]
The
RuleCore
struct has been updated with a newfixer
field and associated methods, which is consistent with the PR objectives to allow transformations on specific sub-nodes.
- 193-208: The
Default
implementation forRuleCore
has been updated to include the default value for the newfixer
field.- 184-217: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [214-233]
The
Matcher
implementation forRuleCore
has been updated to include the new matching logic, which is crucial for the new feature's functionality.
- 260-267: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [263-297]
The tests have been updated to reflect the new structures and functionalities, ensuring that the new features work as expected.
fix #723
Summary by CodeRabbit
New Features
Improvements
Refactor
RuleWithConstraint
with the more robustRuleCore
.Removals
constraints
module to simplify the configuration framework.Bug Fixes