Skip to content

Conversation

@scottgerring
Copy link
Member

@scottgerring scottgerring commented Jul 9, 2025

This PR introduces three new ReturnTypePatterns (SelfValue, SelfRef, SelfMutRef) and the MustNotExist rule. This lets us do things like assert how builders should look:

builder
    .function_lint()
      .lint_named("builder_style_with_consuming_forbidden")
      // forbid any `with_*` method that returns `Self`
      .matching(|m| m.name_regex("^with_").and(m.returns_self()))
      .with_severity(Severity::Error)
      .must_not_exist()
      .build();

The rule forces code to follow the consuming-builder pattern:

impl WidgetBuilder {
    pub fn set_height(&mut self, h: u32) -> &mut Self {
        self.height = h;
        self
    }
}

and not this:

impl WidgetBuilder {
    pub fn with_height(self, h: u32) -> Self { /* ... */ } 
}```

@scottgerring scottgerring changed the title feat: elaborate on function lints feat(function-lint): add Self-return patterns and MustNotExist rule for builder-style APIs Jul 9, 2025
@scottgerring scottgerring force-pushed the feat/more-function-lints branch 4 times, most recently from 1bc4f16 to 4a5e593 Compare July 9, 2025 18:01
@scottgerring scottgerring force-pushed the feat/more-function-lints branch from 4a5e593 to 19b67f1 Compare July 9, 2025 18:04
@scottgerring scottgerring merged commit bdd6cd2 into main Jul 9, 2025
2 checks passed
@scottgerring scottgerring deleted the feat/more-function-lints branch July 9, 2025 18:09
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