Commit Graph
797 Commits
Author SHA1 Message Date
JP Simard eb85125a5f release 0.51.0 2023-03-27 11:44:47 -04:00
JP Simard efc5afd5d5 Apply small formatting fixes (#4840)
* Trim excess trailing and vertical whitespace
* Move `SwiftyTextTable` dependency into `frameworkDependencies`
* Adjust wording in README around analyzer rules in the `opt_in_rules`
  section, since analyzer rules can only go in the `analyzer_rules`
  section.
2023-03-26 16:09:43 -04:00
Martin Redington 31510b662e Use all optin rules facility for SwiftLint's own .swiftlint.yml (#4800) 2023-03-11 11:59:05 +01:00
Martin Redington 0bd8a7aba6 Add new blanket_disable_command rule (#4731) 2023-03-07 21:43:53 +01:00
Martin Redington 228d53787b Stopsuperfluous_disable_command from firing when disabled (#4791) 2023-03-05 19:21:35 +01:00
1in1 4fee8e6a0c Add new duplicate_conditions rule (#4771) 2023-03-05 11:05:23 +01:00
Martin Redington 1c3c62e422 Add new invalid_swiftlint_command rule (#4546) 2023-03-04 13:53:27 +01:00
Danny Mösch 393318d903 Add new direct_return opt-in rule (#4717) 2023-02-19 13:09:41 +01:00
Danny Mösch 5eed8fe91b Enable if_let_shadowing rule and fix all violations (#4247) 2023-01-31 22:31:38 +01:00
Danny Mösch 693e504258 Use basic NSRegularExpression type with caching (#4683) 2023-01-11 20:28:16 +01:00
kyounh12 5ec6112ba1 Interpret strings in excluded option of *_name rules as regex (#4655) 2023-01-10 23:29:04 +01:00
Danny Mösch cc44c989b7 Check every used internal violation reason for a pending period 2023-01-10 22:29:13 +01:00
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 AveoandJP Simard 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 SimardandKeith Smiley 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