I want to lint a subdirectory with my root configuration, to only get the filtered result.
files as follow:
root:
- .swiftlint.yml
- Config
- a.swift
- b.swift
- Module
- a.swift
- b.swift
.swiftlint.yml content:
included:
- Module
- Config
excluded:
- Module/a.swift
disabled_rules:
- todo
suppose my current working dir is root directory:
if I run: swiftlint
, works correctly
if I run: swiftlint -- Module/
or swiftlint lint --path Module/
, lint all swift, including Module/a.swift, and print Todo Violation. seems root .swiftlint.yml is ignored
if I run swiftlint lint --config .swiftlint.yml --path Module/
, report Module/.swiftlint.yml:File not found
, the relative path is relative to --path, not current working directory, a little counter-intuitive.
if I run swiftlint lint --config $PWD/.swiftlint.yml --path Module/
or swiftlint lint --config $PWD/.swiftlint.yml -- Module/
, report No lintable files found at paths.
if I copy create a more Module directory in Module directory, and cp Module/*.swift Module/Module/
, it works by lint Module/Module/b.swift, seems .swiftlint.yml's include and exclude rule also relative to --path
if I run swiftlint lint --config $PWD/.swiftlint.yml -- Module x
(path x is not exist), ~lint finally works~. it lint all twice, as if I run swiftline lint
twice
if I run swiftlint lint -- Module x
, it's same.
if I run swiftlint lint --config $PWD/.swiftlint.yml -- Module/b.swift
, it works. but this way need my specify the swift file I want to lint. I need to manual exclude unwanted swift file.
if I run swiftlint lint --config $PWD/.swiftlint.yml -- Module/b.swift Module
, it lint Module/b.swift, Module/b.swift, Config/b.swift, Config/a.swift, as if provide directory path same as lint root.
if I run swiftlint lint --config $PWD/.swiftlint.yml -- Module Config
, it lint all file twice, as run swiftlint lint --config $PWD/.swiftlint.yml
twice
So. How can I only lint a subdirectory with root .swiftlint.yml when contains --include?
swiftlint version
to be sure)?Hi @SolaWing,
The README currently states that included
would override the --path
parameter. So, in theory, I do not see a way of doing what you want without removing the included
section in your config file.
However, it appears that there are some issues with these "path" options (#2275, #2351).
I've just had some troubles with this as well while using danger-swiflint.
I've done some investigation and I've also found that there are issues with the implementation when you specify a single path in the command line invocation. In this case, the config's rootPath seems to be set to the path to lint which mess up with the file path resolution when searching for files to lint.
Maybe there should be some changes about how the --path
option is handled and that it should override the included
option instead of being the other way around. And when implementing this, we could fix the implementation.
What's your thoughts about this @marcelofabri @jpsim ?
--path inputed by user, config file normal is a default project share config. so --path override the included option seems more reasonable.
so this may be a feature request.
This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!
Most helpful comment
--path inputed by user, config file normal is a default project share config. so --path override the included option seems more reasonable.
so this may be a feature request.