I use SwiftLint to control the code style of my project, it is working fine almost all the time. But I met a little trouble: when the .swiftlint.yml
file not in the same folder with the project file '.xcodeproj', if I use command swiftlint autocorrect
or use Xcode build to use SwiftLint I need change .swiftlint.yml
every time. The below is the details:
- My project structure like below:
> SampleProject > ├── .swiftlint.yml > ├── SampleProject > │ ├── Frameworks > │ ├── Info.plist > │ ├── SampleProject > │ ├── SampleProject.xcodeproj > │ └── SampleProjectTests > ├── SampleProject.xcworkspace > ├── Configuration > ├── CommonFoundation > │ ├── CommonFoundation > │ ├── CommonFoundation.xcodeproj > │ └── CommonFoundationTests > ├── Gemfile > ├── Gemfile.lock > ├── Podfile > ├── Podfile.lock > ├── Pods > ├── README.md > ├── fastlane > └── release.sh
the .swiftlint.yml
in the root path, but SampleProject.xcodeproj
in the sub folder;
- I've installed SwiftLint via
brew install swiftlint
; I've add
SwiftLint Script
with below code in Xcode for projectSampleProject.xcodeproj
:if which swiftlint >/dev/null; then swiftlint --config ../.swiftlint.yml else echo "warning: SwiftLint not installed, 'brew install swiftlint' or download from https://github.com/realm/SwiftLint" fi
.swiftlint.yml
code as below:disabled_rules: # rule identifiers to exclude from running - colon - comma - control_statement - line_length - type_body_length - function_body_length - cyclomatic_complexity opt_in_rules: # some rules are only opt-in - empty_count included: # paths to include during linting. `--path` is ignored if present. - ./SampleProject/Manager/Configs.swift excluded: # paths to ignore during linting. Takes precedence over `included`. - Carthage - Pods analyzer_rules: # Rules run by `swiftlint analyze` (experimental) - explicit_self force_cast: warning # implicitly force_try: severity: warning # explicitly type_body_length: - 300 # warning - 400 # error # or they can set both explicitly file_length: warning: 1000 error: 1500 type_name: min_length: 4 # only warning max_length: # warning and error warning: 40 error: 50 excluded: iPhone # excluded via string identifier_name: min_length: # only min_length error: 3 # only error excluded: # excluded via string array - i - j - id - GlobalAPIKey reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
When I build project with Xcode with SwiftLint with file
SampleProject/SampleProject/Manager/Configs.swift
, I need update theincluded
item in.swiftlint.yml
as below:included: # paths to include during linting. `--path` is ignored if present. - ./SampleProject/Manager/Configs.swift
When I run command 'swiftlint autocorrect' with SwiftLint with file
SampleProject/SampleProject/Manager/Configs.swift
, I need update theincluded
item in.swiftlint.yml
as below:included: # paths to include during linting. `--path` is ignored if present. - SampleProject/SampleProject/Manager/Configs.swift
I want find a way to help on this is do not change .swiftlint.yml
file but command 'swiftlint autocorrect' and Xcode build are working fine with SwiftLint.