Commit Graph

767 Commits

Author SHA1 Message Date
Ryan Cole c34955ca64 Add accessibility_trait_for_button rule (#3989) 2022-09-06 21:44:09 +00:00
Marcelo Fabri 772e5f5806 Delegate Location init for AbsolutePosition to existing one (#4162) 2022-09-05 01:47:25 -04:00
Marcelo Fabri 79347a1728 Rewrite ForceUnwrappingRule using SwiftSyntax (#4155) 2022-09-04 02:08:26 -07:00
JP Simard 57dc1c9532 release 0.49.1 2022-09-01 12:32:19 -04:00
JP Simard 9979c4fd27 Add new self_binding opt-in rule (#4146)
To enforce that `self` identifiers are consistently re-bound to a common
identifier name.

Configure `bind_identifier` to the name you want to use.

Defaults to `self`.

Addresses https://github.com/realm/SwiftLint/issues/2495
2022-08-30 16:37:19 -04:00
JP Simard f032c82b59 Fix link in comments (#4145) 2022-08-29 14:29:20 -04:00
JP Simard 4119c27857 Fix typo 2022-08-29 00:33:51 -04:00
JP Simard ef36201e6b release 0.49.0 2022-08-26 10:48:09 -04:00
JP Simard 83bf37e642 Add SwiftLintFile.isTestFile (#4122) 2022-08-23 12:04:30 -04:00
JP Simard dd55f59207 release 0.49.0-rc.2 2022-08-18 13:31:47 -04: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 3037946bbc Migrate ClosureSpacingRule to SwiftSyntax (#4092)
Fixes #4090. Continued from #4091.
2022-08-15 18:27:43 +00:00
JP Simard 6f03036591 release 0.49.0-rc.1 2022-08-12 09:49:13 -04:00
Danny Mösch a02d4a76cb Remove references to ManuallyTestedExamplesRule protocol (#4082)
Follow-up of d730e0b3fa.
2022-08-10 21:42:10 +00: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
Danny Mösch cdb87e3869 Verify all examples provided in rule descriptions (#4061) 2022-08-04 23:06:37 +02: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
Marcelo Fabri 45a03dec20 Add back void_function_in_ternary rule (#3956) 2022-06-27 09:41:52 -07:00
JP Simard e497f1f5b1 release 0.47.1 2022-04-25 11:31:09 -04:00
Ryan Cole 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 Fabri 5f44d3f306 Add comma_inheritance_rule rule (#3954)
Fixes #3950
2022-04-17 04:47:02 -07:00
Marcelo Fabri 1752587b7b Add unavailable_condition rule (#3953)
Fixes #3897
2022-04-17 03:30:53 -07:00
Marcelo Fabri a786e310a3 Add back return_value_from_void_function rule (#3882) 2022-04-16 16:53:11 -07:00
Marcelo Fabri 0fbf010ea4 Only skip autocorrect on files with errors (#3933)
* Only skip autocorrect on files with errors

* Use other kind of warning so tests succeed on Linux

* Update CHANGELOG.md

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

Co-authored-by: JP Simard <jp@jpsim.com>
2022-04-05 10:59:50 -07:00
Danny Moesch a801bbc83b Add new type-safe ArrayInitRule (#3914)
The idea of this new Analyzer rule is to filter the calls of `map` before they are passed on to the classic ArrayInitRule which does the detailed checking of the lambda function block. The rule makes sure that only the `map` function is considered that is defined by the `Sequence` protocol.
2022-03-23 22:29:50 +01:00
JP Simard e5791ec16c release 0.47.0 2022-03-23 10:58:54 -04:00
Paul Taykalo 1616023b63 Add ability to run only one(focused) example (#3911)
* Add ability to focus on a specific test example

* Update CHANGELOG.md

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

* Update CONTRIBUTING.md

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

Co-authored-by: JP Simard <jp@jpsim.com>
2022-03-22 19:21:25 +02:00
Marcelo Fabri db2721f78e Require Swift 5.0 in runtime (#3886)
* Require Swift 5.0 in runtime

* Fix violation

* Enable legacy_rule by default

* Update changelog

* Fix changelog after rebase

* More cleanup
2022-03-11 14:01:27 -08:00
JP Simard 3273cef42b Prevent empty files from triggering rule violations (#3885)
There are many valid cases to have an empty Swift source files, and these
shouldn't trigger violations.
2022-03-09 16:09:11 -05:00
Marcelo Fabri b619154905 Automatically enforce min Swift version for all rules (#3881)
* Automatically enforce min Swift version for all rules

* Fix violations
2022-03-09 11:44:56 -08:00
JP Simard 0691a2e7e4 release 0.46.5 2022-03-08 16:35:33 -05:00
JP Simard f3712b2b93 release 0.46.4 2022-03-07 11:15:27 -05:00
Marcelo Fabri ff4249856e Fix false positive in EmptyEnumArgumentsRule with Swift 5.6 (#3868)
Fixes #3850
2022-03-07 11:10:15 -05:00
JP Simard 02675a9c09 Fix typo in doc comment: delimeter -> delimiter 2022-03-07 09:27:28 -05:00
Danny Moesch d77d23cbeb Add option to exclude examples from the rule documentation (#3834)
The option can be used if an example has mainly been added as another test case, but is not suitable
as a user example. User examples should be easy to understand. They should clearly show where and
why a rule is applied and where not. Complex examples with rarely used language constructs or
pathological use cases which are indeed important to test but not helpful for understanding can be
hidden from the documentation with this option.
2022-03-02 10:55:42 -05:00
JP Simard 9c81e1a93a release 0.46.3 2022-02-22 15:29:40 -05:00
JP Simard b4a54f32df release 0.46.2 2022-01-27 09:16:25 -05:00
JP Simard 61c5351978 release 0.46.1 2022-01-21 16:59:57 -05:00
JP Simard 17779cbfd4 release 0.46.0 2022-01-21 15:57:48 -05:00
JP Simard 341ec2a907 Remove 'weak_delegate' rule (#3809)
This was very prone to false positives and not worth keeping.

The identifier will stick around for a release to ease the migration.
2022-01-21 17:56:59 +00:00
Andrés Cecilia Luque af59581b66 Fix specifying the cachePath from command line (#3797) 2022-01-21 08:01:48 -08:00
JP Simard 95349376fd release 0.45.1 2021-11-29 16:47:21 -05:00
Danny Mösch 050473a0e1 Add optional prefer_self_in_static_references rule (#3732) 2021-11-29 18:42:53 +00:00
JP Simard 99465e659f release 0.45.0 2021-10-18 11:57:37 -04:00
Marcelo Fabri 383e5b5bc2 Handle get async and get throws in implicit_getter (#3743)
Fixes #3684
2021-10-12 10:32:34 -07:00
Marcelo Fabri 4052c43f16 Make rule more generic and rename it 2021-09-29 10:28:39 -07:00
Marcelo Fabri 2674d367f9 Fix violation 2021-09-29 10:28:39 -07:00