Commit Graph

5952 Commits

Author SHA1 Message Date
Marcelo Fabri 286e59a0e6
Fix false positive in `nsobject_prefer_isequal` rule (#4408)
Fixes #4404
2022-10-17 22:26:37 -07:00
Marcelo Fabri db910946dc
Simplift `DiscouragedNoneNameRule` implementation (#4407) 2022-10-18 04:43:40 +00:00
JP Simard 1837ae59cb
Rewrite `legacy_objc_type` with SwiftSyntax (#4372) 2022-10-17 17:29:09 -04:00
Marcelo Fabri 03848ce583
Make `DiscouragedNoneNameRule` opt-in again (#4403)
I mistakenly made it enable by default when rewriting it
2022-10-17 17:01:42 -04:00
JP Simard e9f2248072
Remove dead code in `DiscouragedDirectInitRule.swift` (#4402) 2022-10-17 18:25:02 +00:00
Marcelo Fabri 9a9629c1e8
Rewrite `discouraged_direct_init` with SwiftSyntax (#4397) 2022-10-17 10:47:46 -07:00
JP Simard 1b86aa7eeb
Simplify `SwitchCaseAlignmentRule` (#4399)
By using `ReasonedRuleViolation`, `SwiftSyntaxRule` and `makeVisitor()`.
2022-10-17 10:59:07 -04:00
JP Simard 8ec6e0eefc
Update SwiftSyntax (#4398)
https://github.com/apple/swift-syntax/pull/938 was impacting some
corrections in Lyft's codebase.
2022-10-17 09:42:02 -04:00
Marcelo Fabri 937228d1ba
Add `function_parameter_count` to CHANGELOG 2022-10-17 00:44:43 -07:00
Marcelo Fabri 0504d2c3f9
Migrate `function_parameter_count` to SwiftSyntax (#4394) 2022-10-17 00:44:17 -07:00
Marcelo Fabri 07be57027a
Add more rewritten rules to CHANGELOG 2022-10-16 23:55:42 -07:00
Marcelo Fabri 844b7c02dd
Rewrite `trailing_comma` rule with SwiftSyntax (#4385) 2022-10-16 23:36:11 -07:00
Marcelo Fabri b4ec2d360d
Rewrite `unused_control_flow_label` with SwiftSyntax (#4339) 2022-10-16 22:58:01 -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
Marcelo Fabri 6f4b75b0f6
Migrate `legacy_constructor` to SwiftSyntax (#4386) 2022-10-16 22:56:25 -07:00
Marcelo Fabri 4522005ab4
Migrate `implicitly_unwrapped_optional` to SwiftSyntax (#4278)
* Migrate `implicitly_unwrapped_optional` to SwiftSyntax

* Update Source/SwiftLintFramework/Rules/RuleConfigurations/ImplicitlyUnwrappedOptionalConfiguration.swift

Co-authored-by: Danny Mösch <danny.moesch@icloud.com>

* Fix after rebase

Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
2022-10-16 22:55:32 -07:00
Marcelo Fabri 56a23448c3
Migrate `unused_enumerated` to SwiftSyntax (#4391) 2022-10-16 22:34:26 -07:00
Marcelo Fabri bb1de21059
Convert `enum_case_associated_values_count` to SwiftSyntax (#4393) 2022-10-16 22:34:12 -07:00
Marcelo Fabri 89c24cd52d
Rewrite `fatal_error_message` rule with SwiftSyntax (#4230) 2022-10-16 20:52:09 -04:00
Danny Mösch 0fbd03cf2b
Require visitors to exist (#4383) 2022-10-16 18:40:12 +02:00
Marcelo Fabri 8b96aa0585
Make UnavailableConditionRule conform to SwiftSyntaxRule (#4388) 2022-10-16 07:49:36 -07:00
Marcelo Fabri 7ff3094821
Support .focused() in keys for corrections (#4384) 2022-10-16 07:50:10 -04:00
Danny Mösch f8e5339c69
Introduce `ReasonedRuleViolation` type to associate a reason with a violation position (#4379) 2022-10-16 12:53:38 +02:00
Marcelo Fabri 9959f971f9
Add way to preprocess syntaxTree in SwiftSyntaxRule (#4381)
* Add way to preprocess syntaxTree in SwiftSyntaxRule

* Update Source/SwiftLintFramework/Protocols/SwiftSyntaxRule.swift

Co-authored-by: Danny Mösch <danny.moesch@icloud.com>

* Update Source/SwiftLintFramework/Protocols/SwiftSyntaxRule.swift

Co-authored-by: Danny Mösch <danny.moesch@icloud.com>

Co-authored-by: Danny Mösch <danny.moesch@icloud.com>
2022-10-16 01:40:02 -07:00
Danny Mösch dcf03f5987
Fix compilation errors (#4380) 2022-10-15 22:49:16 -04:00
Marcelo Fabri 860b027005
Migrate `private_over_fileprivate` to SwiftSyntax (#4376) 2022-10-15 14:49:16 -07:00
Marcelo Fabri 4aa9588454
Rewrite `function_default_parameter_at_end` with SwiftSyntax (#4320)
* Rewrite `function_default_parameter_at_end` with SwiftSyntax

* Fix oss-check issues

* Handle optional closures

* Handle other closure types

* Fix violation

* Handle @autoclosure
2022-10-15 14:48:59 -07:00
Marcelo Fabri 37bf2c9168
Rewrite `discouraged_none_name` with SwiftSyntax (#4377)
* Rewrite `discouraged_none_name` with SwiftSyntax

* Handle `none`
2022-10-15 14:48:38 -07:00
Danny Mösch bd8c9e5bcb
Provide syntax visitor base class allowing for convenient skipping of declaration nodes (#4310) 2022-10-15 19:03:49 +02:00
Marcelo Fabri 510cb39b11
Rewrite `quick_discouraged_pending_test` with SwiftSyntax (#4378) 2022-10-15 04:21:38 -07:00
Marcelo Fabri c9ef157c29
Rewrite `conditional_returns_on_newline` with SwiftSyntax (#4340)
* Rewrite `conditional_returns_on_newline` with SwiftSyntax

* Keep original behavior

* PR feedback
2022-10-15 02:25:56 -07:00
Marcelo Fabri e74e11533c
Rewrite `valid_ibinspectable` rule with SwiftSyntax (#4322)
* Rewrite `valid_ibinspectable` rule with SwiftSyntax

* Fix false positives
2022-10-14 20:32:03 -07:00
Danny Mösch a7ff8a8d76
Rename `if_let_shadowing` rule to `shorthand_optional_binding` (#4334) 2022-10-14 21:47:37 +00:00
JP Simard 7585aef910
Rewrite `reduce_boolean` with SwiftSyntax (#4375) 2022-10-14 07:03:30 -04:00
JP Simard f04e28cbf8
Rewrite `switch_case_alignment` with SwiftSyntax (#4373) 2022-10-14 10:06:54 +00:00
JP Simard 39bb05f7d1
Rewrite "body length" rules with SwiftSyntax (#4370)
- `closure_body_length`
- `function_body_length`
- `type_body_length`
2022-10-14 03:50:39 -04: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 5c3d4c1dab
Rewrite `legacy_hashing` with SwiftSyntax (#4367) 2022-10-13 16:27:54 +00:00
JP Simard 02b5a034d2
Rewrite `is_disjoint` with SwiftSyntax (#4368) 2022-10-13 12:22:57 -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 3bae16bee5
Rewrite `contains_over_filter_is_empty` with SwiftSyntax (#4364) 2022-10-13 10:45:40 -04: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
JP Simard de0b91cd5a
Print violations in realtime if progress with an output file (#4362) 2022-10-13 06:23:24 +00:00
JP Simard 4e3c750086
Rewrite `attributes` with SwiftSyntax (#4359)
Not 100% the same as it previously was, but I think all the changes
reported by OSSCheck are improvements or neutral.
2022-10-13 00:40:24 -04:00
JP Simard 2f300502c0
Fix changelog formatting (#4361) 2022-10-13 00:36:25 -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
Marcelo Fabri 99436906cd
Rewrite `self_in_property_initialization` with SwiftSyntax (#4343) 2022-10-12 20:58:57 -07:00
JP Simard 7653b2d635
Update link to video presentation in readme (#4360)
This link has had a broken video resource for years.

The video was just re-published.
2022-10-12 22:49:45 -04:00