Commit Graph
2930 Commits
Author SHA1 Message Date
chrisjfandGitHub 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 SutoandGitHub 3aa249b8a1 Fix first_where false negative (#4105) 2022-08-17 00:06:32 +00:00
JP SimardandGitHub 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 SimardandGitHub 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 SimardandGitHub ac23f2e89a Log time spent in each custom rule (#4100) 2022-08-15 22:03:06 -04:00
JP SimardandGitHub 13703c4466 Update SourceKitFreeRules (#4097)
None of these rules use SourceKit
2022-08-16 00:56:03 +00:00
JP SimardandGitHub 3037946bbc Migrate ClosureSpacingRule to SwiftSyntax (#4092)
Fixes #4090. Continued from #4091.
2022-08-15 18:27:43 +00:00
sarastro-nlandGitHub d1a1485af6 enable glob for includePaths (#4093) 2022-08-15 13:54:49 +00:00
Danny MöschandGitHub 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 SoloninandGitHub 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öschandGitHub a02d4a76cb Remove references to ManuallyTestedExamplesRule protocol (#4082)
Follow-up of d730e0b3fa.
2022-08-10 21:42:10 +00:00
Danny MöschandGitHub d730e0b3fa Let all example verification tests be generated by Sourcery (#4076) 2022-08-10 22:49:28 +02:00
Danny MöschandGitHub 828f36958f Introduce option to ignore indentation of compiler directives in indentation_width rule (#4066) 2022-08-10 21:52:32 +02:00
Sara TavaresandGitHub 436a6f3484 chore(typo): fix typo on func (#4077) 2022-08-10 13:35:42 -04:00
Danny MöschandGitHub 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 SimardandGitHub 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 SimardandGitHub 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öschandGitHub cdb87e3869 Verify all examples provided in rule descriptions (#4061) 2022-08-04 23:06:37 +02:00
JP SimardandGitHub 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 EliyahuandGitHub 19eda14df1 Fix false positives in duplicated_key_in_dictionary_literal rule (#4057) 2022-07-31 21:07:15 +02:00
JP SimardandGitHub 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 MadsenandGitHub 4d8abec16e Make comma_inheritance rule opt-in (#4047) 2022-07-27 17:01:11 +02:00
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
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 SimardandGitHub 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öschandGitHub 4aa38957c3 Enable auto-test for rule (#4033) 2022-07-24 08:24:11 -04:00
Craig SiemensandGitHub c5aa8065d1 Update nimble_operator to suggest the (in)equal operator instead of beNil() (#4025) 2022-07-14 13:44:29 -04:00
Danny MöschandGitHub a51be7bcce Refactor deployment target configuration to avoid duplications (#4017) 2022-07-06 17:07:15 -04:00
Taha BebekandGitHub e34f49695b Support extension targets in deployment_target rule (#4011) 2022-07-05 22:41:56 +02:00
Koki HirokawaandGitHub 25ed3d2d26 Support UIEdgeInsets type in prefer_zero_over_explicit_init rule (#4008) 2022-06-29 21:28:47 +02:00
Marcelo FabriandGitHub 45a03dec20 Add back void_function_in_ternary rule (#3956) 2022-06-27 09:41:52 -07:00
Marcelo FabriandGitHub 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öschandGitHub 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öschandGitHub a20a75d422 Fix various shortcomings in relative path computation (#4005) 2022-06-24 02:25:37 -04:00
Danny MöschandGitHub 04972a39da Look for call expressions which are not wrapped into an argument (#3977)
This makes the added test cases work in Xcode 13.2 where the wrapping does not happen.
The call expression is the first substructure in the dictionary, while in Xcode 13.3
it's an argument containing the call expression.
2022-06-19 13:39:07 -04:00
Danny MöschandGitHub 634406a30a Fix violation message in untyped_error_in_catch rule (#4001)
It was just "warning". Now it is the description of the rule (default).
2022-06-19 13:09:33 -04:00
Danny MöschandGitHub 0d070a8c8c Update result builder methods in unused_declaration rule fixing some false-positives (#4000) 2022-06-19 11:59:23 +02:00
Danny MöschandGitHub 323a249f70 Make for_where independent of order in structure dictionary (#3979) 2022-06-14 13:55:12 -04:00
Marcelo FabriandGitHub 4382ef49b9 Use URL(fileURLWithPath:isDirectory) to avoid file system call (#3976) 2022-05-26 21:54:23 +02:00
Jaehong KangandGitHub 809dcc6bdc Prevent crash for private types named _ in type_name rule (#3972) 2022-05-10 19:15:44 +02:00
Danny MöschandGitHub ca9217d5e1 Ignore array types if their associated Index is accessed (#3970) 2022-05-07 19:11:53 -04:00
Marcelo FabriandGitHub f880b66cbf Rewrite operator_usage_whitespace with SwiftSyntax (#3962) 2022-05-06 16:48:57 -07:00
Marcelo FabriandGitHub ebc77391bc Add workaround to avoid stack overflow in debug (#3963) 2022-05-01 14:57:28 -07:00
Danny MöschandGitHub a27c7da7e2 Allow custom attributes on lines directly before let/var declarations (#3943) 2022-04-26 22:00:44 +02:00
JP Simard e497f1f5b1 release 0.47.1 2022-04-25 11:31:09 -04:00
Ryan ColeandGitHub 43c84146db Add accessibility_label_for_image rule (#3862)
Warns if a SwiftUI Image does not have an accessibility label and is not hidden from accessibility. When this is the case, the image's accessibility label defaults to the name of the image file causing a poor UX.
2022-04-18 10:40:51 +02:00
Marcelo FabriandGitHub 5f44d3f306 Add comma_inheritance_rule rule (#3954)
Fixes #3950
2022-04-17 04:47:02 -07:00