Skip to main content

[iOS] SwiftLint - Linter for Swift

What and Why SwiftLint???

Linter is a specialized tool that analyses our source code and helps us to find errors, bug and indentation issues. As the name suggests SwiftLint helps us to enforce the coding styles on the swift code and makes us follow its rules and conventions. SwiftLint is an open source project and is maintained by Realm team. There are many rules which are defined in SwiftLint. These rules are applied to our code. If any of the compulsory rules are broken SwiftLint will either generate a warning(if not critical) or build will fail(in case of critical). This way developer has to strictly follow the rules before making any pull request and code being merged to the main codebase. This will help us in many ways. In a codebase where many developers are working from junior to senior level, there will be uniformity in writing the code and style. So codebase will be consistent and uniformed throughout. Also, the codebase will be easy to maintain and debug. The more maintainable the code more the scalability.

Setting up...

The first step we will look into how to setup SwiftLint locally on the machine. Since we will be using Brew to install SwiftLint on our machine. The Brew is a must before starting the process. In case Brew is not installed, take a look at the installation process here.
Once brew setup is done, open terminal and type,
brew help
If the brew is installed successfully, you will get an output. If not, command not found error will get displayed on the terminal.

Next step is to install SwiftLint on our machine.
brew install swiftlint

After installation, the next step is to link it to our Xcode project Open Xcode, go to build phases and add new “Run Script Phase” and paste below code there
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

Configuration...

Once SwiftLint is set up, in order to work we need to add configurations. We can configure by adding .swiftlint.yml to the root folder of our project directory.

To create 
".swiftlint.yml" -> Go to Project directory -> Open terminal -> "touch .swiftlint.yml"

Once the file is created we can configure the following parameters
- disabled_rules: Disable the default enabled rules from the SwiftLint
- opt_in_rules: Opt-in rules which are not set by default
- whitelist_rules: Only the rules specified in this list will be enabled. This will not work alongside opt_in_rules & disabled_rules
- analyser_rules: This is an entirely separate list of rules that are only run by the analyse command


This completes setting up of SwiftLint, Please feel free to comment or ask any questions if there are any queries. 


Comments

Popular posts from this blog

[Roku Development] Debugging Roku Code - Visual Studio Code

For ease of debug instead of terminal we will use Visual Studio Code for Roku Channel development. Visual Studio Code download link is mentioned below https://code.visualstudio.com Once IDE is downloaded, we need to install extenstion for Roku Development available in VSC known as " BrightScript Language" Step 1: Install BrightScript Language Extension Once package is installed, open the project which you need to work upon Step 2: Open Roku Channel Project After opening the project goto Run and Debug option, since this is the first time we are opening this project we need to setup the environment. In this case we need to click on create a launch.json file Step 3: Setup launch.json file Once we click on create launch.json file, it will ask for which environment we want to setup the Run and Debug option. Here we need to choose BrightScript Debug option .  Note that, BrightScript Debug option will be available under only if BrightScript Language extension is installed Step 4: En

[iOS] Updating iOS 16 Beta

Apple has recently announced iOS 16 in WWDC - 2022. Currently Beta versions are made available to the public for download. Most of us must be curious to get this version on their personal devices.  Previously downloading beta versions on personal devices was hectic process and requires lots of efforts to upgrade devices to latest beta versions. Now Apple has came up to update iOS devices with very simple process. With this Apple is trying to get the first hand reviews from the users before actually releasing the iOS version in the market. 1. To get the latest version of beta for iOS/iPadOS, please register yourself at the below mentioned portal with the help of Apple ID -  https://beta.apple.com/sp/betaprogram/  2. After registering login to the beta program portal and navigate to "Enroll Your Devices"  3. Download profile  4. Install the downloaded profile 5. Once profile is installed successfully, goto Settings -> General -> Software update. There you will find the be