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

Add SwiftLint and Swift Maker #2463

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Add SwiftLint and Swift Maker #2463

wants to merge 6 commits into from

Conversation

jandamm
Copy link
Contributor

@jandamm jandamm commented Feb 6, 2020

This Pull Request adds a new Maker for SwiftLint.
It also adds a Maker for compiling a swift script with swift (instead of swiftc).

SwiftLint will automatically be enabled when a .swiftlint.yml is found.

swiftfile won't be enabled per default. In my own vimrc I'll replace swiftc with it though.

Rationale:
Having a ~/.swiftlint.yml will enable SwiftLint but won't use this configuration but the default instead.
As this is also true for the existing swiftpm, I did ignore it.

Possible solutions:

  • Replace/restrict FindGlobFile with a function which only searches up until the project root.
  • Use the found .swiftlint.yml*

* This would result in having support for global a SwiftLint config. But as SwiftLint can merge multiple configurations this feature would be lost.

Copy link
Member

@blueyed blueyed left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I've left some comments.
I'm currently refactoring signs / types so that we can finally have type="style", which would make sense here.

I currently plan to have "S", "SE", and "SW" as new types (for internal lists, the qflist would get "S").
For current types "E" is the default, and here it would be "W", i.e. "S" == "SW".
See also #584.
What do you think?

autoload/neomake/makers/ft/swift.vim Outdated Show resolved Hide resolved
endfunction

function! s:get_swiftpm_config() abort
return neomake#utils#FindGlobFile('Package.swift')
endfunction

function! s:get_swiftlint_config() abort
return executable('swiftlint') && !empty(neomake#utils#FindGlobFile('.swiftlint.yml'))
endfunction
Copy link
Member

Choose a reason for hiding this comment

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

Isn't there also such a thing as a global config?

I think it makes sense to not require a local config for linters to be enabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SwiftLint officially does not support global configs. It does have a default configuration which I think many wouldn't want to be enabled for every file they open. E.g. it marks every variable shorter than two letters as an error.
The convention is having a config file in your project or provide it via an argument.

I think the best solution would be to search for a config file then run swiftlint, check for ~/.swiftlint.yml if it exists run swiftlintglobal (with config provided).

Copy link
Member

@blueyed blueyed Feb 7, 2020

Choose a reason for hiding this comment

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

But wouldn't people not liking swiftlint then just not install it?
I.e. if you have it it should be used - not only if you have some explicit config for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have it installed because some projects I work on use it, but others don't.
I cannot speak for everyone but I wouldn't want the default rules enabled and I'm not sure many are using a global config (there is a pretty old issue requesting this, though)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've had a look at swift.vim.
There swiftlint is also only enabled when a .swiftlint.yml is present or the user requests it.
https://github.com/keith/swift.vim/blob/master/syntax_checkers/swift/swiftlint.vim#L14

What is your opinion? I would leave the current implementation as is. The user can always opt in and run/enable swiftlint for himself.

autoload/neomake/makers/ft/swift.vim Show resolved Hide resolved
@jandamm
Copy link
Contributor Author

jandamm commented Feb 7, 2020

I think SW would match well.
If you're setting up SwiftLint in your IDE (which is recommended) an Error will fail your compilation, so I'm not sure it would be a Style Error.

When using the wrong swift toolchain an error without line or column can
occur:
/path: error: package at '/path' is using Swift tools version 5.2.0 but the installed version is 5.1.0
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

2 participants