Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ashfurrow/danger-swiftlint
Automated Swift linting on pull requests
https://github.com/ashfurrow/danger-swiftlint
danger-plugin danger-swift swiftlint
Last synced: 17 days ago
JSON representation
Automated Swift linting on pull requests
- Host: GitHub
- URL: https://github.com/ashfurrow/danger-swiftlint
- Owner: ashfurrow
- License: mit
- Created: 2017-12-09T15:59:09.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-04T15:30:29.000Z (almost 6 years ago)
- Last Synced: 2024-05-02T01:11:35.332Z (7 months ago)
- Topics: danger-plugin, danger-swift, swiftlint
- Language: Swift
- Homepage:
- Size: 74.2 KB
- Stars: 145
- Watchers: 7
- Forks: 15
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-danger - danger-swiftlint - Automated Swift linting on pull requests. (Plugins / Swift (danger-swift))
README
**Deprecation Notice**: This repo has been deprecated, since SwiftLint integration is now a part of [Danger Swift](https://github.com/danger/swift) as a first-class feature. You can read [this issue](https://github.com/ashfurrow/danger-swiftlint/issues/17) for context. This repo will remain available for legacy use, but **new projects should _not_ use this repo**.
---
[![CircleCI](https://circleci.com/gh/ashfurrow/danger-swiftlint.svg?style=svg)](https://circleci.com/gh/ashfurrow/danger-swiftlint)
# Danger SwiftLint
[Danger Swift](https://github.com/danger/danger-swift) plugin for [SwiftLint](https://github.com/realm/SwiftLint/). So you can get SwiftLint warnings on your pull requests!
(**Note**: If you're looking for the _Ruby_ version of this Danger plugin, it has been moved [here](https://github.com/ashfurrow/danger-ruby-swiftlint).)
## Usage
[Install and run](https://github.com/danger/danger-swift#ci-configuration) Danger Swift as normal and install SwiftLint in your CI's config file. Something like:
```yaml
dependencies:
override:
- npm install -g danger # This installs Danger
- brew install danger/tap/danger-swift # This installs Danger-Swift
- brew install swiftlint # This is for the Danger SwiftLint plugin.
```Then use the following `Dangerfile.swift`.
```swift
// Dangerfile.swiftimport Danger
import DangerSwiftLint // package: https://github.com/ashfurrow/danger-swiftlint.gitSwiftLint.lint()
```That will lint the created and modified files
#### Inline mode
If you want the lint result shows in diff instead of comment, you can use inline_mode option. Violations that out of the diff will show in danger's fail or warn section.
```swift
SwiftLint.lint(inline: true)
```#### Config & Directory
You can also specify a path to the config file using `configFile` parameter and a path to the directory you want to lint using `directory` parameter. This is helpful when you want to have different config files for different directories. E.g. Harvey wants to lint test files differently than the source files, thus they have the following setup:
```swift
SwiftLint.lint(directory: "Sources", configFile: ".swiftlint.yml")
SwiftLint.lint(directory: "Tests", configFile: "Tests/HarveyTests/.swiftlint.yml")
```### Lint all files
By default, only files that were added or modified are linted.
It's not possible to use [nested configurations](https://github.com/realm/SwiftLint#nested-configurations) in that case, because Danger SwiftLint lints each file on it's own, and by doing that the nested configuration is disabled. If you want to learn more details about this, read the whole issue [here](https://github.com/ashfurrow/danger-swiftlint/issues/4).
However, you can use the `lintAllFiles` option to lint all the files. In that case, Danger SwiftLint doesn't lint files individually, which makes nested configuration to work. It'd be the same as you were running `swiftlint` on the root folder:
```swift
SwiftLint.lint(lintAllFiles: true)
```### Custom SwiftLint binary path
By default, Danger SwiftLint runs `swiftlint` assuming it's installed globally. However, there're cases where it makes sense to use a different path. One example would be if you've installed SwiftLint using [CocoaPods](https://github.com/CocoaPods/CocoaPods).
To use another binary, you can use the `swiftlintPath` option:
```swift
SwiftLint.lint(swiftlintPath: "Pods/SwiftLint/swiftlint")
```# Contributing
If you find a bug, please [open an issue](https://github.com/ashfurrow/danger-swiftlint/issues/new)! Or a pull request :wink:
No, seriously.
This is the first command line Swift I've ever written, and it's the first Danger Swift plugin _anyone_ has ever written, so if something doesn't work, I could really use your help figuring out the problem.
A good place to start is writing a failing unit test. Then you can try to fix the bug. First, you'll need to fork the repo and clone your fork locally. Build it and run the unit tests.
```sh
git clone https://github.com/YOUR_USERNAME/danger-swiftlint.git
cd danger-swiftlint
swift build
swift test
```Alright, verify that everything so far works before going further. To write your tests and modify the plugin files, run `swift package generate-xcodeproj`. Open the generated Xcode project and enjoy the modernities of code autocomplete and inline documentation. You can even run the unit tests from Xcode (sometimes results are inconsistent with running `swift test`).
One place that unit tests have a hard time covering is the integration with the `swiftlint` command line tool. If you're changing code there, open a pull request ([like this one](https://github.com/Moya/Harvey/pull/15)) to test everything works.
# Customizing
There are tonnes of ways this plugin can be customized for individual use cases. After building [the Ruby version](https://github.com/ashfurrow/danger-ruby-swiftlint) of this plugin, I realized that it's really difficult to scale up a tool that works for everyone. So instead, I'm treating this project as a template, that you to do fork and customize however you like!
1. [Fork](https://github.com/ashfurrow/danger-swiftlint#fork-destination-box) this project.
1. Change the `import DangerSwiftLint` package URL to point to your fork.
1. After making your changes to the plugin, push them to your fork and **push a new tag**.Because you need to tag a new version, testing your plugin can be tricky. I've built some basic unit tests, so you should be able to use test-driven development for most of your changes.
If you think you've got a real general-purpose feature that most users of this plugin would benefit from, I would be grateful for a pull request.
# License
[#MIT4Lyfe](LICENSE)
# A Fun GIF
Your feeling when you lint your swift code