55namespace Stolt \ReadmeLint \Commands ;
66
77use Stolt \ReadmeLint \Configuration ;
8+ use Stolt \ReadmeLint \Configuration \Resolver as ConfigurationResolver ;
89use Stolt \ReadmeLint \Linter ;
910use Stolt \ReadmeLint \LintIssue ;
1011use Stolt \ReadmeLint \Rules \BadgeRule ;
@@ -39,7 +40,7 @@ protected function configure(): void
3940 'rules ' ,
4041 null ,
4142 InputOption::VALUE_OPTIONAL ,
42- " Comma-separated list of lint rules to apply (e.g. RequiredSectionsRule, MaxLineLengthRule) "
43+ ' Comma-separated list of lint rules to apply (e.g. RequiredSectionsRule, MaxLineLengthRule) '
4344 )->addOption (
4445 'config ' ,
4546 null ,
@@ -68,18 +69,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6869
6970 $ linter = (new Linter ($ path ));
7071 $ rulesResolver = new Resolver ();
72+ $ configurationResolver = new ConfigurationResolver ();
7173
72- $ viaOptionSetConfigPath = (string ) $ input ->getOption ('config ' );
74+ $ viaOptionSetConfigurationPath = (string ) $ input ->getOption ('config ' );
7375 $ viaOptionSetRules = (string ) $ input ->getOption ('rules ' );
7476
75- if ($ viaOptionSetConfigPath !== '' ) {
76- if (!\file_exists ($ viaOptionSetConfigPath )) {
77- $ output ->writeln ('Configuration file <error>not</error> found at <info> ' . $ viaOptionSetConfigPath . '</info> ' );
77+ $ configurationPath = $ configurationResolver ->resolveConfigurationPath ($ viaOptionSetConfigurationPath );
7878
79+ if ($ configurationPath !== null ) {
80+ if (!\file_exists ($ configurationPath )) {
81+ $ output ->writeln ('Configuration file <error>not</error> found at <info> ' . $ configurationPath . '</info> ' );
7982 return Command::FAILURE ;
8083 }
8184
82- $ config = require $ viaOptionSetConfigPath ;
85+ $ config = require $ configurationPath ;
8386
8487 if ($ config instanceof Configuration) {
8588 $ linter ->addRules ($ config ->getRulesToApply ());
@@ -90,10 +93,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9093 $ linter ->addRules ($ resolved );
9194 }
9295 }
93- } elseif ($ viaOptionSetRules !== '' ) {
96+ }
97+
98+ // Override config rules with --rules option if provided
99+ if ($ viaOptionSetRules !== '' ) {
94100 $ names = \array_values (\array_filter (\array_map ('trim ' , \explode (', ' , $ viaOptionSetRules ))));
101+ // Clear previously added rules and use only the ones from --rules option
102+ $ linter = (new Linter ($ path ));
95103 $ linter ->addRules ($ rulesResolver ->resolveRulesByNames ($ names ));
96- } else {
104+ } elseif ($ configurationPath === null ) {
105+ // No config found and no rules option provided, use defaults
97106 $ linter ->addRules ([
98107 new RequiredSectionsRule (),
99108 new BadgeRule (),
0 commit comments