Coder Social home page Coder Social logo

danger-swiftlint's Introduction

Deprecation Notice: This repo has been deprecated, since SwiftLint integration is now a part of Danger Swift as a first-class feature. You can read this issue for context. This repo will remain available for legacy use, but new projects should not use this repo.


CircleCI

Danger SwiftLint

Danger Swift plugin for 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.)

Usage

Install and run Danger Swift as normal and install SwiftLint in your CI's config file. Something like:

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.

// Dangerfile.swift

import Danger
import DangerSwiftLint // package: https://github.com/ashfurrow/danger-swiftlint.git

SwiftLint.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.

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:

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 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.

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:

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.

To use another binary, you can use the swiftlintPath option:

SwiftLint.lint(swiftlintPath: "Pods/SwiftLint/swiftlint")

Contributing

If you find a bug, please open an issue! Or a pull request 😉

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.

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) to test everything works.

Customizing

There are tonnes of ways this plugin can be customized for individual use cases. After building the Ruby version 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 this project.
  2. Change the import DangerSwiftLint package URL to point to your fork.
  3. 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

A Fun GIF

Your feeling when you lint your swift code

danger-swiftlint's People

Contributors

ashfurrow avatar killectro avatar orta avatar sunshinejr avatar thii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

danger-swiftlint's Issues

Merging all linters into one.

Hey Ash!

So I've been finishing my danger-xiblint plugin and I found myself copying most of your infrastructure. Then I thought that maybe we could create a general plugin for linters, because they share a big amount of code.

Pros:

  • all in one - I could use all linters I want without searching and installing for another library
  • API consistency across linters
  • when new version of Danger/Swift comes, only one package would need to be updated
  • easier for adding additional linters for Danger Swift infra

Cons:

  • not sure if it's scalable
  • we would need some people to help if there'll be more interest for this one
  • architecting the general plugin to make it easy to both maintain & add new linters

I'd be eager to hear your opinion, because I'm still debating if it's the right choice myself! 😅

Source files that have been moved throw "error opening input file '/path/to/file' (No such file or directory)"

Hey 👋

I've noticed that files that have been moved throw "No such file or directory" because this plugin attempts to read the file in its old location.

The errors thrown look like this:

error opening input file '/Users/rogerluan/Documents/Projects/redacted/redacted/SampleFile1.swift' (No such file or directory)
SourceKittenFramework/File.swift:28: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file “SampleFile1.swift” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/rogerluan/Documents/Projects/redacted/redacted/SampleFile1.swift, NSUnderlyingError=0x7f858bc8d420 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Not sure if this should be reported in Danger itself, or in this plugin, because I know for a fact that Danger itself report the moved files in a misleading way (IMO). We had to implement this workaround for other Dangerfiles in our project:

files_of_interest = git.added_files + git.modified_files
renamed_files = git.renamed_files
added_or_modified_files = files_of_interest.map do |file|
    renamed_dict = renamed_files.find { |dict| dict[:before] == file }
    if renamed_dict
        renamed_dict[:after]
    else
        file
    end
end

And whenever we want "added or modified files", we need to use added_or_modified_files instead of files_of_interest (in the example above).

How can we improve this behavior? Right now this plugin simply crashes when facing those errors 😬

Add documentation/examples for new SwiftLint.lint() parameters.

We've added 2 new parameters to SwiftLint.lint():

  • directory - files only in this directory will be linted
  • configFile - path to .swiftlint.yml to use for linting

We need to add documentation/examples to our Readme.md (probably Usage paragraph).

You can find more about the usage for these parameters in this comment.

Is it possible to use this plugin from DangerJS?

We are using DangerJS at the moment where we share common rules for different repositories. I'm looking to integrate SwiftLint into an iOS repository which is already integrated with DangerJS.

Is it possible to use this plugin from JS?

Thanks!

Proposal: Merge into Danger Swift

This is likely to be one of the main reasons people use Danger Swift, I think it makes sense to probably just include in in core to save on some of the expense of Danger plugins ( e.g. #14 ). While I think this can be fixed, I'm not sure if it can be done in an elegant way (danger swift has to be compiled twice if you're not using a package.swift for example )

This related to the discussion in danger/swift#139

Plugin doesn't respect per-directory configs (nested configuration).

👋 (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!

Stalling out on CI with Xcode 10

After updating our app to Xcode 10 and Swift 4.2, danger-swiftlint stalls out on CircleCI. After linting some of our files, it eventually stops printing to STDOUT, and after 10 minutes of inactivity, CircleCI terminates it.

This behavior did not occur with Xcode 9 and Swift 4.1.

This is the relevant portion of our Dangerfile.swift:

import Danger
import DangerSwiftLint // package: https://github.com/ashfurrow/danger-swiftlint.git

SwiftLint.lint(inline: true, directory: "Clutter/Application”)

This is the (abridged) log from CircleCI:

#!/bin/bash --login -o pipefail
danger process danger-swift
Ran with: Dangerfile.swift /var/folders/gk/lkr9pm5x039fx6d3j9r52rv80000gn/T/danger-dsl.json /var/folders/gk/lkr9pm5x039fx6d3j9r52rv80000gn/T/danger-response.json
Executing pwd 
Working directory: /Users/distiller/project

Executing swiftlint lint --quiet --path "Clutter/Application/API/ClutterAPI.swift" --reporter json
<189 lines omitted>
Executing swiftlint lint --quiet --path "Clutter/Application/Protocols/TableViewController.swift" --reporter json
Executing swiftlint lint --quiet --path "Clutter/Application/StyleKits/ClutterStyleKit.swift" 
Too long with no output (exceeded 10m0s)

I notice that the final swiftlint lint line doesn’t end with -- reporter json. Additionally, ClutterStyleKit.swift is a 3005-line, PaintCode-generated file. Not sure if either of those is relevant.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.