From 75ea9c09cd6904e6e53170af0661fd3dcb39c9e9 Mon Sep 17 00:00:00 2001 From: Zain Rizvi Date: Thu, 2 Mar 2023 13:15:05 -0600 Subject: [PATCH] feat: Enable setting default --merge-base-with values * feat: You can now specify a default value for the parameter in the .lintrunner.toml file. To do so, add a line to the top in the form . Generally you'll set that to either or , depending on how your repo is setup. * Switch to option * Doc updates * fix * lint fixes --- .lintrunner.toml | 2 ++ README.md | 2 ++ src/lint_config.rs | 5 +++++ src/main.rs | 7 +++++++ tests/integration_test.rs | 1 + 5 files changed, 17 insertions(+) diff --git a/.lintrunner.toml b/.lintrunner.toml index 84788e7..1fe4aa6 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -1,3 +1,5 @@ +merge_base_with="main" + [[linter]] code = 'RUSTFMT' include_patterns = ['**/*.rs'] diff --git a/README.md b/README.md index 63711da..f42e523 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ file, conventionally named `.lintrunner.toml`. Here is an example linter configuration: ```toml +merge_base_with = 'main' + [[linter]] name = 'FLAKE8' include_patterns = [ diff --git a/src/lint_config.rs b/src/lint_config.rs index 5952fb5..b1fc6d5 100644 --- a/src/lint_config.rs +++ b/src/lint_config.rs @@ -10,6 +10,11 @@ use serde::{Deserialize, Serialize}; pub struct LintRunnerConfig { #[serde(rename = "linter")] pub linters: Vec, + + /// The default value for the `merge_base_with` parameter. + /// Recommend setting this is set to your default branch, e.g. `main` + #[serde()] + pub merge_base_with: Option, } fn is_false(b: &bool) -> bool { diff --git a/src/main.rs b/src/main.rs index 45d1ed8..78d0f15 100644 --- a/src/main.rs +++ b/src/main.rs @@ -212,6 +212,13 @@ fn do_main() -> Result { RevisionOpt::Revision(revision) } else if let Some(merge_base_with) = args.merge_base_with { RevisionOpt::MergeBaseWith(merge_base_with) + } else if lint_runner_config.merge_base_with.is_some() { + RevisionOpt::MergeBaseWith( + lint_runner_config + .merge_base_with + .clone() + .expect("Merge base should be defined"), + ) } else { RevisionOpt::Head }; diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 0c93ad3..5b5e9a9 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -47,6 +47,7 @@ fn temp_config_returning_msg(lint_message: LintMessage) -> Result