Commit Graph

2451 Commits

Author SHA1 Message Date
Marcelo Fabri 3879151abf Enable some opt-in rules (#2801) 2019-08-28 14:49:23 -07:00
Marcelo Fabri b24fd6cdd4 Enable contains_over_filter_is_empty in SwiftLint itself 2019-08-25 20:58:11 -07:00
Marcelo Fabri 3e115835b1 Merge pull request #2846 from realm/mf-contains_over_filter_is_empty
Add `contains_over_filter_is_empty` opt-in rule
2019-08-25 20:55:11 -07:00
Marcelo Fabri 67526344ef Add contains_over_filter_is_empty opt-in rule 2019-08-25 20:22:41 -07:00
Marcelo Fabri 759ccd8a1e Avoid false positives in contains_over_filter_count 2019-08-25 20:11:23 -07:00
Marcelo Fabri 00d2b5d772 Add contains_over_filter_count opt-in rule
Fixes #2803
2019-08-25 20:00:50 -07:00
Marcelo Fabri 7c6d5d0994 Merge pull request #2815 from atfelix/issue-2791-swiftui-previews
Removes `type_name` violation for SwiftUI template code
2019-08-25 19:32:05 -07:00
Adam Felix 6f67cfa5aa Issue-2791: type_name violation for with SwiftUI template code
* Ignore SwiftUI Previews underscore character
2019-08-25 20:01:28 -04:00
Marcelo Fabri e96e75b49f Merge pull request #2844 from realm/mf-bugfix-2690
Don't trigger `missing_docs` on `deinit`
2019-08-25 04:07:17 -07:00
Marcelo Fabri 150db104c7 Don't trigger missing_docs on deinit
Fixes #2690
2019-08-25 03:28:44 -07:00
Marcelo Fabri f6b73431a1 Avoid triggering redundant_type_annotation with @IBInspectable
Fixes #2842
2019-08-25 02:22:33 -07:00
Timofey Solonin 7800220ff7 #2737 - Fix unused_imports false positive when only operators from the module are used (#2840)
As was discussed #2737, I utilized the `indexsource` request to look up the operators and fetch the cursorInfo per operator. In the implementation I refrained from using `usr` to look up the operator because SourceKit [doesn't support](https://github.com/apple/swift/blob/5add16804272b4df917da15c46eb6f28d826d656/tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp#L1799) fetching cursorInfo by `usr` when it comes from C (but it can still be fetched by offset).

I also made [an alternative implementation](https://github.com/realm/SwiftLint/compare/master...biboran:fix-unused-imports-for-operators-alternative) which uses the `indexsource` request instead of the `editor.open`. It seems to work with the unit tests but I am not 100% sure it doesn't introduce a regression since there is no oss-check for analyzer rules.

I also updated [the example](https://github.com/biboran/synthax-bug-example) to better reflect the original issue in case you want to test the changes manually
2019-08-23 16:19:57 -07:00
a-25 40457a7044 Fixed false positive in colon (#2836) 2019-08-14 08:42:34 -07:00
JP Simard 08946e65e5 release 0.34.0 2019-07-18 18:28:39 -07:00
JP Simard e63e8cad0f Add UnusedDeclarationRule (#2814)
This PR adds a new `unused_declaration` analyzer rule to lint for unused declarations.
By default, detects unused `fileprivate`, `private` and `internal` declarations.
Configure the rule with `include_public_and_open: true` to also detect unused `public` and `open` declarations.

Completely remove the `unused_private_declaration` rule.

This is built on the work enabling collecting rule infrastructure in https://github.com/realm/SwiftLint/pull/2714.
2019-07-18 18:23:43 -07:00
Elliott Williams 3d5239429e Add AnyCollectingRule and isCollecting
All CollectingRules implement AnyCollectingRule, which is used to check
whether a linter will perform any collections and only print the
"Collecting" log message if so.
2019-07-18 14:59:42 -07:00
Elliott Williams a47b9a90fc Document Linter / CollectedLinter relation 2019-07-18 14:59:42 -07:00
Elliott Williams f277fbe5d2 Make RuleStorage have dictionary semantics and check for collected info inside Rule 2019-07-18 14:59:42 -07:00
Elliott Williams ddee9c8e6b Refactor spacing, indenting, and rename collect to collectInfo 2019-07-18 14:59:42 -07:00
Elliott Williams ab655b226c Remove File+Hashable and bump SourceKitten 2019-07-18 14:59:42 -07:00
Elliott Williams 7344732799 PR: Create File+Hashable, symlink Array+SwiftLint, fix nits 2019-07-18 14:59:42 -07:00
Elliott Williams 512e06a4e4 Update tests to compile and pass
Publicize Array extensions

Address linting violations
2019-07-18 14:59:42 -07:00
Elliott Williams b1ca533649 Add RuleStorage and a pre-linting stage to run collection
In order for rules to collect arbitrary information about all files
being linted, a shared RuleStorage instance is defined in each command
and passed into the linter.

Linting now requires two "passes": once to call collect and populate the
storage (rules that are non-collecting do nothing here), and again to
call validate. The old Linter factory now creates a Prelinter, which can
collect for a file and produce a Linter that orchestrates all the
traditional validation/collection logic.

This design enforces that a file is only validated once it has been
collected; in turn, the file-visiting loop ensures that all files are
collected before the first is validated, so that the storage is fully
populated.

Use storage-backed correct method

Crash if storage for a rule is accessed prematurely

Key FileInfo by File

Rename Prelinter to Linter and Linter to CollectedLinter

Clean up rule protocols such that rule-facing storage methods are actually called

Make RuleStorage a reference type to solve mutating data races
2019-07-18 14:59:42 -07:00
Elliott Williams 01ea736a46 Add CollectingRule to support arbitrary pre-lint collection 2019-07-18 14:59:42 -07:00
JP Simard 18c78684b0 Remove unused declarations (#2816) 2019-07-18 13:52:57 -07:00
JP Simard ffd0804746 release 0.33.1 2019-07-08 08:54:53 -07:00
JP Simard 3a0c2b0c05 Migrate LinterCache to use Codable models (#2799)
* Migrate LinterCache to use Codable models

improving performance and type safety

* Fix Linux

* Avoid creating a Decoder if it won't be used

For example if the file doesn't exist or can't be read.

* Use corelibs plist coder if available

It's available in the Swift 5.1 branch: https://github.com/apple/swift-corelibs-foundation/pull/1849

* Remove unused error case
2019-07-07 00:35:10 -07:00
Colton Schlosser 18e90be780 Split cache into one file per configuration (#2796)
* Split cache into one file per configuration

* Only write cache files with changes

* Avoid converting from Data -> String -> Data when saving cache files

* Move empty check to for where

* Split cache changelog entry

* Reword changelog entry to better reflect impact
2019-07-06 11:50:20 -07:00
Marcelo Fabri 94c6009fc4 Fix false positive in function_default_parameter_at_end
Fixes #2788
2019-07-04 22:25:52 -07:00
Marcelo Fabri 0652b323f5 Use new source.request.compiler_version request 2019-07-04 10:59:43 -07:00
Marcelo Fabri 596bf8dbc8 Detect parameter attribute in vertical_parameter_alignment
Fixes #2792
2019-07-04 10:42:11 -07:00
JP Simard 7f4b736ea3 Synthesize Equatable implementations where possible (#2790) 2019-07-01 17:22:18 -04:00
Marcelo Fabri 740e398f91 release 0.33.0 2019-06-02 09:54:05 -07:00
Marcelo Fabri 0ee12bd096 Catch != 0 in legacy_multiple rule (#2778) 2019-06-02 09:52:05 -07:00
Marcelo Fabri 6be5bf74c3 Add legacy_multiple opt-in rule (#2771)
Fixes #2612.
2019-06-01 22:49:23 -07:00
Marcelo Fabri 90cb1349c0 Add duplicate_enum_cases rule (#2777)
Fixes #2676
2019-06-01 20:32:55 -07:00
Marcelo Fabri 862913f0c0 Don't trigger no_fallthrough_only if next case is @unknown (#2770)
* Don't trigger no_fallthrough_only if next case is @unknown

Fixes #2696
2019-05-25 21:53:23 -07:00
JP Simard a55178e681 Use isDisjoint(with:) instead of intersection().isEmpty 2019-05-20 10:19:37 -07:00
Dalton Claybrook a371419ce4 Fix issue where force-unwrapping self does not trigger a violation of the force_unwrapping rule (#2764)
* Fix issue where force-unwrapping self does not trigger a rule violation

* Update changelog
2019-05-20 10:17:32 -07:00
JP Simard c216ccc1e5 Remove WeakComputedProperyRule (#2761)
* Remove WeakComputedProperyRule

Addresses https://github.com/realm/SwiftLint/issues/2712

* fixup! Remove WeakComputedProperyRule
2019-05-16 02:19:01 -07:00
Cihat Gündüz d01ed712f9 Merge pull request #2754 from samrayner/samrayner/file-types-order-extensions
#2749 Fix file_types_order in extension-only files
2019-05-14 12:44:04 +02:00
Sam Rayner 7b82250995 #2749 Fix file_types_order in extension-only files
Prevents extensions being flagged as in the wrong order when a file only contains extensions and nothing else (enums, classes, structs). In this case it's not intuitive that the longest extension be considered the "main" one so the file can be considered as having no "main" type.
2019-05-13 13:59:16 +01:00
Kevin Randrup d7439410e9 Introduce " - " delimiter to allow rules to be commented (#2721)
* Introduce " - " delimiter to allow rules to be commented
Ex. swiftlint:disable:next force_try - Explanation here

* Fix changelog formatting
2019-05-12 21:40:12 -07:00
Alvar Hansen af72c06be4 Skip module import if cursor info is missing module info (#2746) 2019-05-06 08:57:01 -07:00
Marcelo Fabri a3aa36757b Add unowned_variable_capture opt-in rule
Fixes #2097
2019-04-30 10:12:20 -07:00
Frederick Pietschmann 3b9917f89d Add nested type handling specification to file_name rule (#2718)
* Add nestedTypeSeparator to FileNameConfiguration

* Add tests for nested_type_separator configurability of file_name rule

* Add changelog entry

* Fix changelog position after rebase
2019-04-30 08:12:43 -07:00
Javier Soto 49c288eb3f Fixed typo in nslocalizedstring_require_bundle rule description 2019-04-29 17:06:28 -07:00
Marcelo Fabri d14d79d2c4 Don’t trigger redundant_void_return when using subscripts 2019-04-29 09:47:00 -07:00
JP Simard 6534946fe3 release 0.32.0 2019-04-28 21:30:19 -07:00
Marcelo Fabri 3a36212b94 Swift 5 support (#2720)
* Update project to compile with Xcode 10.2

* Fix explicit_acl with Swift 5

* Update macOS VM image

* Fix ConfigurationTests on Swift 5

* Update Podspec

* Workaround SR-10486 to fix validation tests

* Fix testDetectSwiftVersion on Swift 5

* Update specs repo when validating CocoaPods spec

* Fix redundant_set_access_control tests

* Manually update Package.resolved

* Use .upToNextMinor

* [Azure Pipelines] Add `sw_vers`

* Relax expecting conditions for crashing output in `testSimulateHomebrewTest()`

Because TSAN makes `swiflint` to produce additional output on crashing.

* Add CHANGELOG entry

* Ignore extensions in explicit ACL rules

* Work around SR-10486 for Sourcery
2019-04-28 21:10:06 -07:00