A shareable SwiftLint configuration for enforcing Swift style guidelines and maintaining code consistency.
Ensure swiftLint
is installed on your system:
brew install swiftlint
Since swiftLint
runs as an external tool, install the necessary peer dependencies:
npm install -D swiftlint
To simplify usage, add the following script to your package.json
:
{
"scripts": {
"swiftlint": "node-swiftlint"
}
}
To install the shared SwiftLint configuration, run:
npm install -D @ebarooni/swiftlint-config
To apply this SwiftLint configuration, create a swiftlint.config.js
file in the project root:
module.exports = {
...require("@ebarooni/swiftlint-config"),
included: ["${PWD}/ios"],
excluded: ["${PWD}/node_modules", "${PWD}/ios/Pods"],
};
To streamline linting and formatting, add these scripts to your package.json
:
{
"scripts": {
"swiftlint:check": "npm run swiftlint -- lint",
"swiftlint:fix": "npm run swiftlint -- --fix --format"
}
}
Run these commands:
-
Check Swift code for issues:
npm run swiftlint:check
-
Fix and format Swift code automatically:
npm run swiftlint:fix
If you need to modify the rules, extend the configuration in swiftlint.config.js
:
module.exports = {
...require("@ebarooni/swiftlint-config"),
rules: {
line_length: {
warning: 120,
},
},
};