realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.46k stars 2.2k forks source link

Adds `--working-directory` command line option #5560

Closed mildm8nnered closed 5 days ago

mildm8nnered commented 2 months ago

Adds a --working-directory argument to lint and analyze, for users who cannot easily control the current directory when executing SwiftLint (e.g. in some plugin and CI scenarios).

Addresses #5424

This is required because .swiftlint.yml's in the current directory are treated slightly differently to .swiftlint.yml's found deeper in the tree.

For example:

$ pwd
/Users/some.user/Documents/Source/SwiftLint
$
$ swiftlint --quiet --reporter summary
Linting Swift files in current working directory
+-----------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| rule identifier | opt-in | correctable | custom | warnings | errors | total violations | number of files |
+-----------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| Total           |        |             |        |        0 |      0 |                0 |               0 |
+-----------------+--------+-------------+--------+----------+--------+------------------+-----------------+
$
$
$ cd ../..
$ pwd
/Users/some.user/Documents
$
$
$ swiftlint  --quiet --reporter summary Source/SwiftLint
Linting Swift files at paths Source/SwiftLint
+---------------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| rule identifier     | opt-in | correctable | custom | warnings | errors | total violations | number of files |
+---------------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| file_name           | yes    | no          | no     |       18 |      0 |               18 |              18 |
| type_name           | no     | no          | no     |        8 |      0 |                8 |               8 |
| file_header         | yes    | no          | no     |        5 |      0 |                5 |               5 |
| trailing_comma      | no     | yes         | no     |        4 |      0 |                4 |               1 |
| empty_xctest_method | yes    | no          | no     |        1 |      0 |                1 |               1 |
| legacy_objc_type    | yes    | no          | no     |        1 |      0 |                1 |               1 |
| let_var_whitespace  | yes    | no          | no     |        1 |      0 |                1 |               1 |
+---------------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| Total               |        |             |        |       38 |      0 |               38 |              21 |
+---------------------+--------+-------------+--------+----------+--------+------------------+-----------------+
Done linting! Found 38 violations, 0 serious in 646 files.
$
$
$ swiftlint --quiet --reporter summary --working-directory Source/SwiftLint 
Linting Swift files in current working directory
+-----------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| rule identifier | opt-in | correctable | custom | warnings | errors | total violations | number of files |
+-----------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| Total           |        |             |        |        0 |      0 |                0 |               0 |
+-----------------+--------+-------------+--------+----------+--------+------------------+-----------------+

We could assume that the first .swiftlint.yml we encountered was the "main" one, but this would not be true in the unusual, but valid case, where users intentionally did not have a "main" .swiftlint.yml. Additionally, some SwiftLint code, specifically some reporters, assume that the current directory is also the top-level directory of the project.

All relative paths on the command line and in configuration files will be treated as relative to the specified working directory.

SwiftLintBot commented 2 months ago
17 Messages
:book: Linting Aerial with this PR took 1.02s vs 0.98s on main (4% slower)
:book: Linting Alamofire with this PR took 1.37s vs 1.36s on main (0% slower)
:book: Linting Brave with this PR took 8.04s vs 8.03s on main (0% slower)
:book: Linting DuckDuckGo with this PR took 4.39s vs 4.42s on main (0% faster)
:book: Linting Firefox with this PR took 11.35s vs 11.34s on main (0% slower)
:book: Linting Kickstarter with this PR took 10.07s vs 10.06s on main (0% slower)
:book: Linting Moya with this PR took 0.56s vs 0.56s on main (0% slower)
:book: Linting NetNewsWire with this PR took 2.77s vs 2.75s on main (0% slower)
:book: Linting Nimble with this PR took 0.82s vs 0.81s on main (1% slower)
:book: Linting PocketCasts with this PR took 8.68s vs 8.68s on main (0% slower)
:book: Linting Quick with this PR took 0.45s vs 0.46s on main (2% faster)
:book: Linting Realm with this PR took 5.02s vs 5.05s on main (0% faster)
:book: Linting Sourcery with this PR took 2.53s vs 2.51s on main (0% slower)
:book: Linting Swift with this PR took 4.93s vs 4.92s on main (0% slower)
:book: Linting VLC with this PR took 1.33s vs 1.34s on main (0% faster)
:book: Linting Wire with this PR took 19.22s vs 19.25s on main (0% faster)
:book: Linting WordPress with this PR took 14.21s vs 14.22s on main (0% faster)

Generated by :no_entry_sign: Danger