Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swiftlint

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?

like image 533
Bhuvanendra Pratap Maurya Avatar asked Mar 30 '17 05:03

Bhuvanendra Pratap Maurya


People also ask

Where can I find Swiftlint Yml?

swiftlint. yml) and runs the tool. It is now located at the root of your project, in the same folder of your project configuration file (. xcodeproj), although it can be anywhere that you like.

Where do I put Swiftlint file?

swiftlint. yml file to your project directory. Note that this file should be added alongside your Xcode project and your Xcode workspace. It should not be placed inside of your project files directory.

How do I see Swiftlint rules?

Configuration file You can find all rules by running $ swiftlint rules . You have the possibility to control which rule is disabled/enabled and set thresholds for warnings and errors for a given rule.


3 Answers

If you are using the terminal:

    cd your_project_directory     touch .swiftlint.yml 
like image 194
Lehlohonolo_Isaac Avatar answered Oct 24 '22 06:10

Lehlohonolo_Isaac


I found this video helpful: https://www.youtube.com/watch?v=3MAlqOVIAwI

You can create a .swiftlint.yml in XCode and save it in your project directory. Just select File -> New -> File -> Empty

like image 31
Greg Robertson Avatar answered Oct 24 '22 07:10

Greg Robertson


Create this file in your project main directory and name should .swiftlint.yml

File example

disabled_rules: # rule identifiers to exclude from running
  - colon
  - comma
  - control_statement
  - identifier_name #rule for checking variable conditions (Upper case , lower case , underscore )
  - force_cast
  - shorthand_operator

cyclomatic_complexity:
  warning: 25 # two nested ifs are acceptable
  error: 50   # six nested ifs shows warning, 6 causes compile error


opt_in_rules: # some rules are only opt-in
  # - empty_count
  # Find all the available rules by running:
  # swiftlint rules

#included: # paths to include during linting. `--path` is ignored if present.
#  - Source

excluded: # paths to ignore during linting. Takes precedence over `included`.
  - Carthage
  - Pods
  - AppFolder\ App/Class/*
 # - AppFolder\ App/ViewController/* //Enabled for this

analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
  - explicit_self

# configurable rules can be customised 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: 200
# they can set both implicitly with an array

type_body_length:
  - 300 # warning
  - 600 # error
# or they can set both explicitly

file_length:
  warning: 500
  error: 2500

function_body_length:
  - 200 #warning
  - 300 #error

# 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

identifier_name:
#  allowed_symbols: "_"
  max_length:
    warning: 45
    error: 60
  min_length:
    warning: 1


reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
like image 29
Jogendra.Com Avatar answered Oct 24 '22 08:10

Jogendra.Com