Commit Graph

785 Commits

Author SHA1 Message Date
Danny Mösch e64e82d80d Get rid of periods finishing rule descriptions 2023-01-10 22:29:13 +01:00
Julio Carrettoni 3745704c03
Add rule for single space after period on comments (#4624) 2022-12-15 23:27:33 +01:00
JP Simard a876e860ee
release 0.50.3 2022-12-09 14:12:02 -05:00
JP Simard ff06e0ed00
release 0.50.2 2022-12-09 13:49:24 -05:00
Ryan Aveo 92304cdd98
Fix building tests in Xcode (#4607)
Co-authored-by: JP Simard <jp@jpsim.com>
2022-11-30 10:33:33 -05:00
JP Simard 28a4aa2195
release 0.50.1 2022-11-25 11:38:16 -05:00
JP Simard fd502b4526
Add new `local_doc_comment` rule (#4581)
Moving the validation of doc comments in local scopes out of
`orphaned_doc_comment` and into a new opt-in `local_doc_comment` rule.

Addresses https://github.com/realm/SwiftLint/issues/4573.
2022-11-23 17:50:18 -05:00
JP Simard cdd891a4a2
release 0.50.0 2022-11-18 14:43:44 -05:00
JP Simard 18f9a0e3a6
Write some docs for internal APIs (#4550)
These should be useful when writing rules, but also may become public
API in the future.
2022-11-16 13:58:55 -05:00
Danny Mösch 32152646f3
Use `Self` in constructor calls (#4505) 2022-11-02 22:50:22 +00:00
Henry 63c043664d
Add new `no_magic_numbers` rule (#4265) 2022-10-30 15:28:20 +01:00
Marcelo Fabri 59ad84f6e9
Add ns_number_init_as_function_reference rule (#4414) 2022-10-20 09:15:17 -07:00
Danny Mösch a7ff8a8d76
Rename `if_let_shadowing` rule to `shorthand_optional_binding` (#4334) 2022-10-14 21:47:37 +00:00
Danny Mösch 9db88947b9
Fix bugs when auto-correcting content given via stdin (#4212)
Fixes #4211.
Fixes #4234.
Fixes #4347.
2022-10-13 00:34:48 -04:00
JP Simard 602070164b
Reduce memory usage (#4349)
When linting SwiftLint, this brings memory usage down by around 20%,
going from 372MB to 297MB.

This is achieved by removing the unused `RebuildQueue` and by clearing
cached data associated with files after processing them.

Depends on https://github.com/jpsim/SourceKitten/pull/749.
2022-10-12 09:39:36 -04:00
JP Simard 44382ea397
Avoid making SourceKit requests to get parser diagnostics (#4286)
By using SwiftSyntax instead, we avoid the overhead of a SourceKit
request, which has a significant impact if none of the rules being
corrected use SourceKit.
2022-10-05 15:38:11 +00:00
Danny Mösch c6eec8072c
Move method (#4238) 2022-09-25 12:31:24 -04:00
Danny Mösch 7be6f866fe
Add new `if_let_shadowing` rule (#4206) 2022-09-22 19:27:45 +02:00
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