File tree 2 files changed +29
-15
lines changed
2 files changed +29
-15
lines changed Original file line number Diff line number Diff line change 1
1
use anyhow:: Result ;
2
2
3
3
use crate :: app;
4
+ use crate :: git:: git_ls_files;
4
5
5
6
/// Check that markdown is styled properly
6
7
#[ derive( clap:: Args , Debug ) ]
@@ -9,20 +10,22 @@ pub struct Cli {}
9
10
10
11
impl Cli {
11
12
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 )
27
30
}
28
31
}
Original file line number Diff line number Diff line change @@ -165,3 +165,14 @@ pub fn run_and_check_output(args: &[&str]) -> Result<String> {
165
165
fn is_warning_line ( line : & str ) -> bool {
166
166
line. starts_with ( "warning: " ) || line. contains ( "original line endings" )
167
167
}
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
+ }
You can’t perform that action at this time.
0 commit comments