[AMSDK-9723] [Tools] Setup SwiftLint #50
Conversation
New Makefile target 'setup-lint-tool' will install SwiftLint and a Git pre-commit hook. SwiftLint is installed via Homebrew. The Git hook is stored under 'hooks/pre-commit' and is copied to '.git/hooks/pre-commit'.
…se to lint source files.
…rce_try' to warnings
Add 'lenient' flag to unit test and functional test lint runs to treat all errors as warnings.
…it to autocorrect all files.
…t-files flag to autocorrect only the files in Git's stage area.
Makefile
Outdated
There was a problem hiding this comment.
Should we rename this to setup tools to fit more tools in the future and maybe include it in make setup?
There was a problem hiding this comment.
I was thinking the same, however the tools setup can take several seconds as it runs Homebrew. I would prefer to use this make setup target in CI and as a documented way to setup the project once first cloned. If, when changing branches and wanting to correct the installed Pods, then make pod-install should be used. Thoughts?
There was a problem hiding this comment.
I guess it's fine to not include it in make setup, you only need to run it once. I will keep my comment for renaming to make setup-tools
tools/format/.swiftlint.yml
Outdated
There was a problem hiding this comment.
We might need to reduce these a bit. hope we don't have many functions with 300+ lines
There was a problem hiding this comment.
Interesting read, seems like protocol ClassName: AnyObject is preferred though and class is deprecated without a warning https://forums.swift.org/t/class-only-protocols-class-vs-anyobject/11507
tools/git-hooks/pre-commit
Outdated
There was a problem hiding this comment.
Thanks for this, I feel less stressed about formatting the lines manually 😄
Description
Setup SwiftLint for project. NOTE: Does not include CircleCI changes which will be included in another PR.
Part of this checkin are SwiftLint autocorrections and manual corrections to fix SwiftLint errors. The following is a list of the relevant changes.
./Makefileto install SwiftLint from Homebrew and setup pre-commit Git hooktools/git-hooks/pre-committo run SwiftLint autocorrect on all files in Git stage area before being committed.tools/git-hooks/setup.shto copy pre-commit file to.git/hooks/pre-commit. Script is run from Makefile'ssetup-lint-tooltargettools/format/.swiftlint.ymlSwiftLint configuration file. This file contains several changes to the default SwiftLint configurations, including enabling several opt-in rules, disabling the "nesting" rule, and setting "force_cast" and "force_try" rules to warnings instead of errors.linton the target's source files. Each target has their own run script which lints the relevant files for that target (i.e. source, unit tests, functional tests, demo apps).codeusing the configuration undertools/format/.swiftlint.yml. Also, manually corrected some errors reported by SwiftLint which were not auto-correctable. Note, I did not fix all the warnings produced by SwiftLint, just the errors in order for the project to build.Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: