Skip to content

Latest commit

 

History

History
116 lines (92 loc) · 2.62 KB

CONTRIBUTING.md

File metadata and controls

116 lines (92 loc) · 2.62 KB

🤝 Contributing

For all contributions it is necessary that commits are made following a standard, that is why we use Conventional Commits.

How to set up the project

🦀 Install Rust via rustup

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

🚀 Install clippy and rustfmt

$ rustup component add clippy
$ rustup component add rustfmt

🖖 Useful commands

# Run the project
$ cargo run

# Run tests
$ cargo test

# Run linters
$ cargo clippy

# Run rustfmt
$ cargo fmt

How to add a new check

  1. Create a new file in the src/checks directory. The file name should contain the name of the check, for example: src/checks/example.rs
  2. Add a new struct for this check, for example:
pub(crate) struct ExampleChecker {
    template: String,
}
  1. Implement 2 methods for this struct: default and run, for example:
impl Default for ExampleChecker {
    fn default() -> Self {
        Self {
            template: String::from("Example detected"),
        }
    }
}

impl Check for ExampleChecker {
    fn run(&mut self, line: &LineEntry) -> Option<Warning> {
        // Write your check logic here...
        if line.raw_string.starts_with("EXAMPLE") {
            Some(Warning::new(line.clone(), self.template.clone()))
        } else {
            None
        }
    }
}
  1. Write tests for this check, for example:
#[cfg(test)]
mod tests {
    use super::*;
    use std::path::PathBuf;

    #[test]
    fn working_run() {
        let mut checker = ExampleChecker::default();
        let line = &LineEntry {
            number: 1,
            file_path: PathBuf::from(".env"),
            raw_string: String::from("FOO=BAR"),
        };
        assert_eq!(None, checker.run(line));
    }

    #[test]
    fn failing_run() {
        let mut checker = ExampleChecker::default();
        let line = LineEntry {
            number: 1,
            file_path: PathBuf::from(".env"),
            raw_string: String::from("EXAMPLE=true"),
        };
        let expected = Some(Warning::new(line.clone(), String::from("Example detected")));
        assert_eq!(expected, checker.run(&line));
    }
}
  1. Add a new check to the file src/checks.rs, for example:
mod example;
//...
fn checklist() -> Vec<Box<dyn Check>> {
    vec![
        Box::new(leading_space::LeadingSpaceChecker::default()),
        Box::new(example::ExampleChecker::default()),
    ]
}
  1. That's all! You are awesome! ❤️