Commit Graph

2174 Commits

Author SHA1 Message Date
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
Marcelo Fabri 0e5d838765 Support #unavailable in deployment_target rule (#3898)
Fixes #3896
2022-03-16 10:41:04 -04: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
tobias 811ca32c6d class_delegate_protocol: Add line break separator for protocol inheritance
clause to match format style with curly brackets on new line
2022-03-09 14:37:47 -05:00
Danny Moesch 6fa8ff6070 Exclude examples with complex language constructs from the rule documentation (#3880) 2022-03-08 16:04:51 -05:00
Marcelo Fabri f9b9c35c1f Fix regression in trailing_closure rule with Swift 5.6 (#3879)
Fixes #3848
2022-03-08 12:52:07 -08:00
JP Simard 2ae6a55ba4 Fix regression in unused_import rule when using Swift 5.6 (#3878)
Fixes https://github.com/realm/SwiftLint/issues/3849
2022-03-08 13:15:39 -05:00
JP Simard 28dd673c48 Use SwiftSyntax visitor to parse commands (#3872)
* Cache SwiftSyntax syntax trees
* Use SwiftSyntax visitor to parse commands
* Update changelog entry
* Cache commands
2022-03-08 12:33:06 -05:00
Marcelo Fabri 678c3483ed Fix regression in last_where rule with Swift 5.6 (#3874)
Fixes #3847
2022-03-08 07:53:56 -05:00
Marcelo Fabri 3f24998be5 Fix closure_parameter_position rule with Swift 5.6 (#3871)
Fixes #3845
2022-03-07 13:23:31 -08:00
Marcelo Fabri f19555f707 Fix empty_parentheses_with_trailing_closure with Swift 5.6 (#3870)
Fixes #3846
2022-03-07 13:39:57 -05:00
JP Simard a43e52aa91 Integrate Swift Syntax in the force_cast rule (#3867)
We've tried adding Swift Syntax support to SwiftLint in the past but had to turn it off in https://github.com/realm/SwiftLint/pull/3107 due to distribution and portability issues.

With https://github.com/keith/StaticInternalSwiftSyntaxParser it should be possible to avoid those issues by statically linking the internal Swift syntax parser so it's available no matter where users have Xcode installed on their computer.

By removing all calls to SourceKit (collecting comment commands + checking the current Swift version), there's a really significant performance improvement.

| Framework | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| SourceKit | 517.8 ± 8.3 | 505.5 | 531.1 | 6.59 ± 0.43 |
| SwiftSyntax | 78.6 ± 5.0 | 72.6 | 92.1 | 1.00 |

In practice, the SourceKit overhead will continue being there for as long as any rule being run is still looking up the SwiftLint syntax map though.
2022-03-07 12:51:24 -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
Goran Blažič 7b7754ad3b Ignore MARK in multiline comment (#3844)
Fixes #1749 and #3841
2022-03-04 11:33:12 -05:00
JP Simard 54a24638a2 Print minimum_fraction_length in description even when unset 2022-03-03 12:49:11 -05:00
Danny Moesch 0e7b588d50 Ignore meta class types in prefer_self_in_static_references rule (#3832) 2022-03-02 10:52:12 -05:00
Greg c09b6fe3ad fix typo (#3837) 2022-02-02 15:31:06 -05:00
JP Simard 2f2a4ad680 [ClosureEndIndentationRule] Fix crash with Swift 5.6 (#3831)
Fixes https://github.com/realm/SwiftLint/issues/3830
2022-01-27 17:36:31 -05:00
Steven 09f6f1bc83 Fix class_delegate_protocol false positives when using where clause (#3829) 2022-01-27 06:03:53 -08:00
JP Simard 006bb2a85e Sort implicit return configuration description (#3823)
To make the output deterministic
2022-01-24 17:13:12 -08:00
Danny Moesch a94d120839 Ignore prefer_self_in_static_references rule in extensions generally (#3813) 2022-01-24 09:57:57 -08:00
Danny Moesch 0f55447956 Use pre-defined set of extension kinds (#3814) 2022-01-24 09:55:01 -08:00
JP Simard 31872aaa3f Re-add 'weak_delegate' rule as opt-in
After feedback from users: https://github.com/realm/SwiftLint/pull/3809#issuecomment-1018859093
2022-01-21 16:57:13 -05:00
Danny Moesch d99be668c5 Ignore more locations of static references not using 'Self' in classes (#3771)
Static references with `Self` are not allowed to define

* default values of properties,
* annotation parameter values and
* default method parameter values

in classes.
2022-01-21 12:43:12 -08:00
JP Simard e3f232ec28 Fix convenience_type false positives when using actors (#3812)
Fixes https://github.com/realm/SwiftLint/issues/3761.
2022-01-21 19:54:59 +00: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
Sergei aff3536bb8 Fix the regex for expiring-todos. (#3803)
- Make "middle part" `.*` not so greedy with `?`.
- Use `(?!` negative look-ahead to improve matching.
- Added corresponding unit tests.

Co-authored-by: Sergei Shirokov <sshirokov@malwarebytes.com>
2022-01-21 17:42:17 +00:00
Ikko Ashimine 640efba68d Fix typo: implict -> implicit 2022-01-21 11:05:21 -05:00
Ikko Ashimine 3d7775de11 Fix typo in CommentSpacingRule.swift (#3795)
charcter -> character
2022-01-21 07:47:14 -08:00
Ethan Wong 5fd8ef38c1 Fix malformed doc for rule "InclusiveLanguage". 2022-01-21 10:45:15 -05:00
Paul Williamson 9e37d0fa44 Prevent false triggering of unused_closure_parameter when using list bindings (#3799) 2022-01-21 07:35:12 -08:00
grosem c90c329f12 Allow unused_setter_value for overrides (#3653)
Fixes #2585
2022-01-20 22:53:18 +00:00
JP Simard 027bdcdc95 Fix crash when parsing multi-line attributes with the attributes rule (#3776)
Fixes #3761
2021-12-06 16:08:53 +00:00
iressler 3da6502bac Fix false positive in legacy_objc_type when a non-legacy Objective-C type name begins with a legacy Objective-C type name. (#3752) 2021-11-29 12:36:27 -08:00
Danny Mösch 050473a0e1 Add optional prefer_self_in_static_references rule (#3732) 2021-11-29 18:42:53 +00:00
Kaitlin Mahar 5429ff642c Fix false positives with async closures for large_tuple rule (#3754) 2021-11-29 18:06:15 +00:00
Ikko Ashimine d97bf0951e Fix typo in StrictFilePrivateRule.swift (#3737)
occurences -> occurrences
2021-11-29 09:47:17 -08:00
JP Simard 2544d7b945 [unused_import] Fix SwiftShims being considered a used import (#3766) 2021-11-29 17:07:38 +00:00
Paul Taykalo 945efde5f5 Prevent multiple recalculations of capture groups ranges (#3745) 2021-10-15 02:38:18 +03:00
Paul Taykalo a87aee1771 Colon rule should ignore cases when comment is in function argument (#3740) 2021-10-14 16:05:11 +03:00
Marcelo Fabri 383e5b5bc2 Handle get async and get throws in implicit_getter (#3743)
Fixes #3684
2021-10-12 10:32:34 -07:00
Artem Garmash 67114bb729 Exclude id from identifier_name by default (#3730) 2021-10-04 21:13:40 +00:00
Paul Taykalo 6b8c4442b0 Speed up "computed accessors order" rule (#3727) 2021-10-01 03:07:57 +03:00
Naruki Chigira e4ff164f64 Fix redundant_optional_initialization autocorrect (#3717)
* Fix autocorrect for redundant_optional_initialization in case observer's brace exists.
2021-09-30 23:15:53 +00:00
Marcelo Fabri b63a60df14 Fix false positive in unneeded_break_in_switch (#3725)
Fixes #3724
2021-09-29 12:00:08 -07:00