Commit Graph

2085 Commits

Author SHA1 Message Date
Artem Garmash b679b8d75c Add check for return type Never 2020-11-09 12:18:42 +03:00
Paul Taykalo ba58d571d8
Add option that allows skipping aligned constants (#3391) 2020-11-08 10:07:24 -05:00
Marcelo Fabri 0e29701aba
Merge pull request #3410 from realm/mf-bugfix-3398
Fix false positive in `toggle_bool` rule
2020-11-08 05:23:57 -08:00
Marcelo Fabri 551cf2da3c Fix false positive in `toggle_bool` rule 2020-11-08 04:57:59 -08:00
Marcelo Fabri 7ccda8eb23 Validate closures outside of function calls in unused_closure_parameter
Fixes #1082
2020-11-08 04:47:35 -08:00
Marcelo Fabri c8596a647a Add prefer_nimble opt-in rule
Fixes #3293
2020-11-08 00:09:51 -08:00
Paul Taykalo 1b3e9945af
Fix inconsistency in `operator_usage_whitespace` rule (#3388)
This Fixes case when the right part of the expression is an array or a string
Previously, strings and comments tokens were ignored.
In the current implementation, matching done first and then those are filtered if the operator is within the string token
2020-11-07 23:16:44 -05:00
Dalton Claybrook d305e03905
Add `inclusive_language` rule (#3243)
Current events have renewed the conversation in our community about the roles of terminology with racist connotations in our software. Many companies and developers are now taking appropriate steps to remove this terminology from their codebases and products. (e.g. [GitHub](https://twitter.com/natfriedman/status/1271253144442253312)) This small rule prevents the use of declarations that contain any of the terms: whitelist, blacklist, master, and slave. It may be appropriate to add more terms to this list now or in the future.
2020-11-07 22:03:08 -05:00
Zev Eisenberg 87bf6c6a6b
Fix convenience type false positives (#3062) 2020-11-07 20:12:09 -05:00
JP Simard 390e9a2423
Remove UnneededNotificationCenterRemovalRule (#3407)
See https://github.com/realm/SwiftLint/issues/3338 for detailed
motivation.
2020-11-07 18:59:33 -05:00
Paul Taykalo 693ee2cae9
Add Isnot Empty extension in the Swift Framework (#3387) 2020-11-07 18:42:55 -05:00
Dalton Claybrook 580314d21e
'nslocalizedstring_key' now validates the comment argument in addition to the key argument (#3373) 2020-11-07 18:10:30 -05:00
JP Simard c8d8d913b9
Fix incorrect violation message for line length violations (#3406) 2020-11-07 18:01:04 -05:00
Quinn Taylor 865b59f0c8
Fix some missed cases in rule `unavailable_function`. (realm#3374) (#3375) 2020-11-07 17:36:26 -05:00
JP Simard 2dcce6b184
[AttributesRule] Fix parameterized attributes (#3405)
Some attributes are parameterized, such as `@objc(name)`. Previously
these reported `attributes` violations because their contents weren't
included in the configuration, which would just have `@objc`.
2020-11-07 16:57:57 -05:00
Zsolt Kovács ac2c5e4054
Allow opening brace on newline in case of multiline function (#3068) 2020-11-07 16:02:17 -05:00
JP Simard b005920cc5
Improve compilation times (#3404)
By speeding up a handful of the longest expressions to compile.
2020-11-07 12:16:25 -08:00
JP Simard d628c41665
[IdentifierNameRule] Allow "allowed symbols" as first character (#3403)
This means that if `allowed_symbols` contains `_`, you can now write
identifiers like `let _myLet`.

Fixes https://github.com/realm/SwiftLint/issues/3306
2020-11-07 09:54:04 -08:00
Keith Smiley 05344f5fed
Fix DuplicateImportsRule's support for import attributes (#3402)
* Fix DuplicateImportsRule's support for import attributes

* update changelog

* Fix changelog
2020-11-05 10:45:01 -08:00
Keith Smiley 51084adf82
Remove @IBOutlet and @IBInspectable from UnusedDeclarationRule (#3184) 2020-11-05 08:21:54 -08:00
Sam e6df1d32e1
Use indentation_width severity configuration (#3397)
* Use the severity from the configuration

It was previously using a hardcoded value, that of the default configuration.

* Update CHANGELOG.md

* Correctly format CHANGELOG addition
2020-10-31 11:50:43 +02:00
Iulian Onofrei 1950abb3b7
Fix incomplete example (#3396) 2020-10-28 12:45:00 -07:00
hank121314 9afc3bbfd9
[Fix] `UnusedCaptureListRule`: unowned self in @escaping closures (#3392)
* [Fix] `UnusedCaptureListRule`: should also handle unowned self
* [Docs] `CHANGELOG.md`: update.
2020-10-24 21:10:18 +03:00
Paul Taykalo 662db7be39
Fix correct .zero autocorrection (#3386) 2020-10-19 14:27:47 -07:00
Keith Smiley 5d6e25ae5f
Add TestCaseAccessibilityRule (#3376)
Co-authored-by: JP Simard <jp@jpsim.com>
2020-10-12 08:59:45 -07:00
Sven Münnich da408b5901
Fix some false positives in rule `explicit_self` (#3368) 2020-09-25 09:23:03 -07:00
JP Simard 15c25abc47
Update SourceKitten to 0.30.1 (#3367) 2020-09-23 08:34:46 -07:00
JP Simard 2731f994d8
Fix issues with analyzer rules, Xcode 12 & SwiftUI (#3366)
We weren't properly handling some new Xcode 12 compiler logs.

We also were marking declarations used by SwiftUI as unused
(`@main` and preview providers).
2020-09-23 07:15:54 -07:00
Frederick Kellison-Linn 64b309e19e
Fix false positives for 'multiple_closures_with_trailing_closure' (#3353) 2020-09-22 14:18:50 -07:00
JP Simard 494796b526
[UnusedDeclarationRule] Work around SR-11985 (#3363) 2020-09-22 10:00:16 -07:00
JP Simard f71394a372
[UnusedDeclarationRule] Add more tests (#3359) 2020-09-21 12:10:46 -07:00
JP Simard 0ecf9a945b
Don't mark `@NSApplicationMain` or `@UIApplicationMain` classes as unused (#3355) 2020-09-20 07:16:26 -07:00
hank121314 5e537fa821
[Fix] `UnusedCaptureListRule`: implicit self in @escaping closures (#3352)
## Summary

This pr fixes: #3267 .

Since Swift 5.3 is released. It support implicit self in @escaping closures([SE-0269](https://github.com/apple/swift-evolution/blob/master/proposals/0269-implicit-self-explicit-capture.md))

I think we should exclude self keyword from capture list rule.

## Test Plan

I have already add some test in example.

Thanks you so much for your code review!
2020-09-18 07:26:49 -07:00
JP Simard 6d2e8cfc06
Skip correcting files with parser diagnostics (#3349)
* Skip correcting files with parser diagnostics

Also fix many rule examples with parser diagnostics.

* Sourcery

* Link to issue in changelog entry
2020-09-17 18:14:00 -04:00
JP Simard ea311bab23
[UnusedDeclarationRule] Speed up and detect more dead code (#3340)
By using SourceKit's `index` request to index the entire source file,
we can avoid having to make `cursor-info` requests for every candidate
token in the file, which scales linearly with the number of candiate
tokens.

For the Yams project, this approach improved the total SwiftLint run
time by 4.6x: 7.9 down from 36.8s.

The SourceKit index response doesn't have everything we need to identify
declarations, so we still need to make some `cursor-info` requests,
mostly to detect overrides: protocol conformances and parent class
overrides.

This approach ends up finding more unused declarations because the index
contains more declared USRs than can be found by calling `cursor-info`
on candidate tokens in a file.

---

Remove unused declaration in ArrayInitRule

---

Update package versions
2020-09-15 10:33:27 -07:00
Ryan Demo 51544bb4cc
Add `excluded_match_kinds` custom rule config parameter (#3336)
This allows custom rules to define an `excluded_match_kinds` array instead of listing out all but one or a few of the `SyntaxKind`s in `match_kinds`. Rules that include both `match_kinds` and `excluded_match_kinds` will be invalid, since there's not an obvious way to resolve the two without an arbitrary priority between them.
2020-09-10 21:08:41 -04:00
Lukas Schmidt 8945038087
Use correct term for associated values
See https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html for reference
2020-09-03 11:26:57 +02:00
Marcelo Fabri 5e1c13be52 Add `unneeded_notification_center_removal` rule
Fixes #2755
2020-08-10 07:46:51 -07:00
Marcelo Fabri 4756ce6b69 Ignore local vars and params 2020-08-05 21:46:33 -07:00
Marcelo Fabri bb372c2146 Fix false positives in extension_access_modifier with Swift 5.2 2020-08-05 21:36:09 -07:00
Marcelo Fabri 30c7add095 Change to .idiomatic 2020-08-05 15:11:41 -07:00
antonnazarov 09a0a216d1 Change types on string representation 2020-08-05 15:05:02 -07:00
antonnazarov 63bd8ce7a5 Add PreferZeroOverExplicitInitRule 2020-08-05 15:05:02 -07:00
Marcelo Fabri 89523a92a9
Merge pull request #3122 from lordzsolt/if-guard-case
Extend empty_enum_arguments rule to support `if case` and `guard case`
2020-08-05 14:51:55 -07:00
Janak Shah 6b3e4e64a0
Include IndexSet in byArrayLiteral collection 2020-08-05 13:03:46 +01:00
Zsolt Kovacs b33b86acd9 Extend empty_enum_arguments rule to support `if case` and `guard case` 2020-08-05 03:48:42 -07:00
Marcelo Fabri 2d67213741
Merge pull request #3282 from realm/marcelo/self-and-is-multiple
Enable legacy_multiple and prefer_self_type_over_type_of_self in our codebase
2020-08-05 03:46:50 -07:00
Marcelo Fabri 8638d23aec
Merge pull request #3281 from realm/marcelo/bugfix-3225
Trigger closure_parameter_position in free closures and capture lists
2020-08-05 01:12:22 -07:00
Marcelo Fabri f8ef7d649c Enable legacy_multiple and prefer_self_type_over_type_of_self in our codebase 2020-08-05 01:11:17 -07:00
Marcelo Fabri a05a87e7f2
Merge pull request #3258 from SimplyDanny/bugfix-3034
Fix #3034: Allow opening brace directly after another opening brace
2020-08-05 01:02:00 -07:00
Marcelo Fabri 6ec5806a93 Trigger closure_parameter_position in free closures and capture lists 2020-08-05 00:42:27 -07:00
Marcelo Fabri d36743b58a Fix false positive in no_space_in_method_call with multiple trailing closures
Fixes #3259
2020-08-04 21:20:54 -07:00
Marcelo Fabri 5ad5bf2dae
Merge pull request #3276 from realm/marcelo/bugfix-3186
Fix false negative in `explicit_acl` rule with Swift 5.2+
2020-08-04 20:53:42 -07:00
Marcelo Fabri b541d253c6 Ignore .varParameter 2020-08-04 20:25:16 -07:00
Marcelo Fabri 1279523798 Ignore varLocal 2020-08-04 16:22:11 -07:00
Marcelo Fabri 0a592a34c9 Fix rule 2020-08-04 15:53:11 -07:00
Keith Smiley cf94d5d8ea
Add IBInspectableInExtensionRule (#3174) 2020-08-04 14:15:40 -07:00
Marcelo Fabri 9e5557fbc5
Merge pull request #3160 from realm/mf-computed_accessors_order
Add computed_accessors_order rule
2020-08-04 05:04:45 -07:00
Marcelo Fabri 2d7702fc25 Fix false positive in `explicit_acl` rule with Swift 5.2+
Fixes #3186
2020-08-04 04:24:52 -07:00
Marcelo Fabri 28bec96b3e Remove a usage of “blacklist” 2020-08-04 04:00:36 -07:00
Tieme van Veen 5f8f9a5a3d Fix false positive UPPERCASE raw_value_for_camel_cased_codable_enum 2020-08-04 03:34:28 -07:00
Marcelo Fabri 240e25232f Add computed_accessors_order rule
Fixes #3158
2020-08-04 03:23:36 -07:00
Marcelo Fabri 063cd3e56c Fix false positive on switch_case_on_newline with Swift 5.3
Fixes #3253
2020-08-04 03:17:23 -07:00
Marcelo Fabri d09a1411c9
Merge branch 'master' into duplicate_imports_configuration 2020-08-04 03:00:38 -07:00
Danny Moesch d08ea47920 Fix #3034: Allow opening brace directly after another opening brace or `in`
This special case occurs in functions implicitly returning closures.
2020-07-26 12:38:46 +02:00
Keith Smiley 46b99892d2 fix lint 2020-06-30 14:03:12 -07:00
Keith Smiley 660920a5f8 Add 'always_keep_imports' to UnusedImportRule
Sometimes we hit issues with SourceKit that cause this rule to produce
false positives of some imports. While we would prefer to fix all of
these cases whenever possible, this gives us a temporary escape hatch to
tell the rule never to remove imports of specific modules until the
fixes land in SwiftLint or Swift itself.

Currently this is for us to opt out of https://bugs.swift.org/browse/SR-13120
2020-06-30 10:00:33 -07:00
Noah Gilmore bda1cd56e0
#3167: Fixes false positives for multiline_parameters_brackets and multiline_arguments_brackets (#3171)
* Issue #3167: Fixes false positives for multiline_parameters_brackets and multiline_arguments_brackets

* Add changelog entry

* Fix trailing comma in MultilineParametersBracketsRule nontriggering examples

* Remove header comments from ExtendedStringTests.swift

Co-authored-by: Paul Taykalo <ptaykalo@macpaw.com>
2020-05-29 11:59:02 +03:00
Mateusz Matrejek 8ed7c31161
Fix false positive in with Swift 5.2 (#3112) (#3206) 2020-05-27 22:13:46 +03:00
Yusuke Goto 7da113e932 Fix severity level configuration for duplicate_imports 2020-05-12 17:27:33 +09:00
Keith Smiley e3ba417303
Fix UnusedImportRule breaking transitive imports (#3198) 2020-05-06 15:39:32 -07:00
Cihat Gündüz 5a22b94ec6
Add new file_content_type for PreviewProvider subclasses (#3063)
Fixes #2860.

Co-authored-by: Paul Taykalo <tt.kilew@gmail.com>
2020-04-24 13:21:24 +03:00
JP Simard da3e1a793b
Fix false positives in valid_ibinspectable rule when using Swift 5.2 (#3155)
* Fix false positives in valid_ibinspectable rule when using Swift 5.2

when defining inspectable properties in class extensions with computed
properties.

The following was triggering:

```swift
extension Foo {
  @IBInspectable var color: UIColor {
    set {
      self.bar.textColor = newValue
    }

    get {
      return self.bar.textColor
    }
  }
}
```

Fix by checking to see if an instance property has `set` keywords in its
body when running with Swift 5.2 or later.

* fixup! Fix false positives in valid_ibinspectable rule when using Swift 5.2
2020-03-27 10:04:04 -07:00
JP Simard 85d3425210
Fix attributes rule false positive with Swift 5.2 (#3154)
The following was triggering:

```swift
func printBoolOrTrue(_ expression: @autoclosure () throws -> Bool?) rethrows {
  try print(expression() ?? true)
}
```

Fix by adding the `rethrows` attribute kind to the rule's blacklist.
2020-03-27 09:33:12 -07:00
Marcelo Fabri 0bbbcb0a56
Fix false positives in redundant_objc_attribute with Swift 5.2 (#3152) 2020-03-26 19:23:48 -07:00
Marcelo Fabri 39ee6fe34e
Fix false positives on implicit_getter with Swift 5.2+ (#3151)
Fixes #3149
2020-03-26 18:53:36 -07:00
JP Simard c201ae43e6
Simplify regex (#3145)
* Simplify regex

`\w` already includes `_`

* Fix test
2020-03-18 16:23:52 -07:00
JP Simard d10ccacb45
Add unused_import config options to require imports for each module used (#3123)
For example, if `CGFloat` is used in a file where only `UIKit` is imported but not `CoreGraphics`, this will be a violation even if the file previously compiled.

This is because Swift allows referencing some declarations that are only transitively imported.

Enabling the `require_explicit_imports` configuration option will require that the module of every declaration referenced in a source file be explicitly imported.

This will add significant noise to the imports list, but has a few advantages:

1. It will be easier to understand all the dependencies explicitly referenced in a source file.
2. Correcting the `unused_import` rule will no longer introduce compilation errors in files that compiled prior to the correction.

If missing imports are added to a file when correcting it, the `sorted_imports` rule will be automatically run on that file.

If you with to allow some imports to be implicitly importable transitively, you may specify the `allowed_transitive_imports` configuration:

```yaml
unused_import:
  require_explicit_imports: true
  allowed_transitive_imports:
    - module: Foundation
      allowed_transitive_imports:
        - CoreFoundation
        - Darwin
        - ObjectiveC
```
2020-02-22 14:39:07 -08:00
JP Simard b744cf08f1
Temporarily remove all SwiftSyntax rules and support (#3107)
The new rules introduced in 0.39.0 that depend on SwiftSyntax have been temporarily removed as we work out release packaging issues.

* `prohibited_nan_comparison`
* `return_value_from_void_function`
* `tuple_pattern`
* `void_function_in_ternary`

See https://github.com/realm/SwiftLint/issues/3105 for details.
2020-02-11 13:40:04 -08:00
JP Simard 05a8a854f5
Fix unused_import rule reported locations and corrections (#3106)
When multiple `@testable` imports are involved.

Because we use the `.dotMatchesLineSeparators` regular expression option, the dot was matching across lines when the intention was for it to just match `\w_` characters.
2020-02-11 11:23:27 -08:00
Marcelo Fabri 6adf529e7e
Fix false positive in `empty_string` rule with multiline literals (#3101)
Fixes #3100
2020-02-10 08:27:44 -08:00
Marcelo Fabri c5e7bb3d31 Fix PrivateActionRule in Swift 5.2 (#3092) 2020-02-09 22:16:00 -08:00
Marcelo Fabri 4e84992a4a Fix false positive in implicit_getter with Swift 5.2 (#3099)
Fixes #3074
2020-02-09 20:00:53 -08:00
Marcelo Fabri a2fe35d620 Fix false positive in `attributes` with Swift 5.2 (#3097)
Fixes #3079
2020-02-09 18:17:45 -08:00
Marcelo Fabri 085e8ea0c9 Fix NSObjectPreferIsEqualRuleTests with Swift 5.2 (#3096)
This is not valid Swift code and Swift 5.2 changes the SourceKit response: https://bugs.swift.org/browse/SR-12167
2020-02-09 17:09:57 -08:00
Marcelo Fabri 66848e0186 Enable some opt-in rules in SwiftLint itself (#3095) 2020-02-09 17:07:24 -08:00
Marcelo Fabri b303cd64ea
Make SyntaxRules Opt-In (#3094) 2020-02-09 16:20:14 -08:00
Marcelo Fabri 14da706ae9 Remove unused variable in AttributesRule (#3090) 2020-02-09 16:06:27 -08:00
Marcelo Fabri b70b7778df
Fix UnownedVariableCaptureRuleTests in Swift 5.2 (#3091)
https://bugs.swift.org/browse/SR-12168
2020-02-09 16:06:11 -08:00
Marcelo Fabri fdd16a6853
Add `prohibited_nan_comparison` opt-in rule (#3089)
Fixes #2086
2020-02-09 15:13:25 -08:00
Zsolt Kovács ab8cd43e67 Empty count configuration (#3052)
* Add `only_after_dot` configuration option to `empty_count` rule

* Update CHANGELOG.md

* Adopt Example wrapper

* Change severity level to error
2020-02-09 15:12:54 -08:00
Marcelo Fabri 62e273c46c
Do not trigger optional_enum_case_matching on `_?` (#3088)
Fixes #3057
2020-02-08 14:42:55 -08:00
Marcelo Fabri f95768d2e6 Add `tuple_pattern` opt-in rule (#3086)
* Add `tuple_pattern` opt-in rule

Fixes #2203

* Remove unused import
2020-02-08 13:57:17 -08:00
Marcelo Fabri bdede7b9c1 Remove extra space in `optional_enum_case_matching` description (#3087) 2020-02-08 13:49:21 -08:00
Marcelo Fabri 1d39071dfd
Add `void_function_in_ternary` opt-in rule (#3085)
* Add `void_function_in_ternary` opt-in rule

Fixes #2358

* Remove unused import and improve description
2020-02-08 13:23:02 -08:00
Marcelo Fabri 8d9c501cb8
Add optional return_value_from_void_function rule using SwiftSyntax (#3054)
* Add optional return_value_from_void_function rule using SwiftSyntax

* Use Script/bootstrap in CI

* Make SwiftSyntax optional

* Make SwiftSyntax optional in SPM

* Fix Package.swift

* Try again

* Add minSwiftVersion

* Fix thread sanitizer issue

* Take 2

* Fix false positive on nested computed variables

* Remove support for Xcode 10.x

* Fix rule description

* Enable opt-in rule in configuration file

* Extract code into `SyntaxRule` protocol

* nit: make property private

* Missing docs

* Fix MasterRuleList.swift

* Update CHANGELOG

* Remove unused imports

* Use Example type

* Change rule kind to .idiomatic

* Update CHANGELOG

* Bump deployment target to macOS 10.12

* Simplify SyntaxRule.validate(file:visitor)

* Make TSan happy

* Use script/bootstrap in the README
2020-02-08 02:43:40 -08:00
John Buckley efe8816315
ImplicitReturnConfiguration description now reports current config (#3083)
* ImplicitReturnConfiguration description now reports current config.

Previously only the default config was reported.

* Updating CHANGELOG.md
2020-02-08 01:55:58 -08:00
Paul Taykalo 057bcb8921
Fixes #3066 Crash on missing (#3067) 2020-02-02 23:30:40 +02: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
Paul Taykalo 25f07af7bc
Merge pull request #3031 from PetteriHuusko/dev
Fix discarded_notification_center_observer false positive on arrays
2020-01-30 09:19:26 +02:00