Skip to content

Instantly share code, notes, and snippets.

@petergi
Last active December 27, 2023 19:57
Show Gist options
  • Select an option

  • Save petergi/436f2fa8fed35c743e2c51ef889fa254 to your computer and use it in GitHub Desktop.

Select an option

Save petergi/436f2fa8fed35c743e2c51ef889fa254 to your computer and use it in GitHub Desktop.

In the Shell

swiftlint autocorrect --config ".swiftlint.yml" --format 
swiftlint lint --config ".swiftlint.yml"

If your project has a lot of warnings, just run the following command to collect all rules:

swiftlint lint | grep -o '([A-Za-z].*)' | sed 's/[()]//g' | uniq -c

If you want to see only the list of rules run this command instead:

swiftlint lint | grep -o '([A-Za-z].*)' | sed 's/[()]//g' | uniq

In order to disable it you can use the following comment:

// swiftlint:disable rule_identifier

After this comment to the end of the file, all checking for that rule becomes disabled. if you want to disable the rule only in the next line of code use the below comment:

// swiftlint:disable:next rule_identifier

Likewise, you can disable the rule in the current line and previous line with swiftlint:disable:this and swiftlint:disable:previous respectively.

In XCode

Add a build phase (before compile phase) with the following:

if which swiftlint >/dev/null; then
  echo "Linting Code and Autocorrecting"
  swiftlint autocorrect --config "$SRCROOT/.swiftlint.yml" --format  
  swiftlint lint --config "$SRCROOT/.swiftlint.yml"   
  #exit 0
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment