Commit Graph

18 Commits

Author SHA1 Message Date
Martin Redington 7623f1e730 Enable more rules in SwiftLint's own .swiftlint.yml (#5532) 2024-04-27 18:43:08 +02:00
JP Simard a7bc9e20c7 Move built-in rules to new SwiftLintBuiltInRules module (#4950) 2023-04-27 11:16:01 -04:00
JP Simard 4c04cdafa7 Introduce SwiftLintTestCase
To consistently set up rules before tests
2023-04-25 12:28:50 -04:00
Danny Mösch e64e82d80d Get rid of periods finishing rule descriptions 2023-01-10 22:29:13 +01: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 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
Marcelo Fabri f880b66cbf Rewrite operator_usage_whitespace with SwiftSyntax (#3962) 2022-05-06 16:48:57 -07: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
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
JP Simard bf2790df54 Enable CommentSpacingRule by default
And fix violations in SwiftLint
2020-11-10 12:50:39 -05:00
Zev Eisenberg fcf848608e Add Inline test failure messages (#3040)
* Add Example wrapper in order to display test failures inline when running in Xcode.
* Stop using Swift 5.1-only features so we can compile on Xcode 10.2.
* Wrap strings in Example.
* Add Changelog entry.
* Wrap all examples in Example struct.
* Better and more complete capturing of line numbers.
* Fix broken test.
* Better test traceability.
* Address or disable linting warnings.
* Add documentation comments.
* Disable linter for a few cases.
* Limit mutability and add copy-and-mutate utility functions.
* Limit scope of mutability.
2020-02-02 10:35:37 +02:00
Timofey Solonin 735567dcb4 Make modifier_order rule autocorrectable (#2521)
* #2353 - Move violating modifiers search to a private function

* #2353 - Add offset and length to the ModifierDescription

* #2353 - Make modifier_oder rule correctable

* #2353 - Add modifier_oder rule correction tests

* #2353 - Upadte the changelog

* #2353 - Add missing Foundation import

* #2353 - Fix linux tests

* Small edits to ModifierOrderRule and changelog entry
2018-12-23 19:53:38 -08:00
JP Simard 0e862ca9c4 Enable vertical whitespace rules in SwiftLint
and fix violations
2018-12-02 14:01:23 -08:00
Timofey Solonin efa68177b2 #2435 - Make modifier_order rule rely on an explicit set of rules (#2458)
* #2435 - Adjust modifier_order rule to require explicit modifier order specified to conclude a violation

* #2435 - Move modifier order rule examples to a separate file

* #2435 - Add modifier interference tests

* #2435 - Fix whitespaces

* Minor edits

* Add changelog entry
2018-11-28 15:10:49 -08:00
Marcelo Fabri af588ee4be Add test to LinuxMain 2018-07-19 08:17:12 -07:00
Daniel Metzing 8d7ac963bc Append failure reason to description 2018-07-09 21:06:15 +02:00
JP Simard 6ff33e675b Refactor 2018-05-05 16:24:54 -07:00
Daniel Metzing 61259692ed Removing s from rule name 2018-04-27 08:59:02 +02:00