Commit Graph

2943 Commits

Author SHA1 Message Date
Martin Hosna f32bc1f337 RedundantDiscardableLetRule should not produce warning when used with async (#4143)
handle situation with async let _ = ....
let can not be removed from "async let _ = ..." because removing it produces invalid swift syntax

Co-authored-by: Martin Hosna <mhosna@samepage.io>
2022-08-29 12:56:35 -04:00
JP Simard 4119c27857 Fix typo 2022-08-29 00:33:51 -04:00
JP Simard cd9bd5f9fd Make duplicate_imports rule documentation deterministic (#4137) 2022-08-28 18:27:12 -04:00
Danny Mösch 9875ab904b Print autocorrected STDIN input to STDOUT (#4132) 2022-08-28 23:17:20 +02:00
Danny Mösch bf9bf83143 Migrate EmptyXCTestMethodRule to SwiftSyntax fixing some false-positives (#4129) 2022-08-27 03:02:05 -04:00
JP Simard ef36201e6b release 0.49.0 2022-08-26 10:48:09 -04:00
JP Simard 5a30991fa4 Add SwiftSyntax rule helpers (#4126)
This cuts down on the boilerplate involved in writing SwiftSyntax-based
rules. May not be significant right now since most rules are still built
with SourceKit, but as we migrate more rules moving forward, this should
make it easier for rule authors to write rules that behave performantly
and correctly.
2022-08-26 14:46:32 +00:00
Ben Davis 7dfadc205a Add new configuration to operator_usage_whitespace rule to specify no-space operators (#4112) 2022-08-25 17:59:27 +02:00
JP Simard 83bf37e642 Add SwiftLintFile.isTestFile (#4122) 2022-08-23 12:04:30 -04:00
Danny Mösch f3e2c0b7bb Replace manual backtracking by location information from the captured group (#4111) 2022-08-19 20:14:19 +02:00
Danny Mösch 6dc2ef937e Add trigger markers to examples (#4110) 2022-08-18 22:15:11 +00:00
JP Simard dd55f59207 release 0.49.0-rc.2 2022-08-18 13:31:47 -04:00
Kotaro Suto 78949c1b99 Fix broken correction for explicit_init rule (#4109) 2022-08-18 17:17:52 +00:00
chrisjf 1ef15f3bb7 Update documentation for multiline_arguments_brackets and multiline_literal_brackets (#4098)
- added two triggering examples that are a common style, to make it immediately obvious that they trigger the rules
- also fixed a spelling mistake throughout the examples for the multiline_literal_brackets rule ("Gryffindor" is now correctly spelt)
2022-08-18 09:53:52 +02:00
Kotaro Suto 3aa249b8a1 Fix first_where false negative (#4105) 2022-08-17 00:06:32 +00:00
JP Simard c2be5b18b4 Only check sourcekitdFailed for SourceKit-based rules (#4104)
And only warn once if it's disabled.

This check is expensive and as more rules move away from SourceKit to
SwiftSyntax, it's increasingly common for rules to not use SourceKit at
all.

In addition, SourceKit crashes used to be a lot more common but I
haven't seen one myself in quite a while.
2022-08-16 16:46:55 +00:00
JP Simard 73c88c3af0 Add version --verbose command (#4102)
Prints out something like this on macOS:

```
Version: 0.49.0-rc.1
Build ID: B43931F3-D096-3704-B41C-FC40673A3F96
```

This can be used to determine if two `swiftlint` executables are
identical.
2022-08-16 14:12:44 +00:00
JP Simard ac23f2e89a Log time spent in each custom rule (#4100) 2022-08-15 22:03:06 -04:00
JP Simard 13703c4466 Update SourceKitFreeRules (#4097)
None of these rules use SourceKit
2022-08-16 00:56:03 +00:00
JP Simard 3037946bbc Migrate ClosureSpacingRule to SwiftSyntax (#4092)
Fixes #4090. Continued from #4091.
2022-08-15 18:27:43 +00:00
sarastro-nl d1a1485af6 enable glob for includePaths (#4093) 2022-08-15 13:54:49 +00:00
Danny Mösch ef515ac45e Fix false positive in yoda_condition rule basing it on SwiftSyntax (#4089) 2022-08-14 16:30:09 -04:00
JP Simard 6f03036591 release 0.49.0-rc.1 2022-08-12 09:49:13 -04:00
Timofey Solonin 557c5b5948 Make duplicate_imports rule correctable (#4014)
Also fix reporting of redundant violations when more than one duplicate is present.
2022-08-11 18:19:26 +02:00
Danny Mösch a02d4a76cb Remove references to ManuallyTestedExamplesRule protocol (#4082)
Follow-up of d730e0b3fa.
2022-08-10 21:42:10 +00:00
Danny Mösch d730e0b3fa Let all example verification tests be generated by Sourcery (#4076) 2022-08-10 22:49:28 +02:00
Danny Mösch 828f36958f Introduce option to ignore indentation of compiler directives in indentation_width rule (#4066) 2022-08-10 21:52:32 +02:00
Sara Tavares 436a6f3484 chore(typo): fix typo on func (#4077) 2022-08-10 13:35:42 -04:00
Danny Mösch 449190d324 Verify examples in rules by default and enforce explicit exclusion (#4065)
A rule must conform to ManuallyTestedExamplesRule to skip generation of a test for its examples.
2022-08-09 22:32:09 +02:00
JP Simard 1ac0419eb6 Fix failing Swift 5.7 test (#4075)
Seems like `CGPoint` moved from the `CoreGraphics` module to the
`CoreFoundation` module.
2022-08-09 16:44:05 +00:00
JP Simard 0ded5859a1 Rewrite ColonRule with SwiftSyntax (#4063)
Making it about 7x faster, finding some previously missed cases.
2022-08-04 17:23:52 -04:00
Danny Mösch cdb87e3869 Verify all examples provided in rule descriptions (#4061) 2022-08-04 23:06:37 +02:00
JP Simard c50b42c183 Rewrite CommaRule with SwiftSyntax (#4062)
Making it about 10x faster, finding some previously missed cases and
fixing some previously wrong corrections.

This pulls in the `Collection.windows(ofCount:)` function from Swift
Algorithms.
2022-08-04 04:29:38 +00:00
Or Eliyahu 19eda14df1 Fix false positives in duplicated_key_in_dictionary_literal rule (#4057) 2022-07-31 21:07:15 +02:00
JP Simard 6c5f53ef66 Add micro-optimization to commands cache (#4050)
Speeds up overall lint time by ~2% for Lyft's iOS monorepo.
2022-07-28 15:44:34 +00:00
Steve Madsen 4d8abec16e Make comma_inheritance rule opt-in (#4047) 2022-07-27 17:01:11 +02:00
Marcelo Fabri 3a64518119 Fix false positive in self_in_property_initialization (#4044)
* Fix false positive in self_in_property_initialization

Fixes #4041

* Update CHANGELOG.md

Co-authored-by: JP Simard <jp@jpsim.com>

Co-authored-by: JP Simard <jp@jpsim.com>
2022-07-26 11:41:09 -07:00
JP Simard c0f9f2175b Add support for native custom rules (#4039)
This change makes it possible to add native custom rules when building
SwiftLint via Bazel (possible as of
https://github.com/realm/SwiftLint/pull/4038).

First, add a local bazel repository where custom rules will be defined
to your project's `WORKSPACE`:

```python
local_repository(
    name = "swiftlint_extra_rules",
    path = "swiftlint_extra_rules",
)
```

Then in the extra rules directory, add an empty `WORKSPACE` and a
`BUILD` file with the following contents:

```python
filegroup(
    name = "extra_rules",
    srcs = glob(["*.swift"]),
    visibility = ["//visibility:public"],
)
```

To add a rule (for example, `MyPrivateRule`) add the following two
files:

```swift
// ExtraRules.swift
func extraRules() -> [Rule.Type] {
    [
        MyPrivateRule.self,
    ]
}
```

```swift
// MyPrivateRule.swift
import SourceKittenFramework
import SwiftSyntax

struct MyPrivateRule: ConfigurationProviderRule {
    var configuration = SeverityConfiguration(.error)

    init() {}

    static let description = RuleDescription(
        identifier: "my_private_rule",
        name: "My Private Rule",
        description: "This is my private rule.",
        kind: .idiomatic
    )

    func validate(file: SwiftLintFile) -> [StyleViolation] {
        // Perform validation here...
    }
}
```

Then you can reference the rule in your configuration or source files as
though they were built in to the official SwiftLint repo.

This means that you have access to SwiftLintFramework's internal API.
We make no guarantees as to the stability of these internal APIs,
although if you end up using something that gets removed please reach
out and we'll make a best effort to maintain some level of support.

This PR also improves the linter cache on macOS to make it correctly
invalidate previous results when custom native rules are edited. This
even works when doing local development of SwiftLint, where previous it
was necessary to use `--no-cache` when working on SwiftLint, now the
cache should always work.

Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
2022-07-26 13:56:22 -04:00
JP Simard 05ac3c9d75 Require macOS 12 & Swift 5.6 (#4037)
This will unblock using Swift Concurrency features and updating to the
latest versions of Swift Argument Parser.

This won't drop support for linting projects with an older toolchain /
Xcode selected, as long as SwiftLint was _built_ with 5.6+ and is
_running_ on macOS 12+. So the main breaking change for end users here
is requiring macOS 12 to run.

However, the upside to using Swift Concurrency features is worth the
breaking change in my opinion. Also being able to stay on recent Swift
Argument Parser releases.
2022-07-26 03:55:36 -04:00
JP Simard 22fb9eb9e5 release 0.48.0 2022-07-26 03:34:06 -04:00
JP Simard f81972e98c Apply minor stylistic edits to OperatorUsageWhitespaceRule 2022-07-26 03:23:35 -04:00
Danny Mösch 4aa38957c3 Enable auto-test for rule (#4033) 2022-07-24 08:24:11 -04:00
Craig Siemens c5aa8065d1 Update nimble_operator to suggest the (in)equal operator instead of beNil() (#4025) 2022-07-14 13:44:29 -04:00
Danny Mösch a51be7bcce Refactor deployment target configuration to avoid duplications (#4017) 2022-07-06 17:07:15 -04:00
Taha Bebek e34f49695b Support extension targets in deployment_target rule (#4011) 2022-07-05 22:41:56 +02:00
Koki Hirokawa 25ed3d2d26 Support UIEdgeInsets type in prefer_zero_over_explicit_init rule (#4008) 2022-06-29 21:28:47 +02:00
Marcelo Fabri 45a03dec20 Add back void_function_in_ternary rule (#3956) 2022-06-27 09:41:52 -07:00
Marcelo Fabri a19ffddf66 Support arrays for included & excluded in custom rules (#4006)
* Support arrays for `included` & `excluded` in custom rules

* Extract shouldValidate(filePath:) and add tests
2022-06-27 00:29:26 -07:00
Danny Mösch 1faea36a22 Do not trigger unavailable_condition rule if other #(un)available checks are involved (#4002) 2022-06-24 22:58:02 +02:00
Danny Mösch a20a75d422 Fix various shortcomings in relative path computation (#4005) 2022-06-24 02:25:37 -04:00