2828 ruleset := atom (),
2929 rules => [tuple ()],
3030 resolved_files => dynamic (),
31- ignore => [string ()]
31+ ignore => [string ()],
32+ allow_no_files => boolean ()
3233 }.
3334-export_type ([t / 0 ]).
3435
@@ -280,6 +281,8 @@ default_for([config, files]) ->
280281 [];
281282default_for ([config , ignore ]) ->
282283 [];
284+ default_for ([config , allow_no_files ]) ->
285+ false ;
283286default_for ([config , ruleset ]) ->
284287 undefined ;
285288default_for ([config , rules ]) ->
@@ -713,9 +716,11 @@ get_config_opt(OptName, Config, true = _Compulsory) ->
713716
714717config_is_valid (CustomRulesetNames , Config ) ->
715718 maybe
716- ok ?= map_keys_are_in (Config , [files , ignore , ruleset , rules ]),
719+ ok ?= map_keys_are_in (Config , [files , ignore , allow_no_files , ruleset , rules ]),
717720 {ok , FileGlobs } ?= get_config_opt (files , Config , true ),
718- ok ?= all_files_globs_are_valid (FileGlobs ),
721+ {ok , AllowNoFiles } ?= get_config_opt (allow_no_files , Config , false ),
722+ ok ?= is_config_boolean (allow_no_files , AllowNoFiles ),
723+ ok ?= all_files_globs_are_valid (FileGlobs , AllowNoFiles ),
719724 {ok , Ignore } ?= get_config_opt (ignore , Config , false ),
720725 ok ?= is_list_of_ignorables (ignore , Ignore ),
721726 {ok , Ruleset } ?= get_config_opt (ruleset , Config , false ),
@@ -744,14 +749,18 @@ map_keys_are_in(Map, Keys) ->
744749 ])}
745750 end .
746751
747- all_files_globs_are_valid (FileGlobs ) when not is_list (FileGlobs ) orelse FileGlobs =:= [] ->
752+ all_files_globs_are_valid (FileGlobs , _AllowNoFiles ) when
753+ not is_list (FileGlobs ) orelse FileGlobs =:= []
754+ ->
748755 {error , " 'files' is expected to be a non-empty list." };
749- all_files_globs_are_valid (FileGlobs ) ->
756+ all_files_globs_are_valid (FileGlobs , AllowNoFiles ) ->
750757 case lists :all (fun (G ) -> is_list (G ) andalso G =/= [] end , FileGlobs ) of
751758 true ->
752759 case lists :any (fun (G ) -> filelib :wildcard (G ) =/= [] end , FileGlobs ) of
753760 true ->
754761 ok ;
762+ false when AllowNoFiles ->
763+ ok ;
755764 false ->
756765 {error ,
757766 io_lib :format (" yielded no files to analyse in [\" ~s \" ]." , [
@@ -762,6 +771,11 @@ all_files_globs_are_valid(FileGlobs) ->
762771 {error , " 'files' is expected to be a non-empty list of non-empty strings." }
763772 end .
764773
774+ is_config_boolean (_What , Value ) when is_boolean (Value ) ->
775+ ok ;
776+ is_config_boolean (What , _Value ) ->
777+ {error , io_lib :format (" '~s ' is expected to be a boolean." , [What ])}.
778+
765779is_list_of_ignorables (What , List ) when not is_list (List ) ->
766780 {error , io_lib :format (" '~s ' is expected to be a list." , [What ])};
767781is_list_of_ignorables (What , List ) ->
0 commit comments