Nested configuration doesn't seem to be working for me -- not sure why, not much information to go on.
I have a test that does some force_try
s, and since it's a test, I'm ok with that. It'll fail fast, easy to read. So I thought I might disable force_try
rule in the test folder, but I'm not having any luck. It's entirely possible that I've done something wrong, but I'm not sure what. Would SwitLint print anything if it picked up the nested configuration? If so, it isn't doing that.
$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'Action.swift' (1/32)
Linting 'APIManager.swift' (2/32)
Linting 'Data.swift' (3/32)
Linting 'DateFormatter.swift' (4/32)
Linting 'ErrorParser.swift' (5/32)
Linting 'Gender.swift' (6/32)
Linting 'HTTPManager.swift' (7/32)
Linting '<Redacted>.swift' (8/32)
Linting 'HTTPMethod.swift' (9/32)
Linting 'Log.swift' (10/32)
Linting 'LogLevel.swift' (11/32)
Linting 'NSNull.swift' (12/32)
Linting 'OptionalAny.swift' (13/32)
Linting '<Redacted>Error.swift' (14/32)
Linting '<Redacted>Manager.swift' (15/32)
Linting 'Profile.swift' (16/32)
Linting 'Result.swift' (17/32)
Linting 'Summary.swift' (18/32)
Linting 'Zone.swift' (19/32)
Linting 'ZoneInfo.swift' (20/32)
Linting 'APIManagerTests.swift' (21/32)
Linting 'DataTests.swift' (22/32)
Linting 'ErrorParserTests.swift' (23/32)
Linting 'Extensions.swift' (24/32)
Linting 'GenderTests.swift' (25/32)
Linting '<Redacted>Tests.swift' (26/32)
Linting 'HTTPManagerTests.swift' (27/32)
Linting 'LogTests.swift' (28/32)
Linting 'Mocks.swift' (29/32)
Linting '<Redacted>ManagerTests.swift' (30/32)
<Redacted>/SDK/Tests/Unit/DataTests.swift:11:23: error: Force Try Violation: Force tries should be avoided. (force_try)
<Redacted>/SDK/Tests/Unit/DataTests.swift:16:23: error: Force Try Violation: Force tries should be avoided. (force_try)
<Redacted>/SDK/Tests/Unit/DataTests.swift:22:23: error: Force Try Violation: Force tries should be avoided. (force_try)
<Redacted>/SDK/Tests/Unit/DataTests.swift:28:23: error: Force Try Violation: Force tries should be avoided. (force_try)
<Redacted>/SDK/Tests/Unit/DataTests.swift:34:23: error: Force Try Violation: Force tries should be avoided. (force_try)
Linting 'ResultTests.swift' (31/32)
Linting 'ZoneTests.swift' (32/32)
Done linting! Found 5 violations, 5 serious in 32 files.
$ cat Tests/.swiftlint.yml
disabled_rules:
# Simplifies tests, limited harm in test code.
- force_try
Am I doing something wrong? If so, I don't know what. I'm not even sure if it's detecting the .swiftlint.yml
in the Tests folder.
Looks like the violations are being reported in <Redacted>/SDK/Tests/Unit/DataTests.swift
, whereas your .swiftlint.yml
file disabling the force_try
rule is in Tests/.swiftlint.yml
. So they're in different subdirectories...
Looks like you might want to move that configuration file to <Redacted>/SDK/Tests/.swiftlint.yml
.
Yeah, I coulda been more clear. My current working directory is the <Redacted>/SDK
folder, so the .swiftlint.yml is in <Redacted>/SDK/Tests
.
Here's a tiny example project:
swiftlint-example.zip
Here's the output I get:
$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'AppCode.swift' (1/2)
Linting 'TestCode.swift' (2/2)
<path>/swiftlint-example/Code/AppCode.swift:3:3: error: Force Try Violation: Force tries should be avoided. (force_try)
<path>/swiftlint-example/Tests/Unit/TestCode.swift:3:3: error: Force Try Violation: Force tries should be avoided. (force_try)
Done linting! Found 2 violations, 2 serious in 2 files.
I can't reproduce this, are you sure you're on SwiftLint 0.16.1?
$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'AppCode.swift' (1/2)
Linting 'TestCode.swift' (2/2)
/Users/jp/Downloads/swiftlint-example/Code/AppCode.swift:3:3: error: Force Try Violation: Force tries should be avoided. (force_try)
Done linting! Found 1 violation, 1 serious in 2 files.
Yup:
$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'AppCode.swift' (1/2)
Linting 'TestCode.swift' (2/2)
.../swiftlint-example/Code/AppCode.swift:3:3: error: Force Try Violation: Force tries should be avoided. (force_try)
.../swiftlint-example/Tests/Unit/TestCode.swift:3:3: error: Force Try Violation: Force tries should be avoided. (force_try)
Done linting! Found 2 violations, 2 serious in 2 files.
$ swiftlint version
0.16.1
$
Bizarrely, if I download my own ZIP file, and run it out of ~/Downloads
, I get the same result as you, and the original folder still shows the error I posted above. If I diff the folders, they're the same. Is there any kind of external cached state that could be triggering this? I'm a little baffled now.
A colleague was having issues where he would change rules and SwiftLint didn't seem to pick it up right away, but he didn't have a clear reproducible case, but this makes me wonder if there's a connection.
Using the same shell that I ran in the ~/Downloads
folder gives the two-error result on the original folder, so it's something about the folder rather than the shell (e.g. Environment variables). And just in case my diff tool was ignoring something, I just ran a hash on both:
$ find . -type f -exec md5sum {} \;
99d8ab78a809109a38c9c54cb2edfb81 ./.swiftlint.yml
e14227660a901792af0866ffe4b78627 ./Code/AppCode.swift
be00bac7e366c96e3e01da2027825651 ./Tests/.swiftlint.yml
c71317a3196931c37cf7cae7ea4933a3 ./Tests/Unit/TestCode.swift
$ find ~/Downloads/swiftlint-example -type f -exec md5sum {} \;
99d8ab78a809109a38c9c54cb2edfb81 ~/Downloads/swiftlint-example/.swiftlint.yml
e14227660a901792af0866ffe4b78627 ~/Downloads/swiftlint-example/Code/AppCode.swift
be00bac7e366c96e3e01da2027825651 ~/Downloads/swiftlint-example/Tests/.swiftlint.yml
c71317a3196931c37cf7cae7ea4933a3 ~/Downloads/swiftlint-example/Tests/Unit/TestCode.swift
I don't know enough about SwiftLint's internals to have a theory, other than "SwiftLint uses something in addition to the current folder's contents when running."
Had a theory last night -- and validated it this morning. If .swiftlint.yml
changes, but the code does not, the errors do not change until the code changes. You should be able to reproduce this with the example project.
$ mv Tests/.swiftlint.yml Tests/.swiftlint.bak
$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'AppCode.swift' (1/2)
Linting 'TestCode.swift' (2/2)
~/Downloads/swiftlint-example/Code/AppCode.swift:3:3: error: Force Try Violation: Force tries should be avoided. (force_try)
Done linting! Found 1 violation, 1 serious in 2 files.
$ vim Tests/Unit/TestCode.swift
$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'AppCode.swift' (1/2)
Linting 'TestCode.swift' (2/2)
~/Downloads/swiftlint-example/Code/AppCode.swift:3:3: error: Force Try Violation: Force tries should be avoided. (force_try)
~/Downloads/swiftlint-example/Tests/Unit/TestCode.swift:4:3: error: Force Try Violation: Force tries should be avoided. (force_try)
Done linting! Found 2 violations, 2 serious in 2 files.
$ mv Tests/.swiftlint.bak Tests/.swiftlint.yml
$ swiftlint
Loading configuration from '.swiftlint.yml'
Linting Swift files in current working directory
Linting 'AppCode.swift' (1/2)
Linting 'TestCode.swift' (2/2)
~/Downloads/swiftlint-example/Code/AppCode.swift:3:3: error: Force Try Violation: Force tries should be avoided. (force_try)
~/Downloads/swiftlint-example/Tests/Unit/TestCode.swift:4:3: error: Force Try Violation: Force tries should be avoided. (force_try)
Done linting! Found 2 violations, 2 serious in 2 files.
$
So when I removed the .swiftlint.yml
that disables the force_try rule for test, the warning did not reappear immediately. When I modified the Test, it did. And then when I put the .swiftlint.yml
back in place, the error didn't go away again, presumably because I did not modify the file again.
This is a bug in the caching mechanism. We're tracking many such cases in #1184 but I do want to keep this one explicitly open too as it might contain information that isn't covered in #1184.
I believe I am facing the same issue. .swiftlint.yml
nested in subdirectory has no effect.
@mgrebenets Try swiftlint lint --no-cache
. If that fixes your problem, it's probably the cache. (Thanks for the link to the other issue, @jpsim , --no-cache
is helpful for me in the interim).
@geoffreywiseman Thanks for the tip, it was the caching issue after all!
I was surprised to find out SwiftLint uses some form of caching...
Maybe if it was off by default or controlled via option in .swiftlint.yml
it would be easier to check for this sort of caching issues.
Maybe if it was off by default or controlled via option in
.swiftlint.yml
it would be easier to check for this sort of caching issues.
The idea behind not putting caching as a configurable option is that it shouldn't be buggy 😉. And if it has bugs, we'd need to fix them anyway for the cases in which you'd opt-in to the cache, so might as well just fix them for everyone.
Makes sense, given that other linters like rubocop use caching too 👍. We
temporarily added one line script to remove SwiftLint folder in
~/Library/Application Support for CI tasks. I assume this is where the
caches are stored, are they?
We had to do it this way, because adding no cache option to fastlane's
action would require more effort.
On Sat, 11 Mar 2017 at 9:18 am, JP Simard notifications@github.com wrote:
Maybe if it was off by default or controlled via option in .swiftlint.yml
it would be easier to check for this sort of caching issues.The idea behind not putting caching as a configurable option is that it
shouldn't be buggy 😉. And if it has bugs, we'd need to fix them anyway
for the cases in which you'd opt-in to the cache, so might as well just fix
them for everyone.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/realm/SwiftLint/issues/1289#issuecomment-285800323,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAVZvicF3AeQNA0y0yrFlTyBzkGk9W9Lks5rkcwdgaJpZM4L4o7I
.
We disabled SwiftLint's cache altogether in our 0.17.0 release: https://github.com/realm/SwiftLint/releases/tag/0.17.0
Should be fixed in #1530
Most helpful comment
This is a bug in the caching mechanism. We're tracking many such cases in #1184 but I do want to keep this one explicitly open too as it might contain information that isn't covered in #1184.