Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added linting check using SwiftLint #417

Merged
merged 69 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
6a5a4e2
Create pr_swift_lint
henrytwagner Apr 13, 2024
4a8ea61
Rename pr_swift_lint to pr_swift_lint.yaml
henrytwagner Apr 13, 2024
729f000
Testing current push
henrytwagner Apr 13, 2024
6bd8084
Testing current Push
henrytwagner Apr 13, 2024
42aca42
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
75ac683
Create .swiftlint.yaml
henrytwagner Apr 23, 2024
54d8d7b
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
27197e5
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
8d24fce
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
26ca889
Rename .swiftlint.yaml to a.swiftlint.yaml.txt
henrytwagner Apr 23, 2024
5fda9ba
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
0c18d78
Rename a.swiftlint.yaml.txt to .swiftlint.yaml
henrytwagner Apr 23, 2024
bfbaec7
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
db81b0f
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
030967c
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
df7ef72
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
9c61592
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
e775a05
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
21dfc73
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
5e20889
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
3cba1fa
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
514f702
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
0c460e9
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
a40beb0
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
4ea8bf5
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
03c7325
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
e39758c
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
45454fc
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
25d3b3f
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
3228edb
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
a6df895
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
b3a86b8
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
b436ded
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
7f6c9aa
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
7830b7f
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
627e88e
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
5ad8fc9
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
92972ef
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
b7e216d
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
2a9bba9
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
145e80c
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
68989ea
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
21786bf
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
a75f2ed
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
f24b91d
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
5425ba0
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
cfb6001
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
26bd9b0
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
bb5798d
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
cf0a7e2
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
38e4022
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
e638793
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
7ff37df
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
076fb90
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
ef05846
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
6239776
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
d4748ce
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
b338c83
Update pr_swift_lint.yaml
henrytwagner Apr 23, 2024
55841f4
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
0dd0c95
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
877ac32
Update .swiftlint.yaml
henrytwagner Apr 23, 2024
c6a4fe3
Update .swiftlint.yaml
henrytwagner Apr 24, 2024
354900c
Update .swiftlint.yaml
henrytwagner Apr 24, 2024
b42118e
Update .swiftlint.yaml
henrytwagner Apr 24, 2024
842117d
Update .swiftlint.yaml
henrytwagner Apr 24, 2024
553e7c2
Update .swiftlint.yaml
henrytwagner Apr 24, 2024
fa8d8fb
Update pr_swift_lint.yaml
henrytwagner Apr 24, 2024
bbb754c
Update pr_swift_lint.yaml
henrytwagner Apr 24, 2024
3e6d8ca
Delete empty_file.txt
henrytwagner Apr 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really appreciate you adding all the config options in here and also documenting what will cause errors and warnings once they're turned on, @henrytwagner! Will really help us organize the work for this going forward 😊

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll likely move this file to the project root, but for the purposes of this PR it's totally fine to have it here. I figure this is where ESLint and Prettier configs normally are. Will send a commit with this along later :)



# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For here, I'm expecting that there's a pre-prepared workflow that can be subbed in for parts of this, but is looking really good all the same :)

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
Loading