Commit Graph
474 Commits
Author SHA1 Message Date
Jimmy ArtsandGitHub eda0d92f44 Make forceExclude work with directly specified files (#4609) 2022-12-22 21:15:08 +01:00
Julio CarrettoniandGitHub 3745704c03 Add rule for single space after period on comments (#4624) 2022-12-15 23:27:33 +01:00
Danny MöschandGitHub 4adabd8e4b Print a warning for Analyzer rules misplaced in the configuration (#4620) 2022-12-05 18:03:54 -05:00
Martin RedingtonandGitHub 7a8b2d1dab Add test_parent_class option to more test rules (#4262) 2022-12-01 18:56:13 +01:00
92304cdd98 Fix building tests in Xcode (#4607)
Co-authored-by: JP Simard <jp@jpsim.com>
2022-11-30 10:33:33 -05:00
JP SimardandGitHub 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 SimardandGitHub ba8899714d Reduce visibility of custom rules (#4553) 2022-11-16 16:14:50 -05:00
JP SimardandGitHub 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 SimardandGitHub 04d1184904 Remove structure cache (#4541) 2022-11-10 14:53:16 -05:00
Danny MöschandGitHub 1edef5ebdc Trigger prefer_self_in_static_references rule on constructor calls (#4519) 2022-11-06 14:55:28 +01:00
Danny MöschandGitHub 7e8a3ae2ac Introduce onlyElement property on Collection (#4518) 2022-11-06 07:37:44 -05:00
Marcelo FabriandGitHub 45ac3dcdff Rewrite required_enum_case with SwiftSyntax (#4521) 2022-11-06 01:26:11 -08:00
JP SimardandGitHub e97119efec Migrate orphaned_doc_comment to use SwiftSyntax classifications (#4461) 2022-11-02 15:55:47 +00:00
JP SimardandGitHub f1f6a3c4a0 Add ByteSourceRange.toSourceKittenByteRange() helper (#4500)
This will be useful for other rules too.
2022-11-01 14:13:29 -04:00
Marcelo FabriandGitHub 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 SimardandGitHub d551cb8c16 Update SwiftSyntax (#4480)
Moves syntax classifications to a new IDEUtils module.
2022-10-28 09:23:06 -04:00
JP SimardandGitHub 1b59a3f168 Cache location converters (#4481)
This is 2%-12% faster according to OSSCheck
2022-10-26 12:37:16 -04:00
Marcelo FabriandGitHub c1f2b615e2 Rewrite redundant_optional_initialization with SwiftSyntax (#4409) 2022-10-23 20:30:29 -04:00
Marcelo FabriandGitHub 53752f58ad Rewrite redundant_set_access_control with SwiftSyntax (#4395) 2022-10-23 15:30:01 -07:00
JP SimardandGitHub cb79584c7d Migrate comment_spacing to use SwiftSyntax classifications (#4460) 2022-10-23 17:39:38 -04:00
JP SimardandGitHub 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 FabriandGitHub cee4af098f Migrate prefer_zero_over_explicit_init to SwiftSyntax (#4448) 2022-10-23 04:53:00 -07:00
Marcelo FabriandGitHub 9c8708bc01 Extract common SwiftSyntax extensions (#4445) 2022-10-23 00:54:18 -07:00
JP SimardandGitHub 5af8e3dd68 Rewrite lower_acl_than_parent with SwiftSyntax (#4432)
And fix violations in SwiftLint.
2022-10-21 09:31:10 -04:00
Marcelo FabriandGitHub 04d7ce05ca Rewrite joined_default_parameter with SwiftSyntax (#4411) 2022-10-18 20:12:56 -07:00
Marcelo FabriandGitHub 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 SimardandGitHub 7624059caa Rewrite unused_closure_parameter with SwiftSyntax (#4371) 2022-10-14 03:35:51 -04:00
JP SimardandGitHub 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 SimardandGitHub 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 SimardandGitHub 8d29b21ecb Rewrite sorted_first_last & first_where with SwiftSyntax (#4365)
Add a `functionCallBase` helper.
2022-10-13 15:30:22 +00:00
JP SimardandGitHub 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öschandGitHub 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 SimardandGitHub 9aaeff67d0 Add SyntaxProtocol.isContainedIn(regions:locationConverter:) helper (#4356) 2022-10-12 19:50:32 +00:00
JP SimardandGitHub 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 SimardandGitHub 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 SimardandGitHub 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 SimardandGitHub 87e9757af2 Update SwiftSyntax (#4346)
I think there might have been changes impacting the `static_operator`
rule, so I want to look more into those here.

Remove workaround for https://github.com/apple/swift-syntax/issues/888
2022-10-11 21:12:29 -04:00
Marcelo FabriandGitHub 6998d8af23 Migrate shorthand_operator rule to SwiftSyntax (#4336)
* Migrate `shorthand_operator` rule to SwiftSyntax

* Remove unneeded imports
2022-10-10 21:28:55 -07:00
JP SimardandGitHub fe6a930bd4 Use os_unfair_lock instead of NSLock on Darwin (#4330) 2022-10-07 20:42:22 +00:00
JP SimardandGitHub 1a76a882ca Ignore incorrect keypath parser diagnostics (#4325)
Works around https://github.com/apple/swift-syntax/issues/888
2022-10-07 10:33:13 -04:00
JP SimardandGitHub a6c90dd942 Rewrite legacy_cggeometry_functions with SwiftSyntax (#4309) 2022-10-06 15:16:49 -04:00
JP SimardandGitHub d6fd754679 Rewrite contains_over_range_nil_comparison with SwiftSyntax (#4225)
Use SwiftOperators.
2022-10-06 01:18:31 -04:00
JP SimardandGitHub 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
JP SimardandGitHub 2388e49190 Use SwiftSyntax's new SwiftParser (#4216) 2022-10-01 15:05:36 -04:00
tillhainbachandGitHub a9ec894caf Add exceptions to weak_delegate rule (#3599) 2022-09-10 10:07:43 -04:00
Danny MöschandGitHub 311a724c3c Get rid of optional return value (#4187) 2022-09-07 18:18:34 -04:00
Ryan ColeandGitHub c34955ca64 Add accessibility_trait_for_button rule (#3989) 2022-09-06 21:44:09 +00:00
JP SimardandGitHub 4bc6588f38 Add --output option to lint and analyze commands (#4148)
To write to a file instead of to stdout.

Addresses https://github.com/realm/SwiftLint/issues/4048
2022-08-31 17:34:37 -04:00
Danny MöschandGitHub 9875ab904b Print autocorrected STDIN input to STDOUT (#4132) 2022-08-28 23:17:20 +02:00
JP SimardandGitHub 3037946bbc Migrate ClosureSpacingRule to SwiftSyntax (#4092)
Fixes #4090. Continued from #4091.
2022-08-15 18:27:43 +00:00