Skip to content

manuelarte/funcorder-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

funcorder-rs

A linter based on the Go Uber style guideline Function Grouping And Ordering.

What it does

Checks that methods within an impl block are ordered consistently: constructors (pub fn new() -> Self) first, then public methods, and then private methods.

Why is this bad?

Following a consistent order for methods within an impl block improves readability and maintainability. Constructors are often the entry point for creating instances of a struct, so placing them first makes the API clearer. A logical grouping of methods by visibility further enhances code comprehension.

Example

struct MyStruct;

impl MyStruct {
    fn private_method(&self) {} // Bad: Private method before constructor

    pub fn constructor() -> Self {
        MyStruct
    }

    pub(crate) fn crate_method(&self) {}

    pub fn public_method(&self) {}
}

Use instead:

struct MyStruct;

impl MyStruct {
    pub fn constructor() -> Self {
        MyStruct
    }

    pub fn public_method(&self) {}

    pub(crate) fn crate_method(&self) {}

    fn private_method(&self) {}
}

How to use it

funcorder-rs is using dylint. Check in their GitHub page how to use it.

For reference:

[workspace.metadata.dylint]
libraries = [
    { git = "https://github.com/manuelarte/funcorder-rs" },
]

About

🦀 Rust Linter 🧐 to check that methods are ordered as constructor-public-private

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors