kandi background
Explore Kits

SwiftLint | A tool to enforce Swift style and conventions | iOS library

 by   realm Swift Version: 0.47.0 License: MIT

 by   realm Swift Version: 0.47.0 License: MIT

Download this library from

kandi X-RAY | SwiftLint Summary

SwiftLint is a Swift library typically used in Mobile, iOS, React Native, Xcode applications. SwiftLint has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.
SwiftLint is maintained and funded by Realm Inc. The names and logos for Realm are trademarks of Realm Inc. We :heart: open source software! See our other open source projects, read our blog, or say hi on twitter (@realm). Our thanks to MacStadium for providing a Mac Mini to run our performance tests.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • SwiftLint has a medium active ecosystem.
  • It has 15989 star(s) with 1910 fork(s). There are 249 watchers for this library.
  • There were 10 major release(s) in the last 12 months.
  • There are 272 open issues and 1747 have been closed. On average issues are closed in 218 days. There are 35 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of SwiftLint is 0.47.0
SwiftLint Support
Best in #iOS
Average in #iOS
SwiftLint Support
Best in #iOS
Average in #iOS

quality kandi Quality

  • SwiftLint has 0 bugs and 0 code smells.
SwiftLint Quality
Best in #iOS
Average in #iOS
SwiftLint Quality
Best in #iOS
Average in #iOS

securitySecurity

  • SwiftLint has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • SwiftLint code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
SwiftLint Security
Best in #iOS
Average in #iOS
SwiftLint Security
Best in #iOS
Average in #iOS

license License

  • SwiftLint is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
SwiftLint License
Best in #iOS
Average in #iOS
SwiftLint License
Best in #iOS
Average in #iOS

buildReuse

  • SwiftLint releases are available to install and integrate.
  • Installation instructions are not available. Examples and code snippets are available.
SwiftLint Reuse
Best in #iOS
Average in #iOS
SwiftLint Reuse
Best in #iOS
Average in #iOS
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

SwiftLint Key Features

A tool to enforce Swift style and conventions.

Using

copy iconCopydownload iconDownload
brew install swiftlint

Using

copy iconCopydownload iconDownload
pod 'SwiftLint'

Using

copy iconCopydownload iconDownload
$ mint install realm/SwiftLint

Xcode

copy iconCopydownload iconDownload
export PATH="$PATH:/opt/homebrew/bin"

if which swiftlint >/dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

fastlane

copy iconCopydownload iconDownload
swiftlint(
    mode: :lint,                            # SwiftLint mode: :lint (default) or :autocorrect
    executable: "Pods/SwiftLint/swiftlint", # The SwiftLint binary path (optional). Important if you've installed it via CocoaPods
    path: "/path/to/lint",                  # Specify path to lint (optional)
    output_file: "swiftlint.result.json",   # The path of the output file (optional)
    reporter: "json",                       # The custom reporter to use (optional)
    config_file: ".swiftlint-ci.yml",       # The path of the configuration file (optional)
    files: [                                # List of files to process (optional)
        "AppDelegate.swift",
        "path/to/project/Model.swift"
    ],
    ignore_exit_status: true,               # Allow fastlane to continue even if SwiftLint returns a non-zero exit status (Default: false)
    quiet: true,                            # Don't print status logs like 'Linting ' & 'Done linting' (Default: false)
    strict: true                            # Fail on warnings? (Default: false)
)

Docker

copy iconCopydownload iconDownload
docker pull ghcr.io/realm/swiftlint:latest

Command Line

copy iconCopydownload iconDownload
$ swiftlint help
OVERVIEW: A tool to enforce Swift style and conventions.

USAGE: swiftlint <subcommand>

OPTIONS:
  --version               Show the version.
  -h, --help              Show help information.

SUBCOMMANDS:
  analyze                 Run analysis rules
  docs                    Open SwiftLint documentation website in the default web browser
  generate-docs           Generates markdown documentation for all rules
  lint (default)          Print lint warnings and errors
  rules                   Display the list of rules and their identifiers
  version                 Display the current version of SwiftLint

  See 'swiftlint help <subcommand>' for detailed help.

Working With Multiple Swift Versions

copy iconCopydownload iconDownload
$ TOOLCHAINS=com.apple.dt.toolchain.Swift_2_3 swiftlint --fix

pre-commit

copy iconCopydownload iconDownload
repos:
  - repo: https://github.com/realm/SwiftLint
    rev: 0.44.0
    hooks:
      - id: swiftlint

Disable rules in code

copy iconCopydownload iconDownload
// swiftlint:disable colon
let noWarning :String = "" // No warning about colons immediately after variable names!
// swiftlint:enable colon
let hasWarning :String = "" // Warning generated about colons immediately after variable names

Configuration

copy iconCopydownload iconDownload
# By default, SwiftLint uses a set of sensible default rules you can adjust:
disabled_rules: # rule identifiers turned on by default to exclude from running
  - colon
  - comma
  - control_statement
opt_in_rules: # some rules are turned off by default, so you need to opt-in
  - empty_count # Find all the available rules by running: `swiftlint rules`

# Alternatively, specify all rules explicitly by uncommenting this option:
# only_rules: # delete `disabled_rules` & `opt_in_rules` if using this
#   - empty_parameters
#   - vertical_whitespace

included: # paths to include during linting. `--path` is ignored if present.
  - Source
excluded: # paths to ignore during linting. Takes precedence over `included`.
  - Carthage
  - Pods
  - Source/ExcludedFolder
  - Source/ExcludedFile.swift
  - Source/*/ExcludedFile.swift # Exclude files with a wildcard
analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
  - explicit_self

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
  severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 110
# they can set both implicitly with an array
type_body_length:
  - 300 # warning
  - 400 # error
# or they can set both explicitly
file_length:
  warning: 500
  error: 1200
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
  min_length: 4 # only warning
  max_length: # warning and error
    warning: 40
    error: 50
  excluded: iPhone # excluded via string
  allowed_symbols: ["_"] # these are allowed in type names
identifier_name:
  min_length: # only min_length
    error: 4 # only error
  excluded: # excluded via string array
    - id
    - URL
    - GlobalAPIKey
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, codeclimate, junit, html, emoji, sonarqube, markdown, github-actions-logging)

Using Multiple Configuration Files

copy iconCopydownload iconDownload
disabled_rules:
- force_cast

Child / Parent Configs (Locally)

copy iconCopydownload iconDownload
ProjectRoot
    |_ .swiftlint.yml
    |_ .swiftlint_refinement.yml
    |_ Base
        |_ .swiftlint_base.yml

Child / Parent Configs (Remote)

copy iconCopydownload iconDownload
parent_config: https://myteamserver.com/our-base-swiftlint-config.yml

Make Custom SwiftLint action regex ignore comments

copy iconCopydownload iconDownload
match_kinds: # SyntaxKinds to match. optional.
   - comment
   - identifier

SwiftLint configuration rule

copy iconCopydownload iconDownload
switch_case_alignment:  
  indented_cases: true

how to run SwiftLint on uncommitted files for m1

copy iconCopydownload iconDownload
SWIFT_LINT=/usr/local/bin/swiftlint
SWIFT_LINT=/opt/homebrew/bin/swiftlint
SWIFT_LINT=/usr/local/bin/swiftlint
SWIFT_LINT=/opt/homebrew/bin/swiftlint

How to disable default nil-initialization of Optional

copy iconCopydownload iconDownload
struct DataOne {
    let id: String
    var name: Optional<String>
    // ...
}

struct DataTwo {
    let id: String
    var name: Optional<String>
    // ...
}
struct DataOne {
    let id: String
    var name: String?

    init(id: String, name: String?) {
        self.id = id
        self.name = name
    }
}

struct DataTwo {
    let id: String
    var name: String?

    init(id: String, name: String?) {
        self.id = id
        self.name = name
    }
}
struct DataOne {
    let id: String
    var name: Optional<String>
    // ...
}

struct DataTwo {
    let id: String
    var name: Optional<String>
    // ...
}
struct DataOne {
    let id: String
    var name: String?

    init(id: String, name: String?) {
        self.id = id
        self.name = name
    }
}

struct DataTwo {
    let id: String
    var name: String?

    init(id: String, name: String?) {
        self.id = id
        self.name = name
    }
}

Using a closure vs a method within a view that takes in a closure

copy iconCopydownload iconDownload
   Button(action: {self.startTimer.toggle()}, label: {
           ...trailing closure
        })

I Can use a custom Swiftlint Instalation path on xcode?

copy iconCopydownload iconDownload
export PATH=${HOME}/.mint/bin:${PATH}
# Rest of script

SwiftLint Custom Spacing Rule After slass/struct/enum/extension

copy iconCopydownload iconDownload
(class|struct|enum|extension)((?-s)\s.*\{$\n)(?!^\s*$)

SwiftUI: stay on same TextField after on commit?

copy iconCopydownload iconDownload
struct ContentView: View {
    @State private var text = "Hello world!"
    @FocusState private var isFieldFocused: Bool

    var body: some View {
        Form {
            TextField("Field", text: $text, onCommit: {
                isFieldFocused = true
                print("onCommit")
            })
            .focused($isFieldFocused)
        }
    }
}
struct AlwaysActiveTextField: UIViewRepresentable {
    let placeholder: String
    @Binding var text: String
    var focusable: Binding<[Bool]>?
    var returnKeyType: UIReturnKeyType = .next
    var autocapitalizationType: UITextAutocapitalizationType = .none
    var keyboardType: UIKeyboardType = .default
    var isSecureTextEntry: Bool
    var tag: Int
    var onCommit: () -> Void

    func makeUIView(context: Context) -> UITextField {
        let activeTextField = UITextField(frame: .zero)
        activeTextField.delegate = context.coordinator
        activeTextField.placeholder = placeholder
        activeTextField.font = .systemFont(ofSize: 14)
        activeTextField.attributedPlaceholder = NSAttributedString(
            string: placeholder,
            attributes: [NSAttributedString.Key.foregroundColor: UIColor(contentSecondary)]
        )
        activeTextField.returnKeyType = returnKeyType
        activeTextField.autocapitalizationType = autocapitalizationType
        activeTextField.keyboardType = keyboardType
        activeTextField.isSecureTextEntry = isSecureTextEntry
        activeTextField.textAlignment = .left
        activeTextField.tag = tag
        // toolbar
        if keyboardType == .numberPad { // keyboard does not have next so add next button in the toolbar
            var items = [UIBarButtonItem]()
            let spacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

            let toolbar: UIToolbar = UIToolbar()
            toolbar.sizeToFit()
            let nextButton = UIBarButtonItem(title: "Next", style: .plain, target: context.coordinator, action: #selector(Coordinator.showNextTextField))
            items.append(contentsOf: [spacer, nextButton])
            toolbar.setItems(items, animated: false)
            activeTextField.inputAccessoryView = toolbar
        }
        // Editin listener
        activeTextField.addTarget(context.coordinator, action: #selector(Coordinator.textFieldDidChange(_:)), for: .editingChanged)

        return activeTextField
    }

    func updateUIView(_ uiView: UITextField, context: Context) {
        uiView.text = text

        if let focusable = focusable?.wrappedValue {
            if focusable[uiView.tag] { // set focused
                uiView.becomeFirstResponder()
            } else { // remove keyboard
                uiView.resignFirstResponder()
            }
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    final class Coordinator: NSObject, UITextFieldDelegate {
        let activeTextField: AlwaysActiveTextField
        var hasEndedViaReturn = false
        weak var textField: UITextField?

        init(_ activeTextField: AlwaysActiveTextField) {
            self.activeTextField = activeTextField
        }

        func textFieldDidBeginEditing(_ textField: UITextField) {
            self.textField = textField
            guard let textFieldCount = activeTextField.focusable?.wrappedValue.count else { return }
            var focusable: [Bool] = Array(repeating: false, count: textFieldCount) // remove focus from all text field
            focusable[textField.tag] = true // mark current textField focused
            activeTextField.focusable?.wrappedValue = focusable
        }
        // work around for number pad
        @objc
        func showNextTextField() {
            if let textField = self.textField {
                _ = textFieldShouldReturn(textField)
            }
        }

        func textFieldShouldReturn(_ textField: UITextField) -> Bool {
            hasEndedViaReturn = true
            guard var focusable = activeTextField.focusable?.wrappedValue else {
                textField.resignFirstResponder()
                return true
            }
            focusable[textField.tag] = true // mark current textField focused
            activeTextField.focusable?.wrappedValue = focusable
            activeTextField.onCommit()
            return true
        }

        func textFieldDidEndEditing(_ textField: UITextField) {
            if !hasEndedViaReturn {// user dismisses keyboard
                guard let textFieldCount = activeTextField.focusable?.wrappedValue.count else { return }
                // reset all text field, so that makeUIView cannot trigger keyboard
                activeTextField.focusable?.wrappedValue = Array(repeating: false, count: textFieldCount)
            } else {
                hasEndedViaReturn = false
            }
        }
        @objc
        func textFieldDidChange(_ textField: UITextField) {
            activeTextField.text = textField.text ?? ""
        }
    }
}
@State var fieldFocus: [Bool] = [false]
AlwaysActiveTextField(
                            placeholder: "Add...",
                            text: $newItemName,
                            focusable: $fieldFocus,
                            returnKeyType: .next,
                            isSecureTextEntry: false,
                            tag: 0,
                            onCommit: {
                                print("any action you want on commit")
                            }
                        )
struct AlwaysActiveTextField: UIViewRepresentable {
    let placeholder: String
    @Binding var text: String
    var focusable: Binding<[Bool]>?
    var returnKeyType: UIReturnKeyType = .next
    var autocapitalizationType: UITextAutocapitalizationType = .none
    var keyboardType: UIKeyboardType = .default
    var isSecureTextEntry: Bool
    var tag: Int
    var onCommit: () -> Void

    func makeUIView(context: Context) -> UITextField {
        let activeTextField = UITextField(frame: .zero)
        activeTextField.delegate = context.coordinator
        activeTextField.placeholder = placeholder
        activeTextField.font = .systemFont(ofSize: 14)
        activeTextField.attributedPlaceholder = NSAttributedString(
            string: placeholder,
            attributes: [NSAttributedString.Key.foregroundColor: UIColor(contentSecondary)]
        )
        activeTextField.returnKeyType = returnKeyType
        activeTextField.autocapitalizationType = autocapitalizationType
        activeTextField.keyboardType = keyboardType
        activeTextField.isSecureTextEntry = isSecureTextEntry
        activeTextField.textAlignment = .left
        activeTextField.tag = tag
        // toolbar
        if keyboardType == .numberPad { // keyboard does not have next so add next button in the toolbar
            var items = [UIBarButtonItem]()
            let spacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

            let toolbar: UIToolbar = UIToolbar()
            toolbar.sizeToFit()
            let nextButton = UIBarButtonItem(title: "Next", style: .plain, target: context.coordinator, action: #selector(Coordinator.showNextTextField))
            items.append(contentsOf: [spacer, nextButton])
            toolbar.setItems(items, animated: false)
            activeTextField.inputAccessoryView = toolbar
        }
        // Editin listener
        activeTextField.addTarget(context.coordinator, action: #selector(Coordinator.textFieldDidChange(_:)), for: .editingChanged)

        return activeTextField
    }

    func updateUIView(_ uiView: UITextField, context: Context) {
        uiView.text = text

        if let focusable = focusable?.wrappedValue {
            if focusable[uiView.tag] { // set focused
                uiView.becomeFirstResponder()
            } else { // remove keyboard
                uiView.resignFirstResponder()
            }
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    final class Coordinator: NSObject, UITextFieldDelegate {
        let activeTextField: AlwaysActiveTextField
        var hasEndedViaReturn = false
        weak var textField: UITextField?

        init(_ activeTextField: AlwaysActiveTextField) {
            self.activeTextField = activeTextField
        }

        func textFieldDidBeginEditing(_ textField: UITextField) {
            self.textField = textField
            guard let textFieldCount = activeTextField.focusable?.wrappedValue.count else { return }
            var focusable: [Bool] = Array(repeating: false, count: textFieldCount) // remove focus from all text field
            focusable[textField.tag] = true // mark current textField focused
            activeTextField.focusable?.wrappedValue = focusable
        }
        // work around for number pad
        @objc
        func showNextTextField() {
            if let textField = self.textField {
                _ = textFieldShouldReturn(textField)
            }
        }

        func textFieldShouldReturn(_ textField: UITextField) -> Bool {
            hasEndedViaReturn = true
            guard var focusable = activeTextField.focusable?.wrappedValue else {
                textField.resignFirstResponder()
                return true
            }
            focusable[textField.tag] = true // mark current textField focused
            activeTextField.focusable?.wrappedValue = focusable
            activeTextField.onCommit()
            return true
        }

        func textFieldDidEndEditing(_ textField: UITextField) {
            if !hasEndedViaReturn {// user dismisses keyboard
                guard let textFieldCount = activeTextField.focusable?.wrappedValue.count else { return }
                // reset all text field, so that makeUIView cannot trigger keyboard
                activeTextField.focusable?.wrappedValue = Array(repeating: false, count: textFieldCount)
            } else {
                hasEndedViaReturn = false
            }
        }
        @objc
        func textFieldDidChange(_ textField: UITextField) {
            activeTextField.text = textField.text ?? ""
        }
    }
}
@State var fieldFocus: [Bool] = [false]
AlwaysActiveTextField(
                            placeholder: "Add...",
                            text: $newItemName,
                            focusable: $fieldFocus,
                            returnKeyType: .next,
                            isSecureTextEntry: false,
                            tag: 0,
                            onCommit: {
                                print("any action you want on commit")
                            }
                        )
struct AlwaysActiveTextField: UIViewRepresentable {
    let placeholder: String
    @Binding var text: String
    var focusable: Binding<[Bool]>?
    var returnKeyType: UIReturnKeyType = .next
    var autocapitalizationType: UITextAutocapitalizationType = .none
    var keyboardType: UIKeyboardType = .default
    var isSecureTextEntry: Bool
    var tag: Int
    var onCommit: () -> Void

    func makeUIView(context: Context) -> UITextField {
        let activeTextField = UITextField(frame: .zero)
        activeTextField.delegate = context.coordinator
        activeTextField.placeholder = placeholder
        activeTextField.font = .systemFont(ofSize: 14)
        activeTextField.attributedPlaceholder = NSAttributedString(
            string: placeholder,
            attributes: [NSAttributedString.Key.foregroundColor: UIColor(contentSecondary)]
        )
        activeTextField.returnKeyType = returnKeyType
        activeTextField.autocapitalizationType = autocapitalizationType
        activeTextField.keyboardType = keyboardType
        activeTextField.isSecureTextEntry = isSecureTextEntry
        activeTextField.textAlignment = .left
        activeTextField.tag = tag
        // toolbar
        if keyboardType == .numberPad { // keyboard does not have next so add next button in the toolbar
            var items = [UIBarButtonItem]()
            let spacer = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

            let toolbar: UIToolbar = UIToolbar()
            toolbar.sizeToFit()
            let nextButton = UIBarButtonItem(title: "Next", style: .plain, target: context.coordinator, action: #selector(Coordinator.showNextTextField))
            items.append(contentsOf: [spacer, nextButton])
            toolbar.setItems(items, animated: false)
            activeTextField.inputAccessoryView = toolbar
        }
        // Editin listener
        activeTextField.addTarget(context.coordinator, action: #selector(Coordinator.textFieldDidChange(_:)), for: .editingChanged)

        return activeTextField
    }

    func updateUIView(_ uiView: UITextField, context: Context) {
        uiView.text = text

        if let focusable = focusable?.wrappedValue {
            if focusable[uiView.tag] { // set focused
                uiView.becomeFirstResponder()
            } else { // remove keyboard
                uiView.resignFirstResponder()
            }
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    final class Coordinator: NSObject, UITextFieldDelegate {
        let activeTextField: AlwaysActiveTextField
        var hasEndedViaReturn = false
        weak var textField: UITextField?

        init(_ activeTextField: AlwaysActiveTextField) {
            self.activeTextField = activeTextField
        }

        func textFieldDidBeginEditing(_ textField: UITextField) {
            self.textField = textField
            guard let textFieldCount = activeTextField.focusable?.wrappedValue.count else { return }
            var focusable: [Bool] = Array(repeating: false, count: textFieldCount) // remove focus from all text field
            focusable[textField.tag] = true // mark current textField focused
            activeTextField.focusable?.wrappedValue = focusable
        }
        // work around for number pad
        @objc
        func showNextTextField() {
            if let textField = self.textField {
                _ = textFieldShouldReturn(textField)
            }
        }

        func textFieldShouldReturn(_ textField: UITextField) -> Bool {
            hasEndedViaReturn = true
            guard var focusable = activeTextField.focusable?.wrappedValue else {
                textField.resignFirstResponder()
                return true
            }
            focusable[textField.tag] = true // mark current textField focused
            activeTextField.focusable?.wrappedValue = focusable
            activeTextField.onCommit()
            return true
        }

        func textFieldDidEndEditing(_ textField: UITextField) {
            if !hasEndedViaReturn {// user dismisses keyboard
                guard let textFieldCount = activeTextField.focusable?.wrappedValue.count else { return }
                // reset all text field, so that makeUIView cannot trigger keyboard
                activeTextField.focusable?.wrappedValue = Array(repeating: false, count: textFieldCount)
            } else {
                hasEndedViaReturn = false
            }
        }
        @objc
        func textFieldDidChange(_ textField: UITextField) {
            activeTextField.text = textField.text ?? ""
        }
    }
}
@State var fieldFocus: [Bool] = [false]
AlwaysActiveTextField(
                            placeholder: "Add...",
                            text: $newItemName,
                            focusable: $fieldFocus,
                            returnKeyType: .next,
                            isSecureTextEntry: false,
                            tag: 0,
                            onCommit: {
                                print("any action you want on commit")
                            }
                        )

How to get rid of &quot;[podname] not installed...&quot; warning?

copy iconCopydownload iconDownload
if which swiftlint >/dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

iOS SwiftLint Identifier Name doesn't work

copy iconCopydownload iconDownload
import UIKit

class TimeVC: UIViewController {

    @IBOutlet weak var timePicker: UIDatePicker!

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func clickDone(_ sender: Any) {
        dismiss(animated: true, completion: nil)
    }
}

Community Discussions

Trending Discussions on SwiftLint
  • Make Custom SwiftLint action regex ignore comments
  • SwiftLint configuration rule
  • Building Kotlin Multiplatform Mobile with fastlane failing on iOS
  • how to run SwiftLint on uncommitted files for m1
  • How to disable default nil-initialization of Optional
  • Using a closure vs a method within a view that takes in a closure
  • I Can use a custom Swiftlint Instalation path on xcode?
  • SwiftLint Custom Spacing Rule After slass/struct/enum/extension
  • SwiftUI: stay on same TextField after on commit?
  • How to get rid of &quot;[podname] not installed...&quot; warning?
Trending Discussions on SwiftLint

QUESTION

Make Custom SwiftLint action regex ignore comments

Asked 2022-Mar-11 at 18:50

I have a custom SwiftLint action to flag up print() statements:

custom_rules:
    disable_print:
      included: ".*\\.swift"
      name: "print usage"
      regex: "((\\bprint)|(Swift\\.print))\\s*\\("
      message: "Don't use print"
      severity: error

It works but it also flags whenever I have a print() statement specified in a documentation comment like this:

/// some comment mentioning print("hello") <- Error here
func myFunc() {}

How can I alter the regex so it ignores the print statement whenever it's in a documentation comment?

Thanks

ANSWER

Answered 2022-Mar-11 at 18:50

It seems that a custom rule can specify what type of code will match. The property is called match_kinds, example from Swiftlint Readme:

match_kinds: # SyntaxKinds to match. optional.
   - comment
   - identifier

Specifying identifier should be enough for your use case.

Source https://stackoverflow.com/questions/71442187

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install SwiftLint

You can download it from GitHub.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Consider Popular iOS Libraries
Try Top Libraries by realm
Compare iOS Libraries with Highest Support
Compare iOS Libraries with Highest Quality
Compare iOS Libraries with Highest Security
Compare iOS Libraries with Permissive License
Compare iOS Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.