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

Ability to add SwiftLint Preemptively before .Swift files have been added #2608

Closed
2 tasks done
christoff-1992 opened this issue Jan 28, 2019 · 10 comments
Closed
2 tasks done
Labels
enhancement Ideas for improvements of existing features and rules.

Comments

@christoff-1992
Copy link

christoff-1992 commented Jan 28, 2019

New Issue Checklist

Describe the bug

If no .Swift files have been added to the directory then the build will fail with 'No lintable files found at paths'.

This is the correct behaviour currently but it would be nice to add the configuration to a lib/framework before any swift files have been added to the project.

At the moment I am looking at creating a shared framework that builds across iOS, OSX and TVOS. The workspace will use a shared structure for the source files and tests but I would also like to prepare the individual targets for each iOS, OSX and TVOS for SwiftLint without the build failing.

I can edit the run script to check for this manually but wondered if there is a better way around this.

swiftFileCount=`ls -1 *.swift 2>/dev/null | wc -l`
if [ $swiftFileCount != 0 ]
then
    ${PODS_ROOT}/SwiftLint/swiftlint
else
    echo "No lintable files to check, skipping Swiftlint"
fi
@marcelofabri
Copy link
Collaborator

You could add just a dummy Swift file too.

Another option would be adding a new option to swiftlint lint and swiftlint autocorrect. This seems a good candidate for a first contribution!

@marcelofabri marcelofabri added the enhancement Ideas for improvements of existing features and rules. label Jan 29, 2019
@jpsim
Copy link
Collaborator

jpsim commented Jan 29, 2019

I'd rather not add this configurability to the CLI flags. My philosophy on SwiftLint is that a properly configured project with no violations should pass just by running swiftlint.

Perhaps a configuration file key would be more appropriate? allow_zero_lintable_files: true

@christoff-1992
Copy link
Author

@jpsim - I like that approach, as you mention a correctly configured project with no violations should pass just by running swiftlint.

@jpsim
Copy link
Collaborator

jpsim commented Jan 31, 2019

I think there's a broader choice to discuss which is wether or not we should treat linting no Swift files as an error or not. See #2619 where this is also being discussed but for other reasons. /cc @fabb

The argument for exiting with an error code is that if you're expecting to lint a bunch of files and SwiftLint is misconfigured, it's a bit misleading to say "all good". Open to discussing this though since I think the points here and in #2619 are valid.

@fabb
Copy link
Contributor

fabb commented Feb 1, 2019

I would be happy if there just was a separate exit code for the „no files“ case.

@christoff-1992
Copy link
Author

A specific config entry for allow_zero_lintable_files: true would be a conscious decision by the user implementing the config. You could always provide an exit code with a message of Lintable files found at paths: '', when zero lintable files are expected by the current configuration as an additional safety check to ensure that Swiftlint has not been misconfigured.

@thedavidharris
Copy link
Contributor

This is popping up as an issue when using a CI check like Danger, where editing only files that are covered by the ignore triggers a failure (danger/swift#231).

allow_zero_lintable_files: true would make sense to me.

@thedavidharris
Copy link
Contributor

I created a draft PR at #2732 to see if it's satisfactory to get around this

@teameh
Copy link
Contributor

teameh commented May 8, 2019

Same problem here. I'm running swiftlint autocorrect and swiftlint lint on each xcode build with only the changed files as input files with --use-script-input-files and --force-exclude, but all are filtered away. It would be great to be able to add allow_zero_lintable_files: true and get an exit code that XCode would not see as a failure. 👍

@marcelofabri
Copy link
Collaborator

Implemented in #2732

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Ideas for improvements of existing features and rules.
Projects
None yet
Development

No branches or pull requests

6 participants