Questions tagged [swiftlint]

A tool to enforce Swift style and conventions, loosely based on GitHub's Swift Style Guide. SwiftLint hooks into Clang and SourceKit to use the AST representation of your source files for more accurate results.

A tool to enforce Swift style and conventions, loosely based on GitHub's Swift Style Guide. SwiftLint hooks into Clang and SourceKit to use the AST representation of your source files for more accurate results.

The tool verifies that your Swift code conforms to a set of rules syntactic rules defined by you and your teammates.

More details at SwiftLint Github.

185 questions
64
votes
7 answers

SwiftLint: Exclude file for specific rule

I'm trying to do something like this in my .swiftlint.yml file: force_cast: severity: warning # explicitly excluded: - Dog.swift I have this code and I don't like the force_try warning I'm getting for it: let cell =…
etayluz
  • 15,920
  • 23
  • 106
  • 151
57
votes
20 answers

"${PODS_ROOT}/SwiftLint/swiftlint" causes "Command PhaseScriptExecution failed with a nonzero exit code" with Xcode 10

Updating from Xcode 10.0 beta 2 to Xcode 10.0 beta 3 I now get this error at build time for an iOS project: sourcekit: [1:connection-event-handler:10499: 0.0000] Connection interruptsourcekit: [1:updateSemanticEditorDelay:10499: 0.0007] disabling…
Cœur
  • 37,241
  • 25
  • 195
  • 267
52
votes
2 answers

Swiftlint warning : For Where Violation: `where` clauses are preferred over a single `if` inside a `for`. (for_where)

I am using swift for my application development and using Swift lint. But I am getting a warning regarding the following code: for settingsKeys in searchResults { if settingsKeys.key == settingsObject.key { settingsKeys.value =…
Chelsea Shawra
  • 1,593
  • 4
  • 22
  • 43
44
votes
3 answers

Swiftlint can't be found on Apple Silicon xcode

When installing swiftlint with homebrew everything installs correctly but when I open xcode I see the message that swiftlint isn't installed. I read this issue & it say's the homebrew installs under this path now /opt/homebrew with apple silicon &…
user
  • 345
  • 2
  • 8
  • 32
43
votes
5 answers

How do I create .swiftlint.yml file & where I need to put it?

I want to use Swiftlint in my Swift project. I followed the Realm instruction and installed Swiftlint by brew install swiftlint. Further I face the problem to create .swiftlint.yml file. So please suggest me how I proceed?
36
votes
5 answers

Cyclomatic Complexity Violation: Function should have complexity 10 or less: currently complexity equals 13 (cyclomatic_complexity)

I have the following code in swift3 and i am using swift lint for linting the code. The code is given as follows: func selectedMenuInLoggedOutState(sender: UIButton) { switch sender.tag { case 1: if let menu =…
Chelsea Shawra
  • 1,593
  • 4
  • 22
  • 43
31
votes
5 answers

How to fix "Trailing Whitespace Violation" warnings caused by swiftlint in Xcode?

How can we fix the "Trailing Whitespace Violation" warnings caused by swiftlint in my iOS project all in one go? I don't want to manually correct each one of them. Moreover, I don't want to disable these warnings so you can skip that suggestion. I…
Malika Arora
  • 439
  • 1
  • 4
  • 6
30
votes
2 answers

Difference between NSRange and NSMakeRange

Is there any difference between: NSRange(location: 0, length: 5) and: NSMakeRange(0, 5) Because Swiftlint throws a warning when I use NSMakeRange, but I don't know why. Thanks for the Help :-)
Auryn
  • 1,117
  • 1
  • 13
  • 37
27
votes
3 answers

Simple way to run SwiftLint for our Swift package

So far what I found is this blog article: It's time to use Swift Package Manager which recommends integrate SwiftLint and other tools with Package.swift. I was able to add dependency to the package file, build and test successfully but SwiftLint…
Boris Y.
  • 4,387
  • 2
  • 32
  • 50
25
votes
4 answers

How to integrate SwiftLint with an iOS app using Swift Package Manager?

I'm creating a new iOS app using Xcode 11 (beta 5), and I'd like to use Swift Package Manager instead of CocoaPods for managing dependencies. A common pattern when using SwiftLint and CocoaPods is to add SwiftLint as a dependency and then add a…
jjoelson
  • 5,771
  • 5
  • 31
  • 51
18
votes
1 answer

lint Legacy Constructor Violation: (legacy_constructor) NSMakeRange in Swift?

What is the Swift constructor for the code below? NSMakeRange(0, textfield.text!.characters.count)
Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
17
votes
6 answers

How to install a specific version of swiftlint?

I am trying to fix this error: Error: swiftlint does not have a version "0.11.1" in the Cellar. by running this: brew install swiftlint-0.11.1 however this doesn't work, then I tried "brew search swiftlint", but nothing showed up. Can anyone point…
RainCast
  • 4,134
  • 7
  • 33
  • 47
17
votes
2 answers

Remove SwiftLint installed from package

I installed SwiftLint from official packages. Now, I desire remove completely and install from Homebrew. I did not find official documentation about uninstall SwiftLint. Any suggestions?
16
votes
4 answers

Disable some SwiftLint rules for test target/unit tests files

I am looking to disable a couple of SwiftLint rules for the unit tests within my application. For example I am wanting to disable the weak_delegate rule for my unit tests. Having looked at the SwiftLint docs I think it may be possible by defining a…
bencallis
  • 3,478
  • 4
  • 32
  • 58
16
votes
3 answers

How to fix 'Line Length Violation: Line should be 120 characters or less' - SwiftLint

How to fix Line Length Violation? Relevant part of alert message that isn't allowed due to Line Length Violation: message: NSLocalizedString("\nYou will be requested to Use %@ to Sign In. %@ doesn't share any information about you. The permission…
Yatko
  • 8,715
  • 9
  • 40
  • 46
1
2 3
12 13