Commit Graph

3166 Commits

Author SHA1 Message Date
Or Eliyahu 19eda14df1
Fix false positives in duplicated_key_in_dictionary_literal rule (#4057) 2022-07-31 21:07:15 +02:00
JP Simard 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 Madsen 4d8abec16e
Make comma_inheritance rule opt-in (#4047) 2022-07-27 17:01:11 +02:00
Marcelo Fabri 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
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 24735ef4d3
Add support for building with Bazel (#4038) 2022-07-26 07:09:02 -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
JP Simard f81972e98c
Apply minor stylistic edits to `OperatorUsageWhitespaceRule` 2022-07-26 03:23:35 -04:00
Danny Mösch 4aa38957c3
Enable auto-test for rule (#4033) 2022-07-24 08:24:11 -04:00
Craig Siemens c5aa8065d1
Update `nimble_operator` to suggest the (in)equal operator instead of `beNil()` (#4025) 2022-07-14 13:44:29 -04:00
Danny Mösch a51be7bcce
Refactor deployment target configuration to avoid duplications (#4017) 2022-07-06 17:07:15 -04:00
Taha Bebek e34f49695b
Support extension targets in `deployment_target` rule (#4011) 2022-07-05 22:41:56 +02:00
Koki Hirokawa 25ed3d2d26
Support `UIEdgeInsets` type in `prefer_zero_over_explicit_init` rule (#4008) 2022-06-29 21:28:47 +02:00
Marcelo Fabri 45a03dec20
Add back `void_function_in_ternary` rule (#3956) 2022-06-27 09:41:52 -07:00
Marcelo Fabri 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ösch 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ösch a20a75d422
Fix various shortcomings in relative path computation (#4005) 2022-06-24 02:25:37 -04:00
Danny Mösch 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ösch 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ösch 0d070a8c8c
Update result builder methods in unused_declaration rule fixing some false-positives (#4000) 2022-06-19 11:59:23 +02:00
Danny Mösch 86e765c418
Deprecate the `--path` option in favor of the positional `paths` argument (#3952)
There is no real benefit for this option. Files and folders to lint/analyze
can be passed to `swiftlint` as last arguments. There cannot be multiple
`--path` arguments. If there is more than one only the last path is considered.
2022-06-14 23:10:28 +02:00
Danny Mösch 323a249f70
Make `for_where` independent of order in structure dictionary (#3979) 2022-06-14 13:55:12 -04:00
Marcelo Fabri 4382ef49b9
Use URL(fileURLWithPath:isDirectory) to avoid file system call (#3976) 2022-05-26 21:54:23 +02:00
Jaehong Kang 809dcc6bdc
Prevent crash for private types named `_` in `type_name` rule (#3972) 2022-05-10 19:15:44 +02:00
Danny Mösch ca9217d5e1
Ignore array types if their associated `Index` is accessed (#3970) 2022-05-07 19:11:53 -04:00
Marcelo Fabri f880b66cbf
Rewrite `operator_usage_whitespace` with SwiftSyntax (#3962) 2022-05-06 16:48:57 -07:00
Marcelo Fabri ebc77391bc
Add workaround to avoid stack overflow in debug (#3963) 2022-05-01 14:57:28 -07:00
Danny Mösch 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 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 Mösch 291b500269
Analyze all files listed in the command even if the `--path` option is used (#3951) 2022-04-15 10:36:29 -04:00
coffmark 564c6ddb55
Lint all files listed in the command even if the `--path` option is used (#3923) 2022-04-13 15:13:08 -04:00
Chris Hale 9beef23175
Throw error on bad expiring todo date format (#3626) 2022-04-11 21:20:05 +02: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
JP Simard e92a3aeae9
fixup! fixup! Add `--in-process-sourcekit` command line flag 2022-03-31 12:49:12 -04:00
JP Simard 4c14678d77
fixup! Add `--in-process-sourcekit` command line flag 2022-03-31 11:42:42 -04:00
Juozas Valančius 62cc0f1a32
Add `--in-process-sourcekit` command line flag 2022-03-31 09:46:21 -04:00
JP Simard 89ebac11d5
Fix analyzer rules with Xcode 13.3 (#3921)
* Fix analyzer rules with Xcode 13.3

Looks like starting with Xcode 13.3 / Swift 5.6, cursor info requests
started canceling in-flight requests, so we need to pass
`key.cancel_on_subsequent_request: false` to bypass that.

Analyzer rules on Swift 5.6 are extremely slow, however. Not really
usable right now.

* Run analyzer rules one file at a time

* Add changelog entry
2022-03-28 11:58:34 -04:00
Danny Moesch fa2a0bab6c
Move StringView.byteOffset into generally accessible extension (#3917) 2022-03-25 07:27:50 +01:00
JP Simard a773c3ec21
Apply minor changes to the syntactic sugar rewrite (#3915)
* Improve docstrings for `StringView+SwiftSyntax.swift`
* Move changelog entry to correct section & reword
* Change parameter type from `Int` to `ByteCount`
* Move AbsolutePosition / ByteCount conversion to internal API
* Only warn once if syntax tree cannot be parsed
* Move Syntactic Sugar examples to a dedicated file
* Change SyntacticSugarRuleVisitor from SyntaxAnyVisitor to SyntaxVisitor
* Add `SugaredType` enum to help with the implement `SyntacticSugarRule`
2022-03-24 10:27:05 -04: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 83a86870bb
Fix false positives in `unused_closure_parameter` (#3916)
When using parameters with backticks.
2022-03-23 16:57:23 -04:00
Paul Taykalo d756541204
Rewrite SyntacticSugarRule using SwiftSyntax (#3866)
Rewrite SyntacticSugarRule with SwiftSyntax
2022-03-23 18:30:43 +02: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
JP Simard de3569cb3b
Update SwiftSyntax to 0.50600.0 (#3901)
Uses SwiftSyntax 5.5 on Linux when building with Swift 5.5. We use the 5.6 version of
SwiftSyntax when building with Swift 5.5 and 5.6 on macOS because we statically link
`lib_InternalSwiftSyntaxParser` thanks to
https://github.com/keith/StaticInternalSwiftSyntaxParser/releases/tag/5.6.

This keeps SwiftLint binaries portable across machines on macOS, regardless of
_where_ or even _if_ `lib_InternalSwiftSyntaxParser` is installed.

* Run TSan CI job with `--configuration release` to avoid stack overflows
* Add Swift 5.6 CI job
* Fix linker settings
2022-03-17 13:19:48 -04:00