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

rule: prefer-method-call #222

Open
paperclover opened this issue Jan 29, 2025 · 0 comments
Open

rule: prefer-method-call #222

paperclover opened this issue Jan 29, 2025 · 0 comments
Labels
A-linter Area - linter and lint rules C-rule Category - Lint rule suggestion

Comments

@paperclover
Copy link

Description

Prefer method call syntax instead of passing the namespace's type as the first parameter.

Examples

Examples of incorrect code for this rule

const A = struct {
    fn doSomething(a: A, arg: i32) void {};
    fn actOnPointer(a: *A, arg: i32) void {};
    comptime {
        var a: A = .{};
        doSomething(a, 4); // a.doSomething(4);
        actOnPointer(&a, 4); // a.actOnPointer(4);
        (&a).actOnPointer(2); // a.actOnPointer(4); // maybe separate rule
    }
};

Examples of correct code for this rule

const A = struct {
    fn doSomething(a: A, arg: i32) void {};
    comptime {
        var a: A = .{};
        a.doSomething(4);
        doSomething(.{}, 5); // opinion: transforming to method is uglier than direct.
        (A{ }).doSomething(4); // preserve this form if it was already used
    }
};
@paperclover paperclover added A-linter Area - linter and lint rules C-rule Category - Lint rule suggestion labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - linter and lint rules C-rule Category - Lint rule suggestion
Projects
None yet
Development

No branches or pull requests

1 participant