11use std:: { collections:: HashSet , convert:: TryFrom , io:: Write } ;
22
3- use anyhow:: { Context , Result } ;
3+ use anyhow:: { anyhow , Context , Result } ;
44use clap:: Parser ;
55
6+ use directories:: ProjectDirs ;
67use lintrunner:: {
7- do_init, do_lint, lint_config:: get_linters_from_config, path:: AbsPath , render:: print_error,
8+ do_init, do_lint,
9+ init:: check_init_changed,
10+ lint_config:: { get_linters_from_config, LintRunnerConfig } ,
11+ path:: AbsPath ,
12+ render:: print_error,
813 PathsToLint , RenderOpt , RevisionOpt ,
914} ;
1015
@@ -72,6 +77,12 @@ struct Args {
7277 /// not a user-attended terminal.
7378 #[ clap( long) ]
7479 force_color : bool ,
80+
81+ /// If set, use ths provided path to store any metadata generated by
82+ /// lintrunner. By default, this is a platform-specific location for
83+ /// application data (e.g. $XDG_DATA_HOME for UNIX systems.)
84+ #[ clap( long) ]
85+ data_path : Option < String > ,
7586}
7687
7788#[ derive( Debug , Parser ) ]
@@ -120,7 +131,14 @@ fn do_main() -> Result<i32> {
120131 . collect :: < HashSet < _ > > ( )
121132 } ) ;
122133
123- let linters = get_linters_from_config ( & config_path, skipped_linters, taken_linters) ?;
134+ let lint_runner_config = LintRunnerConfig :: new ( & config_path) ?;
135+
136+ let linters = get_linters_from_config (
137+ & lint_runner_config. linters ,
138+ skipped_linters,
139+ taken_linters,
140+ & config_path,
141+ ) ?;
124142
125143 let enable_spinners = args. verbose == 0 && args. output == RenderOpt :: Default ;
126144
@@ -144,13 +162,18 @@ fn do_main() -> Result<i32> {
144162 RevisionOpt :: Head
145163 } ;
146164
165+ let project_dirs = ProjectDirs :: from ( "" , "" , "lintrunner" ) ;
166+ let project_dirs = project_dirs. ok_or ( anyhow ! ( "Could not find project directories" ) ) ?;
167+ let data_dir = project_dirs. data_dir ( ) ;
168+
147169 match args. cmd {
148170 Some ( SubCommand :: Init { dry_run } ) => {
149171 // Just run initialization commands, don't actually lint.
150- do_init ( linters, dry_run)
172+ do_init ( & config_path , data_dir , linters, dry_run)
151173 }
152174 None => {
153175 // Default command is to just lint.
176+ check_init_changed ( & config_path, data_dir, & lint_runner_config) ?;
154177 do_lint (
155178 linters,
156179 paths_to_lint,
0 commit comments