Commit Graph
488 Commits
Author SHA1 Message Date
Martin Redington ca43d2359b Fix unit test configuration (#4847) 2023-03-30 22:46:31 +02:00
Danny Mösch 7ac128c83d Enable direct_return rule in the repository 2023-03-12 14:36:07 +01:00
Danny Mösch 1bf2f25e40 Get rid of some disabled commands (#4807) 2023-03-11 08:20:47 -05: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 1c3c62e422 Add new invalid_swiftlint_command rule (#4546) 2023-03-04 13:53:27 +01:00
Martin Redington d6e3bbb64d Add "all" pseudo-rule which enables all opt-in rules (#4544) 2023-03-04 13:49:00 +01:00
Danny Mösch c9b1b961f5 Fix some issues in direct_return rule (#4783) 2023-02-25 02:48:31 -05:00
JP Simard 2f0e537f9b Update SwiftSyntax to latest development snapshot (#4759)
* Merge `spacedBinaryOperator` and `unspacedBinaryOperator`

* New contextual keyword enums

* Update for removed `UnavailabilityConditionSyntax`

* Handle how attributes are now defined

This partially reverts commit 325d0ee1e4.

* Handle removal of `TokenListSyntax`

* Update `Package.swift`

* Extract some SwiftSyntax helpers

* Update to `0.50900.0-swift-DEVELOPMENT-SNAPSHOT-2023-02-06-a`

* Skip attributes with keypath arguments in `attributes` rule

To preserve the rule's existing behavior.

* Limit unowned_variable_capture violations to capture lists

* Add changelog entries
2023-02-20 10:51:31 -05:00
Danny Mösch f3e5557de9 Stop triggering strict_fileprivate rule on protocol implementations (#4705) 2023-02-18 13:23:26 +01:00
Marcelo Fabri 0163ffd328 Cache folded syntax tree (#4744) 2023-02-06 10:39:36 -08:00
Danny Mösch 5eed8fe91b Enable if_let_shadowing rule and fix all violations (#4247) 2023-01-31 22:31:38 +01:00
JP Simard 0750d5d465 Extract EnumDeclSyntax.supportsRawValues helper (#4727)
I'll want to use this elsewhere shortly.

Also adds `CGFloat` to the raw value types since we were missing that
one.
2023-01-27 16:46:54 -05:00
JP Simard 84c6d200b6 Clean up unused initializers (#4726)
Found with the upcoming improve dead code detection.
2023-01-27 16:31:56 -05:00
Jimmy Arts eda0d92f44 Make forceExclude work with directly specified files (#4609) 2022-12-22 21:15:08 +01:00
Julio Carrettoni 3745704c03 Add rule for single space after period on comments (#4624) 2022-12-15 23:27:33 +01:00
Danny Mösch 4adabd8e4b Print a warning for Analyzer rules misplaced in the configuration (#4620) 2022-12-05 18:03:54 -05:00
Martin Redington 7a8b2d1dab Add test_parent_class option to more test rules (#4262) 2022-12-01 18:56:13 +01: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 4ccf9eebb4 Fix line count calculation for multiline string literals (#4587)
Fixes https://github.com/realm/SwiftLint/issues/4585

Update body length rule thresholds for SwiftLint
2022-11-24 16:40:51 +00:00
JP Simard ba8899714d Reduce visibility of custom rules (#4553) 2022-11-16 16:14:50 -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
JP Simard 04d1184904 Remove structure cache (#4541) 2022-11-10 14:53:16 -05:00
Danny Mösch 1edef5ebdc Trigger prefer_self_in_static_references rule on constructor calls (#4519) 2022-11-06 14:55:28 +01:00
Danny Mösch 7e8a3ae2ac Introduce onlyElement property on Collection (#4518) 2022-11-06 07:37:44 -05:00
Marcelo Fabri 45ac3dcdff Rewrite required_enum_case with SwiftSyntax (#4521) 2022-11-06 01:26:11 -08:00
JP Simard e97119efec Migrate orphaned_doc_comment to use SwiftSyntax classifications (#4461) 2022-11-02 15:55:47 +00:00
JP Simard f1f6a3c4a0 Add ByteSourceRange.toSourceKittenByteRange() helper (#4500)
This will be useful for other rules too.
2022-11-01 14:13:29 -04:00
Marcelo Fabri 20bfe264f5 Rewrite overridden_super_call and prohibited_super_call with SwiftSyntax (#4493)
* Rewrite `overridden_super_call` with SwiftSyntax

* Rewrite `prohibited_super_call` too
2022-10-30 20:28:25 -07:00
JP Simard d551cb8c16 Update SwiftSyntax (#4480)
Moves syntax classifications to a new IDEUtils module.
2022-10-28 09:23:06 -04:00
JP Simard 1b59a3f168 Cache location converters (#4481)
This is 2%-12% faster according to OSSCheck
2022-10-26 12:37:16 -04:00
Marcelo Fabri c1f2b615e2 Rewrite redundant_optional_initialization with SwiftSyntax (#4409) 2022-10-23 20:30:29 -04:00
Marcelo Fabri 53752f58ad Rewrite redundant_set_access_control with SwiftSyntax (#4395) 2022-10-23 15:30:01 -07:00
JP Simard cb79584c7d Migrate comment_spacing to use SwiftSyntax classifications (#4460) 2022-10-23 17:39:38 -04:00
JP Simard 1ee5154687 Update SwiftSyntax to fa7ff05 (#4455)
There's a new SwiftParserDiagnostics module and the rewriter visit
function signatures changed.
2022-10-23 11:56:22 -04:00
Marcelo Fabri cee4af098f Migrate prefer_zero_over_explicit_init to SwiftSyntax (#4448) 2022-10-23 04:53:00 -07:00
Marcelo Fabri 9c8708bc01 Extract common SwiftSyntax extensions (#4445) 2022-10-23 00:54:18 -07:00
JP Simard 5af8e3dd68 Rewrite lower_acl_than_parent with SwiftSyntax (#4432)
And fix violations in SwiftLint.
2022-10-21 09:31:10 -04:00
Marcelo Fabri 04d7ce05ca Rewrite joined_default_parameter with SwiftSyntax (#4411) 2022-10-18 20:12:56 -07:00
Marcelo Fabri 89c227ecaa Migrate weak_delegate rule to SwiftSyntax (#4389)
* Migrate `weak_delegate` rule to SwiftSyntax

* Remove unused declarations
2022-10-16 22:57:42 -07:00
JP Simard 7624059caa Rewrite unused_closure_parameter with SwiftSyntax (#4371) 2022-10-14 03:35:51 -04:00
JP Simard fa6bf50a22 Rethink body line count calculation (#4369)
A long-standing limitation with SourceKit's "editor open" request is
that we weren't able to get certain tokens, such as braces, brackets and
parentheses.

This meant that this code block would be counted as two lines:

```swift
print(
  "hi"
)
```

because the trailing `)` would be treated as a whitespace line.

This meant that our "body length" family of rules that measure the
effective line count of declarations like functions, types or closures
would often significantly under-count the number of content lines in a
body.

Now with SwiftSyntax, we can get all tokens, including the ones
SourceKit was previously ignoring, so we can get much more accurate line
counts when ignoring whitespace and comments.

In addition, we weren't very thorough in how we measured body length.

As an exercise, how many lines long would you say the body of this
function is?

```swift
func hello() {
  print("hello")
}
```

Does the body span one line or three lines?

I propose that we consistently ignore the left and right brace lines
when calculating the body line count of these scopes so that we measure
body line counts like this:

```swift
// 1 line
{ print("foo") }
// 1 line
{
}
// 1 line
{
  print("foo")
}
// 2 lines
{
  let sum = 1 + 2
  print(sum)
}
```

Now with those changes in place, in order to keep the default
configuration thresholds to similar levels as before, we need to adjust
them slightly. Here's what I'm suggesting:

|Rule|Before|After|
|-|-|-|
|closure_body_length|20/100|30/100|
|function_body_length|40/100|50/100|
|type_body_length|200/350|250/350|

This is a pretty significant breaking change and I suspect we'll hear
from users who are surprised that some of their declarations now exceed
the rule limits, but I believe this new approach to calculating body
lines is more correct and intuitive compared to what we've had until
now.

OSSCheck is also going to report a bazillion changes with this, which is
expected given the scope of this change.
2022-10-14 03:16:26 -04:00
JP Simard 48fde2321f Rewrite contains_over_first_not_nil & last_where with SwiftSyntax (#4366)
Replace `MemberAccessExprSyntax.functionCallBase` with
`ExprSyntax.asFunctionCall` so we can use it in more places.

Move `TokenKind.isEqualityComparison` into `SwiftSyntax+SwiftLint.swift`
2022-10-13 15:59:30 +00:00
JP Simard 8d29b21ecb Rewrite sorted_first_last & first_where with SwiftSyntax (#4365)
Add a `functionCallBase` helper.
2022-10-13 15:30:22 +00:00
JP Simard 33f6ee1f36 Update SwiftSyntax (#4363)
Noteworthy:

* https://github.com/apple/swift-syntax/pull/912
* https://github.com/apple/swift-syntax/pull/932
2022-10-13 10:28:00 -04: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 9aaeff67d0 Add SyntaxProtocol.isContainedIn(regions:locationConverter:) helper (#4356) 2022-10-12 19:50:32 +00:00
JP Simard b849234572 Remove Configuration.FileGraph.Vertix.configurationString property (#4354)
It's unused and for large configuration files this uses unnecessary
memory.
2022-10-12 17:16:27 +00:00
JP Simard 0282bf1923 Remove optionality in getting syntax tree and source location converter (#4353)
Parsing does not throw errors.
See https://github.com/apple/swift-syntax/pull/912.
2022-10-12 12:50:17 -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