SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Allow parent config as an argument

Open tahirmt opened this issue 1 year ago • 4 comments

New Issue Checklist

Feature Request

I would like to add --parent-config argument to the lint command. That way we don't have to specify the parent-config: inside of the config file. The use case for this is that the parent config path is not known ahead of time and I need to pass it in from a temporary directory where it is pulled and I don't control the path of the directory.

This is how it would look

swiftlint lint --parent-config "path/to/config" 

It would add the parent config to the .swiftlint config file it reads during execution.

tahirmt avatar Jan 16 '24 16:01 tahirmt

You can also pass multiple configurations to the command in which case the first configuration is treated as a parent and the second one as a child. Is this already sufficient for your use case?

SimplyDanny avatar Jan 16 '24 17:01 SimplyDanny

@SimplyDanny I didn't know about this. This might work. Do you know if in this case any further children would still be able to override any rules if they want. e.g for this directory structure

  • .swiftlint.yml
  • ChildFolder - .swiftlint.yml
  • OtherChild - .swiftlint.yml

So in this case if I run swiftlint lint --config "some/parent/config" --config ".swiftlint.yml" would it allow the child folders to override rules? In any case I am going to try it out and if it works I'll close this ticket and comment here

tahirmt avatar Jan 16 '24 18:01 tahirmt

I don't think it works. There is also this comment there

So if you want to use nested configurations, you can't use the --config parameter.

tahirmt avatar Jan 16 '24 18:01 tahirmt

I noticed another issue.. If I pass in the path to lint then the .swiftlint.yml config files are not read at all and it only runs the default rules and since I can't use nested configs when using --config argument that completely breaks it.

swiftlint lint sources/path will ignore the config defined at sources/path/.swiftlint.yml and instead just use the default rules.

tahirmt avatar Jan 16 '24 20:01 tahirmt