Skip to content

Commit

Permalink
Merge branch 'main' into jkolarik-no_async_without_await
Browse files Browse the repository at this point in the history
  • Loading branch information
jkolarik-paylocity committed Nov 25, 2024
2 parents 7ffd35e + e9ce8ce commit 572bc58
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set Docker tag
if: github.event_name == 'workflow_call' || github.event_name == 'workflow_dispatch'
if: github.event_name != 'push' && ${{ inputs.tag }}
run: echo "DOCKER_TAG=${{ inputs.tag }}" >> $GITHUB_ENV
- name: Use default Docker tag
if: github.event_name == 'push'
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ jobs:
- name: Retrieve author in uppercase
id: retrieve_author
run: |
AUTHOR=${{ github.event.release.author.login }}
echo "name=${AUTHOR@U}" >> $GITHUB_OUTPUT
author=${{ github.event.release.author.login }}
AUTHOR=$(echo $author | tr '[:lower:]' '[:upper:]')
echo "name=${AUTHOR}" >> $GITHUB_OUTPUT
- name: Deploy to CocoaPods
run: make pod_publish
env:
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,23 @@
* Adds `noAsyncFuncWithoutAwait` opt-in rule that check if a async function call at least one async function.
[Jan Kolarik](https://github.com/jkolarik-paylocity)
[#5082](https://github.com/realm/SwiftLint/issues/5082)
* None.

#### Bug Fixes

* None.

## 0.57.1: Squeaky Clean Cycle

#### Breaking

* None.

#### Experimental

* None.

#### Enhancements

* Suggest failable `String(bytes:encoding:)` initializer in
`optional_data_string_conversion` rule as it accepts all `Sequence`
Expand All @@ -36,6 +53,14 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#5774](https://github.com/realm/SwiftLint/issues/5774)

* Add new option `max_number_of_single_line_parameters` that allows only the specified maximum
number of parameters to be on one line when `allows_single_line = true`. If the limit is
exceeded, the rule will still trigger. Confusing option combinations like `allows_single_line = false`
together with `max_number_of_single_line_parameters > 1` will be reported.
[kimdv](https://github.com/kimdv)
[SimplyDanny](https://github.com/SimplyDanny)
[#5781](https://github.com/realm/SwiftLint/issues/5781)

* The `redundant_type_annotation` rule gains a new option,
`ignore_properties`, that skips enforcement on members in a
type declaration (like a `struct`). This helps the rule coexist with
Expand Down
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
arm64-darwin-24
x86_64-linux

DEPENDENCIES
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "swiftlint",
version = "0.57.0",
version = "0.57.1",
compatibility_level = 1,
repo_name = "SwiftLint",
)
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ let package = Package(
package.targets.append(
.binaryTarget(
name: "SwiftLintBinary",
url: "https://github.com/realm/SwiftLint/releases/download/0.57.0/SwiftLintBinary-macos.artifactbundle.zip",
checksum: "a1bbafe57538077f3abe4cfb004b0464dcd87e8c23611a2153c675574b858b3a"
url: "https://github.com/realm/SwiftLint/releases/download/0.57.1/SwiftLintBinary-macos.artifactbundle.zip",
checksum: "c88bf3e5bc1326d8ca66bc3f9eae786f2094c5172cd70b26b5f07686bb883899"
)
)
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,29 @@ struct MultilineParametersConfiguration: SeverityBasedRuleConfiguration {
private(set) var severityConfiguration = SeverityConfiguration<Parent>(.warning)
@ConfigurationElement(key: "allows_single_line")
private(set) var allowsSingleLine = true
@ConfigurationElement(key: "max_number_of_single_line_parameters")
private(set) var maxNumberOfSingleLineParameters: Int?

func validate() throws {
guard let maxNumberOfSingleLineParameters else {
return
}
guard maxNumberOfSingleLineParameters >= 1 else {
Issue.inconsistentConfiguration(
ruleID: Parent.identifier,
message: "Option '\($maxNumberOfSingleLineParameters.key)' should be >= 1."
).print()
return
}

if maxNumberOfSingleLineParameters > 1, !allowsSingleLine {
Issue.inconsistentConfiguration(
ruleID: Parent.identifier,
message: """
Option '\($maxNumberOfSingleLineParameters.key)' has no effect when \
'\($allowsSingleLine.key)' is false.
"""
).print()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ private extension MultilineParametersRule {
numberOfParameters += 1
}

if let maxNumberOfSingleLineParameters = configuration.maxNumberOfSingleLineParameters,
configuration.allowsSingleLine,
numberOfParameters > maxNumberOfSingleLineParameters {
return true
}

guard linesWithParameters.count > (configuration.allowsSingleLine ? 1 : 0),
numberOfParameters != linesWithParameters.count else {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ internal struct MultilineParametersRuleExamples {
) { }
}
""", configuration: ["allows_single_line": false]),
Example("func foo(param1: Int, param2: Bool, param3: [String]) { }",
configuration: ["max_number_of_single_line_parameters": 3]),
Example("""
func foo(param1: Int,
param2: Bool,
param3: [String]) { }
""", configuration: ["max_number_of_single_line_parameters": 3]),
]

static let triggeringExamples: [Example] = [
Expand Down Expand Up @@ -336,5 +343,12 @@ internal struct MultilineParametersRuleExamples {
configuration: ["allows_single_line": false]),
Example("func ↓foo(param1: Int, param2: Bool, param3: [String]) { }",
configuration: ["allows_single_line": false]),
Example("func ↓foo(param1: Int, param2: Bool, param3: [String]) { }",
configuration: ["max_number_of_single_line_parameters": 2]),
Example("""
func ↓foo(param1: Int,
param2: Bool, param3: [String]) { }
""",
configuration: ["max_number_of_single_line_parameters": 3]),
]
}
2 changes: 1 addition & 1 deletion Source/SwiftLintCore/Models/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public struct Version: VersionComparable {
}

/// The current SwiftLint version.
public static let current = Self(value: "0.57.0")
public static let current = Self(value: "0.57.1")

/// Public initializer.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@testable import SwiftLintBuiltInRules
@testable import SwiftLintCore
import XCTest

final class MultilineParametersConfigurationTests: SwiftLintTestCase {
func testInvalidMaxNumberOfSingleLineParameters() throws {
for maxNumberOfSingleLineParameters in [0, -1] {
var config = MultilineParametersConfiguration()

XCTAssertEqual(
try Issue.captureConsole {
try config.apply(
configuration: ["max_number_of_single_line_parameters": maxNumberOfSingleLineParameters]
)
},
"""
warning: Inconsistent configuration for 'multiline_parameters' rule: Option \
'max_number_of_single_line_parameters' should be >= 1.
"""
)
}
}

func testInvalidMaxNumberOfSingleLineParametersWithSingleLineEnabled() throws {
var config = MultilineParametersConfiguration()

XCTAssertEqual(
try Issue.captureConsole {
try config.apply(
configuration: ["max_number_of_single_line_parameters": 2, "allows_single_line": false]
)
},
"""
warning: Inconsistent configuration for 'multiline_parameters' rule: Option \
'max_number_of_single_line_parameters' has no effect when 'allows_single_line' is false.
"""
)
}
}
10 changes: 5 additions & 5 deletions tools/create-github-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ release_notes=$(mktemp)
# Create GitHub Release

release_title="$(sed -n '1s/^## //p' CHANGELOG.md)"
gh release create "$version" --title "$release_title" -F "$release_notes" \
"bazel.tar.gz" \
"bazel.tar.gz.sha256" \
"portable_swiftlint.zip" \
"SwiftLint.pkg" \
gh release create "$version" --title "$release_title" -F "$release_notes" --draft \
"bazel.tar.gz" \
"bazel.tar.gz.sha256" \
"portable_swiftlint.zip" \
"SwiftLint.pkg" \
"SwiftLintBinary-macos.artifactbundle.zip"

rm "$release_notes"

0 comments on commit 572bc58

Please sign in to comment.