Skip to content
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

refactoring #17

Closed
wants to merge 1 commit into from
Closed

refactoring #17

wants to merge 1 commit into from

Conversation

bcpeinhardt
Copy link
Owner

Did a little refactoring, trying to keep PRs small so going ahead and making one.
I got rid of the builder for rules. I like builders in general for public apis but it meant the ruleset couldn't be constant and we needed helper code for it when we can just construct the type directly internally.
I also renamed RuleError to RuleViolation, I think the word Error should be used for things that are proper errors in our application.
The rest is stylistic work, commenting, using use a little more, and trying to use some clearer naming patterns.

Comment on lines 66 to +68
// Represents information the linter has access to. We want this to include
// as much as possible and provide ergonomic accessors for querying it.
//
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Represents information the linter has access to. We want this to include
// as much as possible and provide ergonomic accessors for querying it.
//
/// Represents information the linter has access to. We want this to include
/// as much as possible and provide ergonomic accessors for querying it.
///

Let's make this a doc comment

@@ -1,12 +1,19 @@
//// This rule checks the code for unnecessary string literal concatenation,
//// like "a" <> "b" instead of just "ab".
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
//// like "a" <> "b" instead of just "ab".
//// like `"a" <> "b"` instead of just `"ab"`.

fn visit_expressions(
input: glance.Module,
rules: List(Rule),
) -> List(RuleViolation) {
let funcs = extract_functions(input)
let consts = extract_constants(input)

let f = fn(location_identifier, expr) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's f? Maybe a more descriptive name could help here

@jfmengels
Copy link
Collaborator

I don't think we should transform the rules to constants, because them being functions is a good way to make them configurable.

Also the builder pattern brings a lot of niceties, and allows making the rule opaque, which helps with preventing breaking changes, and with simplifying the API. For instance, when having 10 different kinds of visitors, having to specify them all will be very tedious for rule authors.

@bcpeinhardt
Copy link
Owner Author

Cool cool, if y'all wanna keep the builders let reject this PR and then I'll come through and look at some of the naming and flattening callbacks in another PR rather than trying to deal with merge conflicts 😁

@giacomocavalieri giacomocavalieri deleted the refactoring_bs branch April 13, 2024 15:19
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.

3 participants