Skip to content

Commit

Permalink
Added linting check using SwiftLint (#417)
Browse files Browse the repository at this point in the history
* Create pr_swift_lint

* Rename pr_swift_lint to pr_swift_lint.yaml

* Testing current push

* Testing current Push

* Update pr_swift_lint.yaml

* Create .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Rename .swiftlint.yaml to a.swiftlint.yaml.txt

* Update pr_swift_lint.yaml

* Rename a.swiftlint.yaml.txt to .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Update .swiftlint.yaml

* Update .swiftlint.yaml

* Update .swiftlint.yaml

* Update .swiftlint.yaml

* Update .swiftlint.yaml

* Update .swiftlint.yaml

* Update .swiftlint.yaml

* Update .swiftlint.yaml

* Update pr_swift_lint.yaml

* Update pr_swift_lint.yaml

* Delete empty_file.txt

---------

Co-authored-by: htwags <[email protected]>
  • Loading branch information
henrytwagner and henrytwagner authored Apr 26, 2024
1 parent 990aeef commit 5bf9322
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/.swiftlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SwiftLint Configuration File


# To be tailored to reflect projects ideal linting configuration

#disabled_rules:
# ERRORS IN PROJECT CURRENTLY
# - cyclomatic_complexity
# - identifier_name
# - function_body_length
# - force_cast
# - force_try
# - line_length
# - file_length
# - type_body_length
# WARNINGS IN PROJECT CURRENTLY (excluding those already listed as errors)
# - trailing_comma
# - todo
# - orphaned_doc_comment
# - opening_brace
# - blanket_disable_command
# - for_where
# - trailing_whitespace
# - vertical_whitespace
# - void_function_in_ternary
# - empty_enum_arguments
# - closure_parameter_position


# change individual rule configurations
identifier_name:
min_length: 1
max_length:
warning: 40
error: 41


84 changes: 84 additions & 0 deletions .github/workflows/pr_swift_lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: pr_swift_lint
on:
pull_request_target:
branches:
- main
types:
- opened

jobs:
swift_format_check:
runs-on: macos-latest

name: Run Swift Lint

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install Homebrew (if macOS does not have it)
run: |
if ! command -v brew &>/dev/null
then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
- name: Install jq
run: brew install jq

- name: Install SwiftLint
run: brew install swiftlint

- name: Run SwiftLint
run: |
echo " "
set +e
swiftlint lint --reporter json --config /Users/runner/work/Scribe-iOS/Scribe-iOS/.github/workflows/.swiftlint.yaml > swiftlint-results.json
# Verify the JSON output exists and is not empty
if [ ! -f swiftlint-results.json ] || [ ! -s swiftlint-results.json ]; then
echo "SwiftLint did not produce output or the output is empty."
exit 1
fi
echo " "
# Formatting and printing warnings
echo "WARNINGS:"
warnings_count=$(jq -r '.[] | select(.severity == "Warning") | "\(.file):\(.line): warning: (\(.rule_id)) \(.reason)"' swiftlint-results.json | wc -l)
jq -r '.[] | select(.severity == "Warning") | "\(.file):\(.line): warning: (\(.rule_id)) \(.reason)"' swiftlint-results.json
if [ "$warnings_count" -eq 0 ]; then
echo "No Warnings"
fi
echo " "
# Formatting and printing errors
echo "ERRORS:"
errors_count=$(jq -r '.[] | select(.severity == "Error") | "\(.file):\(.line): error: (\(.rule_id)) \(.reason)"' swiftlint-results.json | wc -l)
jq -r '.[] | select(.severity == "Error") | "\(.file):\(.line): error: (\(.rule_id)) \(.reason)"' swiftlint-results.json
if [ "$errors_count" -eq 0 ]; then
echo "No Errors"
fi
# Printing summary of counts
echo " "
echo "-------- Summary --------"
echo "Total Warnings: $warnings_count"
echo "Total Errors: $errors_count"
echo " "
if [ "$errors_count" -gt 0 ]; then
echo "SwiftLint found errors." # Can change message to be more reflective of what needs to be conveyed
exit 2
elif [ "$warnings_count" -gt 0 ]; then
echo "SwiftLint found warnings." # Can change message to be more reflective of what needs to be conveyed
# exit 1 #Uncomment to enforce warnings
else
echo "SwiftLint found no issues." # Can change message to be more reflective of what needs to be conveyed
fi
shell: bash

0 comments on commit 5bf9322

Please sign in to comment.