Skip to content

Commit

Permalink
feat: Enable setting default --merge-base-with values
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ZainRizvi authored Mar 2, 2023
1 parent 507d273 commit 75ea9c0
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
merge_base_with="main"

[[linter]]
code = 'RUSTFMT'
include_patterns = ['**/*.rs']
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
5 changes: 5 additions & 0 deletions src/lint_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use serde::{Deserialize, Serialize};
pub struct LintRunnerConfig {
#[serde(rename = "linter")]
pub linters: Vec<LintConfig>,

/// 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<String>,
}

fn is_false(b: &bool) -> bool {
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,13 @@ fn do_main() -> Result<i32> {
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
};
Expand Down
1 change: 1 addition & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn temp_config_returning_msg(lint_message: LintMessage) -> Result<tempfile::Name
let serialized = serde_json::to_string(&lint_message)?;
let config = temp_config(&format!(
"\
merge_base = \"some_base\"
[[linter]]
code = 'TESTLINTER'
include_patterns = ['**']
Expand Down

0 comments on commit 75ea9c0

Please sign in to comment.