realm / SwiftLint

A tool to enforce Swift style and conventions.
https://realm.github.io/SwiftLint
MIT License
18.59k stars 2.22k forks source link

SwiftLint fails on circleCI and passes locally because of force casting #2087

Closed Vadimkomis closed 6 years ago

Vadimkomis commented 6 years ago

New Issue Checklist

Bug Report

When I enable force casting as a rule in my linter it makes my build to fail on circleci. I installed the swiftlinter via cocoa pods. It keeps complaining about force casting as you can see below. I think it has something to do with the run script that for swxftlint.

Complete output when running SwiftLint, including the stack trace and command used
Testing failed:
    Force Cast Violation: Force casts should be avoided. (force_cast)
    Force Cast Violation: Force casts should be avoided. (force_cast)
    Force Cast Violation: Force casts should be avoided. (force_cast)
** TEST FAILED **

The following build commands failed:
    PhaseScriptExecution Run\ Script /Users/distiller/Library/Developer/Xcode/DerivedData/Freshly-aqfftomwdlyzfadmktypldmeqhgq/Build/Intermediates.noindex/Freshly.build/Debug-iphonesimulator/Freshly\ Dev.build/Script-DDBA23CD2021057C00E0D5AE.sh
(1 failure)
$ swiftlint lint

Environment

excluded: # paths to ignore during linting. Takes precedence over included.

opt_in_rules: # some rules are only opt-in

disabled_rules: # rule identifiers to exclude from running

line_length: 270

type_name: min_length: 2


* Are you using [nested configurations](https://github.com/realm/SwiftLint#nested-configurations)?
  If so, paste their relative paths and respective contents.
* Which Xcode version are you using (check `xcode-select -p`)?
* Do you have a sample that shows the issue? Run `echo "[string here]" | swiftlint lint --no-cache --use-stdin --enable-all-rules`
  to quickly test if your example is really demonstrating the issue. If your example is more
  complex, you can use `swiftlint lint --path [file here] --no-cache --enable-all-rules`.

```swift
// This triggers a violation:
let foo = try! bar()
marcelofabri commented 6 years ago

Did you add a script to run SwiftLint in your build phases? How's that script?

Vadimkomis commented 6 years ago

@marcelofabri I did add that. Here's the script that I added: "${PODS_ROOT}/SwiftLint/swiftlint"

Vadimkomis commented 6 years ago

@marcelofabri are you sure that it's not a bug ?

marcelofabri commented 6 years ago

This looks like a configuration issue. I suggest you to add the full log from Circle CI so we can understand what's happening.

I also would try to run exactly what Circle runs but locally.

Vadimkomis commented 6 years ago

@marcelofabri Running the script that Circle locally, works just fine. Here's the log that I keep (running with cache and without cache) getting:

▸ Compiling ChooseMeals.storyboard ▸ Compiling Main.storyboard ▸ Compiling Web.storyboard ▸ Compiling CalendarModule.storyboard ▸ Compiling Upcoming.storyboard ▸ Compiling MealPlanner.storyboard ▸ Compiling AppStatus.storyboard ▸ Compiling Forms.storyboard ▸ Processing Freshly Dev-Info.plist ▸ Generating 'Freshly\ Dev.app.dSYM' ▸ Running script 'Run Script' ▸ Running script '[CP] Embed Pods Frameworks' ▸ Running script '[CP] Copy Pods Resources' ▸ Running script 'Run Script' ▸ Running script 'Run Script'

⚠️ /Users/distiller/freshly_ios/Freshly/Controllers/choose-meals/ChooseMealsConfigCell.swift:41:13: Statement Position Violation: Else and catch should be on the same line, one space after the previous declaration. (statement_position)

Linting 'HomeController.swift' (12/264) ^

BUILD FAILED

The following build commands failed: PhaseScriptExecution Run\ Script /Users/distiller/Library/Developer/Xcode/DerivedData/Freshly-aqfftomwdlyzfadmktypldmeqhgq/Build/Intermediates.noindex/Freshly.build/Debug-iphonesimulator/Freshly\ Dev.build/Script-DD8F23DD204E04A700609DF3.sh (1 failure) 2018-03-20 06:36:01.810 xcodebuild[1153:7411] [MT] IDETestOperationsObserverDebug: (C7475127-42C8-4321-AB5C-12500CAA18BF) Beginning test session FreshlyUITests-C7475127-42C8-4321-AB5C-12500CAA18BF at 2018-03-20 06:36:01.810 with Xcode 9C40b on target <DVTiPhoneSimulator: 0x7fca8ecc19e0> { SimDevice: iPhone 6s (D2CE8B34-2AE7-45E4-8BCF-54F4D60212D6, iOS 10.3, Booted) } (10.3.1 (14E8301)) 2018-03-20 06:36:01.817 xcodebuild[1153:7411] [MT] IDETestOperationsObserverDebug: (612A415F-458E-4ADB-9394-0C584ED3F6F4) Beginning test session FreshlyTests-612A415F-458E-4ADB-9394-0C584ED3F6F4 at 2018-03-20 06:36:01.817 with Xcode 9C40b on target <DVTiPhoneSimulator: 0x7fca8ecc19e0> { SimDevice: iPhone 6s (D2CE8B34-2AE7-45E4-8BCF-54F4D60212D6, iOS 10.3, Booted)

Vadimkomis commented 6 years ago

Yes. It was a Circle issue. As soon as I updated to Circle 2.0 it resolved this issue.

rgkobashi commented 4 years ago

I started having the same problem, it happened on Circle 2.0 and 2.1. How I solved it was by explicitly adding included the list of folders I want to scan.

In my project they are only 2 (main app and tests) so no big deal, but still I think this is a bug.

If need any more info feel free to ask :)

ethanroam commented 4 years ago

We're also still experiencing this issue on 2.0, fixed by explicitly adding included as mentioned above.

romansorochak commented 3 years ago

I started having the same problem, it happened on Circle 2.0 and 2.1. How I solved it was by explicitly adding included the list of folders I want to scan.

In my project they are only 2 (main app and tests) so no big deal, but still I think this is a bug.

If need any more info feel free to ask :)

Thanks ! Had the same issue with GitHub Actions. Fixed by using included field.