Skip to content

Commit 61b805c

Browse files
committed
feat: add SwiftLint workflow and configure rules for snapshot tests
1 parent 471b44a commit 61b805c

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed

.github/workflows/swiftlint.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: SwiftLint
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
concurrency:
12+
group: swiftlint-${{ github.ref }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
lint:
17+
name: SwiftLint
18+
runs-on: ubuntu-latest
19+
container: swift:6.2
20+
steps:
21+
- uses: actions/checkout@v5
22+
23+
- name: Restore swiftlint cache
24+
id: cache-swiftlint-restore
25+
uses: actions/cache/restore@v4
26+
with:
27+
path: /usr/local/bin/swiftlint
28+
key: ${{ runner.os }}-swiftlint-v1
29+
30+
- name: Install swiftlint
31+
if: steps.cache-swiftlint-restore.outputs.cache-hit != 'true'
32+
run: |
33+
git clone --depth 1 --branch main https://github.com/realm/SwiftLint.git
34+
cd SwiftLint
35+
swift build -c release
36+
cp .build/release/swiftlint /usr/local/bin/
37+
cd ..
38+
rm -rf SwiftLint
39+
40+
- name: Lint
41+
run: swiftlint lint --strict --reporter github-actions-logging
42+
43+
- name: Save swiftlint cache
44+
uses: actions/cache/save@v4
45+
if: steps.cache-swiftlint-restore.outputs.cache-hit != 'true'
46+
with:
47+
path: /usr/local/bin/swiftlint
48+
key: ${{ runner.os }}-swiftlint-v1

.swiftlint.yml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,42 @@ disabled_rules:
33
- identifier_name
44
- nesting # Allow deeply nested enums for namespacing
55
- redundant_discardable_let # Preserve 'let _ =' in result builder contexts (required for Swift 6.0+)
6+
- opening_brace # Handled by swift-format
7+
- trailing_comma # Handled by swift-format
8+
- trailing_whitespace # Preserve whitespace in snapshot tests
9+
- orphaned_doc_comment # Allow module-level documentation
10+
- large_tuple # CSS/HTML properties may require tuples with multiple components
11+
- mark # Allow flexible MARK comment formatting
12+
- redundant_string_enum_value # Explicit enum values improve clarity for CSS/HTML keywords
613

714
opt_in_rules:
815
- empty_count
916
- explicit_init
1017
- sorted_imports
1118
- force_cast
1219
- force_try
13-
- force_unwrapping
1420
- closure_spacing
1521
- operator_usage_whitespace
1622
- private_outlet
1723
- redundant_nil_coalescing
18-
- unused_capture_list
19-
- empty_string
20-
- explicit_enum_raw_value
2124
- literal_expression_end_indentation
2225
- single_test_class
2326
- sorted_first_last
2427
- vertical_whitespace
25-
- strict_fileprivate
2628
- legacy_random
2729
- no_extension_access_modifier
2830
- colon
29-
- trailing_comma
3031

3132
included:
3233
- Package.swift
3334
- Sources
35+
- Tests
3436

3537
excluded:
3638
- Carthage
3739
- Pods
3840
- fastlane
3941
- build
40-
- Tests
4142

4243
analyzer_rules:
4344
- unused_import
@@ -47,3 +48,35 @@ colon:
4748

4849
vertical_whitespace:
4950
max_empty_lines: 1
51+
52+
# Increased length limits for test files with extensive snapshots
53+
type_body_length:
54+
warning: 800
55+
error: 900
56+
57+
file_length:
58+
warning: 900
59+
error: 1000
60+
61+
function_body_length:
62+
warning: 270
63+
error: 300
64+
65+
# Allow short type names for HTML/CSS elements (H1, BR, B, RGB, HSL, etc.)
66+
type_name:
67+
min_length:
68+
warning: 1
69+
error: 0
70+
max_length:
71+
warning: 40
72+
error: 50
73+
74+
# Allow more function parameters for HTML/CSS functions with many attributes
75+
function_parameter_count:
76+
warning: 8
77+
error: 10
78+
79+
# Increased cyclomatic complexity for CSS/HTML property parsing functions
80+
cyclomatic_complexity:
81+
warning: 16
82+
error: 20

0 commit comments

Comments
 (0)