Skip to content
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

Swiftlint should consider excluded paths in config file #180

Merged
merged 8 commits into from
Feb 4, 2019

Conversation

absolute-heike
Copy link
Contributor

Right now changes in e.g. Pods folder are also checked by Swiftlint, even though they are excluded in the local swiftlint.yml config file. This bug was fixed 8 days ago in realm/SwiftLint#2574 (version 0.30.1).

This PR changes the handling to pass the filelist to swiftlint as an array and set --force-exclude so the config exludes are adhered to.

Calls to Swiftlint should look like this: SCRIPT_INPUT_FILE_COUNT=2 SCRIPT_INPUT_FILE_0="Source/File1.swift" SCRIPT_INPUT_FILE_1="Source/File2.swift" swiftlint lint --quiet --use-script-input-files --force-exclude --reporter json

@absolute-heike absolute-heike changed the title Swiftlint should consider config excluded paths Swiftlint should consider excluded paths in config file Jan 30, 2019
@f-meloni
Copy link
Member

There are some tests that needs to be updated and maybe created (I would like to keep the swiftlint code well tested), but in general looks good 👍
This should also make it quite faster when you have Swiftlint on you Package.swift! 🎉

@absolute-heike
Copy link
Contributor Author

absolute-heike commented Jan 30, 2019

Yeah, I will fix the tests for Swiftlint 👍

Gonna be interesting, because the tests heavily rely on the command just being swiftlint (or the swiftlintPath). But I suffixed the command with the Environment variables 😬

I'm thinking of extending the ShellExecutor protocol to support environment variables, as this would ease up a lot of the issues that we have with the tests 😉

This should also make it quite faster when you have Swiftlint on you Package.swift! 🎉

You mean, because only one instance of Swiftlint is started, instead of one per file? 😄

@f-meloni
Copy link
Member

You mean, because only one instance of Swiftlint is started, instead of one per file? 😄

Yes :)

@f-meloni
Copy link
Member

f-meloni commented Jan 30, 2019

@absolute-heike if i understood your problem correctly I suppose you can use contains instead of == to find the command and then check that the final string is prefixed with the correct variables, something like

command == "SCRIPT_INPUT_FILE_COUNT=2 SCRIPT_INPUT_FILE_0=\"expectedFile0\" SCRIPT_INPUT_FILE_0=\"expectedFile1\" swiftlint"

@absolute-heike
Copy link
Contributor Author

absolute-heike commented Jan 30, 2019

Yes I could do that. Do you prefer this approach?

The change to ShellExecutor would look kinda like this:

func execute(_ command: String, arguments: [String] = [], environmentVariables: [String] = []) -> String {
        let script = [environmentVariables.joined(separator: " "),
                      command,
                      arguments.joined(separator: " ")].filter { !$0.isEmpty }.joined(separator: " ")

@f-meloni
Copy link
Member

Yep, cool :)

CHANGELOG.md Show resolved Hide resolved
@DangerCI
Copy link

DangerCI commented Feb 4, 2019

Warnings
⚠️

Sources/Danger-Swift/Fake.swift#L1 - Files should have a single trailing newline. (trailing_newline)

⚠️

Sources/Danger/Plugins/SwiftLint/ShellExecutor.swift#L3 - TODOs should be resolved (Get a logger into here this is...). (todo)

⚠️

Sources/Danger/Plugins/SwiftLint/ShellExecutor.swift#L65 - Line should be 120 characters or less: currently 128 characters (line_length)

⚠️

Sources/Danger/Plugins/SwiftLint/SwiftLint.swift#L33 - Function should have complexity 10 or less: currently complexity equals 11 (cyclomatic_complexity)

Generated by 🚫 dangerJS against fdf904f

Copy link
Member

@f-meloni f-meloni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment, but looks good 👍

@absolute-heike
Copy link
Contributor Author

absolute-heike commented Feb 4, 2019

Found a bug. When there is no file to lint (e.g. you didn't change a swift file), Swiftlint is still executed and prints No lintable files found at paths: '', hence danger-swift is failing cause it cannot parse this message as JSON.

  • do not execute swiftlint, if no files should be linted
  • test this behavior

@f-meloni
Copy link
Member

f-meloni commented Feb 4, 2019

I would suggest to not execute it in that case, we run on CI then we aim to be as fast as possible.
👍

Copy link
Member

@f-meloni f-meloni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removing the approval because of the bug :)

Copy link
Member

@f-meloni f-meloni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@f-meloni
Copy link
Member

f-meloni commented Feb 4, 2019

merge on green

@peril-staging peril-staging bot merged commit 1dba001 into master Feb 4, 2019
@absolute-heike absolute-heike deleted the fix_swiftlint_exludes branch February 4, 2019 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants