0

We are following the instruction from https://github.com/realm/SwiftLint.

  1. In terminal CD->PROJECT DIRECTORY
  2. touch .swiftlint.yml
  3. open .swiftlint.yml

and added following rules

# 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
  – compiler_protocol_init
  – cyclomatic_complexity
  – file_length
  – force_cast
  – function_body_length
  – function_parameter_count
  – identifier_name
  – multiple_closures_with_trailing_closure
  – notification_center_detachment
  – line_length
  – trailing_whitespace
  – type_body_length
  – type_name
  – todo
  - shorthand_operator
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.
  - Kuwy
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: 500
# 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)

In BuildPhase added the following script

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

and tried following script also

"${PODS_ROOT}/SwiftLint/swiftlint"

But still I am getting errors, and Pods directory not excluded. Somebody please help on this.

Please find the SSError Image

Is there any other configuration missing?

I have installed SwiftLint by following ways

Using Homebrew:

brew install swiftlint

Using CocoaPods: Simply add the following line to your Podfile:

pod 'SwiftLint'
karthikeyan
  • 3,821
  • 3
  • 22
  • 45

1 Answers1

0

I believe its better way to install lint package in system instead installing pods

1.This repo has SwiftLint.pkg. download and install it in your system https://github.com/realm/SwiftLint/releases

  1. Hit brew install swiftlint

3.Add below Run Script phase in Xcode.

if which swiftlint >/dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
  1. Build & Run the project and you are good to go. Don't forget to add .swiftlint.yml in your project

I have used exclude/disabled_rules as below for reference which is working

excluded:
  - Pods
  - ./*/*Core
  - ./*/*GraphQL
  - ./*GraphQlConfig

disabled_rules: # rule identifiers to exclude from running
  - colon
  - comma
  - control_statement