-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): support buildifier (#251)
* feat(bazel): support buildifier * fix: correct enum name
- Loading branch information
Showing
5 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use super::execute_command; | ||
use crate::error::MdsfError; | ||
|
||
#[inline] | ||
pub fn format_using_buildifier( | ||
snippet_path: &std::path::Path, | ||
) -> Result<(bool, Option<String>), MdsfError> { | ||
let mut cmd = std::process::Command::new("buildifier"); | ||
|
||
cmd.arg(snippet_path); | ||
|
||
execute_command(&mut cmd, snippet_path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use schemars::JsonSchema; | ||
|
||
use super::{Lang, LanguageFormatter}; | ||
use crate::{ | ||
error::MdsfError, | ||
formatters::{buildifier::format_using_buildifier, MdsfFormatter}, | ||
}; | ||
|
||
#[derive(Default, serde::Serialize, serde::Deserialize, JsonSchema)] | ||
#[cfg_attr(test, derive(Debug, PartialEq, Eq))] | ||
pub enum Bazel { | ||
#[default] | ||
#[serde(rename = "buildifier")] | ||
Buildifier, | ||
} | ||
|
||
impl Default for Lang<Bazel> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self { | ||
enabled: true, | ||
formatter: MdsfFormatter::<Bazel>::default(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for MdsfFormatter<Bazel> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self::Single(Bazel::Buildifier) | ||
} | ||
} | ||
|
||
impl LanguageFormatter for Bazel { | ||
#[inline] | ||
fn format_snippet( | ||
&self, | ||
snippet_path: &std::path::Path, | ||
) -> Result<(bool, Option<String>), MdsfError> { | ||
match self { | ||
Self::Buildifier => format_using_buildifier(snippet_path), | ||
} | ||
} | ||
} | ||
|
||
impl core::fmt::Display for Bazel { | ||
#[inline] | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
Self::Buildifier => write!(f, "buildifier"), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_bazel { | ||
use super::Bazel; | ||
use crate::languages::Lang; | ||
|
||
#[test] | ||
fn it_should_be_enabled_by_default() { | ||
assert!(Lang::<Bazel>::default().enabled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters