Commit Graph

2878 Commits

Author SHA1 Message Date
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 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
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 1abc50304c Use alternate implementation of glob with globstar support (#3892)
Adapted from https://gist.github.com/efirestone/ce01ae109e08772647eb061b3bb387c3

The implementation from Pathos seems buggy.

Fixes https://github.com/realm/SwiftLint/issues/3891
2022-03-11 13:24:39 -05:00
Fumito Nakazawa 2ae22d06a2 Support recursive globs (#3843)
ref: https://github.com/realm/SwiftLint/issues/3789

## Overview
Support glob recursive by using [Pathos](https://github.com/dduan/Pathos)
- Introduce Pathos
- Replace glob logic
- Fix some test cases
2022-03-10 21:56:43 -05: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
JP Simard 0691a2e7e4 release 0.46.5 2022-03-08 16:35:33 -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
JP Simard f3712b2b93 release 0.46.4 2022-03-07 11:15:27 -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
JP Simard 02675a9c09 Fix typo in doc comment: delimeter -> delimiter 2022-03-07 09:27:28 -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 d77d23cbeb Add option to exclude examples from the rule documentation (#3834)
The option can be used if an example has mainly been added as another test case, but is not suitable
as a user example. User examples should be easy to understand. They should clearly show where and
why a rule is applied and where not. Complex examples with rarely used language constructs or
pathological use cases which are indeed important to test but not helpful for understanding can be
hidden from the documentation with this option.
2022-03-02 10:55:42 -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
JP Simard 9c81e1a93a release 0.46.3 2022-02-22 15:29:40 -05:00
HA Pors 8d0aeb995d Generate fingerprint with relativefile (#3860)
* Change fingerprint generation to use relativeFile instead of location in order to support CI/CD on multiple machines.

* Created copy of location with relativeFile instead of file to generate fingerprint.

Co-authored-by: Henk Pors <hpors@anwb.nl>
2022-02-17 08:29:16 -08:00
Natan Rolnik fe905f8ae9 Fix default rules section in documentation (#3857)
While browsing the rules documentation, I noticed **many** rules were both in the Default Rules and in the Opt In Rules section.

After looking into it, the docs of the `drop(while predicate: (Element) throws -> Bool` function states:

A closure that takes an element of the sequence as its argument and returns true if the element should be skipped or false if it should be included. **Once the predicate returns false it will not be called again.**

This caused the `defaultRuleDocumentations` array to contain almost all `ruleDocumentation`.
2022-02-15 06:23:05 -08:00
Greg c09b6fe3ad fix typo (#3837) 2022-02-02 15:31:06 -05:00
Danny Moesch f9be00421e Rename values for "Enabled by default" property (#3833) 2022-01-29 13:35:09 -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
JP Simard b4a54f32df release 0.46.2 2022-01-27 09:16:25 -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 61c5351978 release 0.46.1 2022-01-21 16:59:57 -05: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
JP Simard 17779cbfd4 release 0.46.0 2022-01-21 15:57:48 -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