Skip to content

Commit fa592c9

Browse files
committed
chore(dev): run markdownlint on git files only
1 parent 9a3d2e8 commit fa592c9

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

vdev/src/commands/check/markdown.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use anyhow::Result;
22

33
use crate::app;
4+
use crate::git::git_ls_files;
45

56
/// Check that markdown is styled properly
67
#[derive(clap::Args, Debug)]
@@ -9,20 +10,22 @@ pub struct Cli {}
910

1011
impl Cli {
1112
pub fn exec(self) -> Result<()> {
12-
app::exec(
13-
"markdownlint",
14-
[
15-
"--config",
16-
"scripts/.markdownlintrc",
17-
"--ignore",
18-
"scripts/node_modules",
19-
"--ignore",
20-
"website/node_modules",
21-
"--ignore",
22-
"target",
23-
".",
24-
],
25-
true,
26-
)
13+
let files = git_ls_files(Some("*.md"))?;
14+
if files.is_empty() {
15+
return Ok(());
16+
}
17+
18+
let args: Vec<&str> = vec![
19+
"--config",
20+
"scripts/.markdownlintrc",
21+
// We should fix these as well. Previously these files were not linted.
22+
"--ignore",
23+
".github"
24+
]
25+
.into_iter()
26+
.chain(files.iter().map(String::as_str))
27+
.collect();
28+
29+
app::exec("markdownlint", &args, true)
2730
}
2831
}

vdev/src/git.rs

+11
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,14 @@ pub fn run_and_check_output(args: &[&str]) -> Result<String> {
165165
fn is_warning_line(line: &str) -> bool {
166166
line.starts_with("warning: ") || line.contains("original line endings")
167167
}
168+
169+
/// Returns a list of tracked files. If `pattern` is specified, it filters using that pattern.
170+
pub fn git_ls_files(pattern: Option<&str>) -> Result<Vec<String>> {
171+
let args = match pattern {
172+
Some(p) => vec!["ls-files", p],
173+
None => vec!["ls-files"],
174+
};
175+
176+
let output = run_and_check_output(&args)?;
177+
Ok(output.lines().map(str::to_owned).collect())
178+
}

0 commit comments

Comments
 (0)