+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

refactor(rome_service): change how rules config is shaped #3016

Merged
merged 1 commit into from
Aug 9, 2022

Conversation

ematipico
Copy link
Contributor

@ematipico ematipico commented Aug 5, 2022

Summary

Closes #3015

The first attempt of the configuration of the rules tried to be too smart (using IndexMap) but it wasn't well designed and it couldn't be extended easily and as a consequence we have rules.js.rules, which was very redundant.

Fortunately flatten directive form serde seems to fit the bill here, and it works as expected.

Future optimization

At the moment the enabled/disabled rules are always computed every time we get a diagnostic from a rule. Same for when we have to create an AnalysisFilter. This is not efficient. We should look into ways to cache this information, although this would require some work around lifetimes, because RuleFilter only works with references and caching them might only be possible if we use the lifetime coming App.

Test Plan

Updated the tests, and now it all passes! We will need to change the configuration once this lands.

@ematipico ematipico temporarily deployed to aws August 5, 2022 12:44 Inactive
@github-actions
Copy link

github-actions bot commented Aug 5, 2022

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45878 45878 0
Passed 44938 44938 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 395 395 0
Failed 5551 5551 0
Panics 0 0 0
Coverage 6.64% 6.64% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12397 12397 0
Failed 3860 3860 0
Panics 0 0 0
Coverage 76.26% 76.26% 0.00%

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 5, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 773a9a2
Status: ✅  Deploy successful!
Preview URL: https://7de13cd1.tools-8rn.pages.dev
Branch Preview URL: https://feature-normalize-rules-conf.tools-8rn.pages.dev

View logs

@github-actions
Copy link

github-actions bot commented Aug 5, 2022

@ematipico ematipico force-pushed the feature/normalize-rules-config branch from 0544b61 to f0d58ac Compare August 5, 2022 13:11
@ematipico ematipico temporarily deployed to aws August 5, 2022 13:11 Inactive
@ematipico ematipico marked this pull request as ready for review August 5, 2022 13:11
@ematipico ematipico requested a review from leops as a code owner August 5, 2022 13:11
@ematipico ematipico requested a review from a team August 5, 2022 13:11
@ematipico ematipico force-pushed the feature/normalize-rules-config branch from f0d58ac to b44a111 Compare August 5, 2022 13:11
@ematipico ematipico temporarily deployed to aws August 5, 2022 13:11 Inactive
@ematipico ematipico temporarily deployed to aws August 5, 2022 13:26 Inactive
@ematipico ematipico temporarily deployed to aws August 8, 2022 13:32 Inactive
Copy link
Contributor

@leops leops left a comment

Choose a reason for hiding this comment

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

Originally the point of using IndexMap was to preserve the ordering of the rules in the original file if the configuration gets re-serialized, this is no longer the case now and the rules will always get printed in the order defined in rules.rs. Would it have been possible to use #[serde(flatten)] instead to inline the rule map into its parent object ?

@ematipico
Copy link
Contributor Author

ematipico commented Aug 9, 2022

Originally the point of using IndexMap was to preserve the ordering of the rules in the original file if the configuration gets re-serialized, this is no longer the case now and the rules will always get printed in the order defined in rules.rs. Would it have been possible to use #[serde(flatten)] instead to inline the rule map into its parent object ?

True, but unfortunately I bumped into some hiccups.

I tried different approaches:

  • using an enum for rules, something like rules: RuleEnume::Js(IndexMap) with a combination of #[serde(untagged)] but unfortunately it didn't workout as I wanted;
  • I evaluted #[serde(flatten)], but unfortunately doesn't work with deny_unknown_fields, so I am not sure if will workout. I could give it a shot. From the documentation:

Note: flatten is not supported in combination with structs that use deny_unknown_fields. Neither the outer nor inner flattened struct should use that attribute.

@leops
Copy link
Contributor

leops commented Aug 9, 2022

I evaluted #[serde(flatten)], but unfortunately doesn't work with deny_unknown_fields, so I am not sure if will workout. I could give it a shot. From the documentation:

Note: flatten is not supported in combination with structs that use deny_unknown_fields. Neither the outer nor inner flattened struct should use that attribute.

I though the lack of support for deny_unknown_fields wouldn't be a problem since the generated deserialize_*_rules functions are checking for unknown fields anyway

@ematipico ematipico force-pushed the feature/normalize-rules-config branch from 1bbfa43 to 773a9a2 Compare August 9, 2022 13:13
@ematipico ematipico temporarily deployed to aws August 9, 2022 13:13 Inactive
@ematipico
Copy link
Contributor Author

I evaluted #[serde(flatten)], but unfortunately doesn't work with deny_unknown_fields, so I am not sure if will workout. I could give it a shot. From the documentation:

Note: flatten is not supported in combination with structs that use deny_unknown_fields. Neither the outer nor inner flattened struct should use that attribute.

I though the lack of support for deny_unknown_fields wouldn't be a problem since the generated deserialize_*_rules functions are checking for unknown fields anyway

PR updated. It now uses flatten and it seems to work as we wanted.

@ematipico ematipico merged commit e8472a8 into main Aug 9, 2022
@ematipico ematipico deleted the feature/normalize-rules-config branch August 9, 2022 15:56
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

review rule configuration
2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载