Commit Graph

30 Commits

Author SHA1 Message Date
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 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
Marcelo Fabri 45a03dec20 Add back void_function_in_ternary rule (#3956) 2022-06-27 09:41:52 -07: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
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 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
Danny Mösch 050473a0e1 Add optional prefer_self_in_static_references rule (#3732) 2021-11-29 18:42:53 +00: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
Marcelo Fabri 68bfc13941 Add add_target_in_variable_declaration_closure rule 2021-09-29 10:28:39 -07:00
Ben Fox 00799cc782 Fixes MissingDocRuleConfiguration (#3713)
* add configuration for missing_docs

* fix MissingDocsRuleConfiguration

* add to changelog

* fix up Config default values and update tests

* use XCTAssertTrue and XCTAssertFalse

* fix line length violation

* finish up unit tests

* rever Package.resolved
2021-09-13 15:23:55 -04:00
Kane Cheshire 4a293632c2 Named rule correctly for Sourcery to work properly 2021-08-24 00:19:35 -07:00
Marcelo Fabri 9939c536d5 Add anonymous_argument_in_multiline_closure opt-in rule (#3659)
* Add anonymous_argument_in_multiline_closure opt-in rule

* Restrict match to the closure

* Fixes
2021-06-17 17:03:19 -07:00
Kane Cheshire 3536a86ba1 Added more non-triggering examples 2021-05-24 12:05:29 -07:00
Marcelo Fabri a10158c475 Add duplicated_key_in_dictionary_literal rule (#3613) 2021-04-28 17:25:08 -07:00
JP Simard e47fb60c7a Regenerate Sourcery output 2021-03-03 15:41:50 -05:00
László Kustra 87d4accb39 Add "Capture non-constant variable" rule 2021-03-02 16:11:33 -05:00
Otavio Cordeiro 24122e1325 Rename Rule to BalancedXCTestLifecycleRule 2021-03-01 01:29:16 +01:00
Otavio Cordeiro bd4dcd5b23 Add required_xctest_tearddown opt-in rule 2021-02-28 23:48:05 +01:00
JP Simard eca9ea4bb8 Adding Legacy ObjC Type Rule #2758 (#3531) 2021-02-23 12:08:01 -08:00
Otavio Cordeiro 46777539ad Add opt-in rule private_passthrough_subject (#3504) 2021-02-08 10:43:27 -08:00
Otavio Cordeiro 59eb887cfa Add opt-in rule discouraged_assert (#3506)
Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
2021-01-29 09:30:57 -08:00
Keith Smiley 800030ad11 Remove NonPrivateXCTestMembersRule (#3459)
* Remove NonPrivateXCTestMembersRule

I accidentally implemented this rule twice. So TestCaseAccessibilityRule
did the same thing but with a bit more behavior. This change deletes
NonPrivateXCTestMembersRule but also ports over the autocorrection from
it to TestCaseAccessibilityRule.
2020-12-09 13:16:40 -08:00
Keith Smiley 3151e6c45f Add NonPrivateXCTestMembersRule (#3248)
Co-authored-by: JP Simard <jp@jpsim.com>
2020-11-16 09:50:56 -08:00
Noah Gilmore dd5c0d3599 Add CommentSpacingRule (#3233) 2020-11-09 21:54:14 -08:00
Marcelo Fabri c8596a647a Add prefer_nimble opt-in rule
Fixes #3293
2020-11-08 00:09:51 -08:00
Dalton Claybrook d305e03905 Add inclusive_language rule (#3243)
Current events have renewed the conversation in our community about the roles of terminology with racist connotations in our software. Many companies and developers are now taking appropriate steps to remove this terminology from their codebases and products. (e.g. [GitHub](https://twitter.com/natfriedman/status/1271253144442253312)) This small rule prevents the use of declarations that contain any of the terms: whitelist, blacklist, master, and slave. It may be appropriate to add more terms to this list now or in the future.
2020-11-07 22:03:08 -05:00