Like Scenery, we always look beautiful scenery every where we gone. If your code is well structured and easy to read is makes people happy to reading your code and doesn't take long to read your code. if you iOS developer you can use swiftLint, it's one help you to make beautiful code in swift 😋.
- brew install swiftlint ( If you install in global project )
- pod 'SwiftLint' ( If you install in specific project with cocoapods )
run swiftlint generate-docs
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Like that :
Build project, the default swiftlint structure is finished installed, Swiftlint checks all files in project, if you what to adjust the structure of the settings and check a specific file you can do that. add .swiftlint.yml in inside folder project, add specific stucture like :
# By default, SwiftLint uses a set of sensible default rules you can adjust: disabled_rules: # rule identifiers turned on by default to exclude from running - colon - comma - control_statement opt_in_rules: # some rules are turned off by default, so you need to opt-in - empty_count # Find all the available rules by running: `swiftlint rules` # Alternatively, specify all rules explicitly by uncommenting this option: # whitelist_rules: # delete `disabled_rules` & `opt_in_rules` if using this # - empty_parameters # - vertical_whitespace included: # paths to include during linting. `--path` is ignored if present. # - Source excluded: # paths to ignore during linting. Takes precedence over `included`. - R.generated.swift - ReloadDataListTests - ReloadDataListUITests - Carthage - Pods - Source/ExcludedFolder - Source/ExcludedFile.swift - Source/*/ExcludedFile.swift analyzer_rules: # Rules run by `swiftlint analyze` (experimental) - explicit_self # configurable rules can be customized from this configuration file # binary rules can set their severity level force_cast: warning # implicitly force_try: severity: warning # explicitly # rules that have both warning and error levels, can set just the warning level # implicitly line_length: 110 # they can set both implicitly with an array type_body_length: - 300 # warning - 400 # error # or they can set both explicitly file_length: warning: 500 error: 1200 # naming rules can set warnings/errors for min_length and max_length # additionally they can set excluded names type_name: min_length: 4 # only warning max_length: # warning and error warning: 40 error: 50 excluded: iPhone # excluded via string allowed_symbols: ["_"] # these are allowed in type names identifier_name: min_length: # only min_length error: 4 # only error excluded: # excluded via string array - id - URL - GlobalAPIKey reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown, github-actions-logging)
run swiftlint autocorrext inside folder . Look at the autocorrect code if it doesn't look like the stucture has such a notification 😊
SwiftLint to make beautiful code in Swift
Reviewed by sdiik
on
October 17, 2020
Rating:
No comments: