-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin doesn't respect per-directory configs (nested configuration). #4
Comments
Okay, had some time to investigate it: Basically I had SwiftLint 0.16~ and there is version 0.23 already. From some 0.2X version there is a "fixed bug" or "regression", depends how you look at it. Basically when you use
It does report different results if you have multiple
Will try to make a PR with this change and we can discuss it further there. |
Hmm, very strange. Any issues/docs/discussions you found that would add more context? |
And thanks for looking into this! |
@ashfurrow Yeah, forgot to add related issues, sorry about that! At least these two SwiftLint#1745 and SwiftLint#1889 could be worth looking into, but there are more similar to these. |
FYI: I'm using the Ruby version of Danger-SwiftLint and I've got the same issue. |
#5 is merged and with that and release 0.2.0 of SwiftLint.lint(directory: "Sources", configFile: ".swiftlint.yml")
SwiftLint.lint(directory: "Tests", configFile: "Tests/HarveyTests/.swiftlint.yml") More on this setup can be found in Harvey#11 |
Is it SwiftLint.lint(directory: "Sources", configFile: ".swiftlint.yml") swiftlint.lint(directory: "Sources", configFile: ".swiftlint.yml") swiftlint.lint(directory: "Sources", config_file: ".swiftlint.yml") swiftlint.lint directory: "Sources" configFile: ".swiftlint.yml" swiftlint.lint directory: "Sources" config_file: ".swiftlint.yml" or any of the above? Or Note: I'm asking about the syntax that should be used in the |
hey @revolter - this is pretty old and since then the plugin is built into the Danger-Swift itself! if you're looking for a Swift syntax for SwiftLint, here's a doc for ya: https://danger.systems/swift/tutorials/ios_app.html#swiftlint-for-the-greater-good |
I know, but I'm using Danger Ruby, not Danger Swift. I don't recall the exact reason for this decision, but I think that there were mentions that Danger Ruby is more mature and has more features. |
Now I get it! I was confused because I read the README of the But from the wording of
So, I guess that the Ruby version of the SwiftLint Danger plugin doesn't support |
It does support those configuration options; the README is unclear. Basically you need to choose between the following:
Hope I make sense here, still need my coffee ☕ If you have suggestions for updates to the README, I would welcome a PR 🙇 |
I see. But using the syntax from #4 (comment) you can have the best of both worlds, right? Meaning, you can lint the changed files, while using the correct configuration. 🤔 I actually tried it, and it failed:
|
Hmm, yeah you're right. That should work. I think the problem is that the Swift version and Ruby version of the Danger plugin get their configuration differently. Swift's version passes all the configuration in the invocation (eg: swiftlint.config_file = '.swiftlint.yml'
swiftlint.directory = "DirectoryA"
swiftlint.lint_files The properties you set ahead of time are here: So you might be able to get the code you posted to work with this approach: swiftlint.config_file = '.swiftlint.yml'
swiftlint.directory = 'Sources'
swiftlint.lint_files(fail_on_error: true)
swiftlint.config_file = 'Tests/.swiftlint.yml'
swiftlint.directory = 'Tests'
swiftlint.lint_files(fail_on_error: true) I think. Honestly I haven't used this in a while so I'm a little rusty 😅 |
For some reason, it seems like it concatenates them, and it fails with the error
Instead of using |
Hmm, maybe it's keeping state in between the two invocations. Can you try swapping the order and seeing if you get the same error? Maybe we need like a |
😂 |
But it should simply overwrite it. Unless there is an explicit piece of code which concatenates the previous value with the new one. 🤔 |
I tried using swiftlint.config_file = '.swiftlint.yml'
swiftlint.directory = 'Sources'
swiftlint.lint_files(fail_on_error: true)
swiftlint.config_file = '.swiftlint.yml'
swiftlint.directory = '../Tests'
swiftlint.lint_files(fail_on_error: true) (and not and I get this output:
even though there are files with lint warnings in the |
Hmm, I'm not really sure. Probably something with I don't have a tonne of free time right not to debug this, sorry. I would encourage you to clone the gem and work away at it locally. Most of the logic is in this one file so you should be able to figure it out. Another option would be to invoke Danger twice, with two configs (ie: point it to two different |
I'm pretty sure it's caused by this line:
(https://www.rubydoc.info/stdlib/core/Dir.chdir) Which means that any other plugin called after this might be affected, because the new working directory remains set for the rest of the process. |
For others interested, the current workaround was to use: current_dir = Dir.pwd()
swiftlint.config_file = '.swiftlint.yml'
swiftlint.directory = 'Sources'
swiftlint.lint_files(fail_on_error: true)
Dir.chdir(current_dir)
swiftlint.directory = 'Tests'
swiftlint.lint_files(fail_on_error: true)
Dir.chdir(current_dir) |
Good catch! We should do better with scoping that, eg: Dir.chdir options.delete(:pwd) do
# pwd is changed inside this block, but is changed back afterwards
end |
I created an issue for this, because I spammed this issue enough (sorry 🙈). You could post this proposed solution there 😃 |
I'm currently using this approach: # Define a method to handle directory linting
def lint_directory(directory, config_file)
Dir.chdir(directory) do
swiftlint.config_file = config_file
swiftlint.lint_files(fail_on_error: true)
end
end
# Lint Sources directory
lint_directory('Sources', '.swiftlint.yml')
# Lint Tests directory
lint_directory('Tests', '.swiftlint.yml') |
👋 (basic reference Harvey#11)
As per title, we have a setup that does rely on Sources having different config file and Tests having different config file as well (this is described as valid nested configuration setting here). This works correctly on local machine, but on CI with Danger & SwiftLint it just goes with default root config.
I didn't really have time to look this one up in the code, I know that Ash doesn't have much time to explore this one either, so if anyone is up for checking this one out please feel free to do so.
Cheers!
The text was updated successfully, but these errors were encountered: