Commit Graph

581 Commits

Author SHA1 Message Date
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 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 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
Marcelo Fabri 5d3403a615
Fix master (#3069) 2020-02-02 16:50:07 -08: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
JP Simard d2643db495
[Docs] Build docs using jazzy (#3016)
* Add `.jazzy.yaml` configuration file
* Update `swiftlint generate-docs` to write docs to a directory rather than a single file
* Add jazzy to the Gemfile
* Run `bundle update`
* Add CI job to run jazzy automatically and publish to GitHub Pages

![swiftlint-jazzy](https://user-images.githubusercontent.com/474794/71799038-fcf4e180-3008-11ea-81fa-3eb9cf296506.gif)
2020-01-07 20:31:29 -08:00
JP Simard cd841dff84
Remove duplicate file entry in SwiftLint.xcodeproj 2020-01-06 10:40:45 -08:00
Frederick Pietschmann 8c245c7581 Add new indentation_width rule 2020-01-06 08:30:49 +01:00
Marcelo Fabri c2bdb589df
Add orphaned_doc_comment rule (#3014)
* Add orphaned_doc_comment rule

Fixes #2989

* Don’t trigger on lines with only “/“
2020-01-05 20:45:06 -08:00
Sven Münnich 72e2063531
Include functions and getters in rule `implicit_return` 2020-01-05 15:04:35 -08:00
timcmiller 4112816077 Added 'file_name_no_space' rule (#3008)
* Added 'file_name_no_space' rule

* Removed unused var, and added to changelog

* Remove custom suffix from 'file-name-no-space' rule

* Fixed LinuxMain

* Switched to use a CharacterSet over Regex
2020-01-03 15:45:30 -08:00
Marcelo Fabri 093370c2b3
Add opt-in `prefer_self_type_over_type_of_self` rule (#3006)
Fixes #3003
2020-01-03 12:33:04 -08:00
Marcelo Fabri 2c3411dc88
Add optional_enum_case_matching rule (#3002) 2020-01-03 00:50:47 -08:00
ldindu 2ccb33b111 Add `enum_case_associated_values_count` opt-in rule 2020-01-02 23:24:06 -08:00
Dan Loman cc57ed3d69 Add ExpiringTodoRule (#2911)
* Add expiring todos rule

* Fix default dateFormat

* Fix date regex to handle 2-4 at beginning/end of string

* Clean up/improve clarity

* Add tests for ExpiringTodoRule

* Add output from make sourcery

* Add output from make sourcery

* Update documentation

* Enable updating of all configuration properties

* Add back Foundation import

* Add changelog entry

* Add 2 spaces after changelog entry

* Add return for legacy swift compatibility

* Add unwrapping to switch statement

* Use disable:next

* Add default values to severity config init; Add public delimiter init

* Add tests for various custom configurations

* Remove unused funcs

* Add extra tests to LinuxMain file

* Update File type -> SwiftLintFile

* Move Changelog entry

* Shorten changelog entry line length

* Fix changelog
2019-11-20 16:50:29 -08:00
Paul Taykalo 73802c285d Add own wrappers over syntax tokens and syntax map 2019-11-10 22:55:54 +02:00
JP Simard beaa2a8a87
Update Commandant and SourceKitten, drop Result (#2947) 2019-11-07 10:59:16 -08:00
Paul Taykalo ac40778cb3 Use SwiftLintFile wrapper over the File 2019-11-07 15:19:17 +02:00
Paul Taykalo 18a3896f97 Update swift structure dictionary 2019-11-07 08:51:16 +02:00
Paul Taykalo 6175c004da Faster tokens resolving in syntaxmap (#2916)
When the request is asked which tokens are have in an intersection, the previous solution was searching for first Index (linearly) and then filtered everything that was coming after that index using `intersect function`

The updated solution  will search for the first token index using`binary search`

# Speedup

While this is only one function was updated, the next options were considered:

- [**lin+filter**] old solution 
- [**lin+prefix**] old solution with `prefix:wihle` instead of filtering
- [**bin+filter**] binary search with filter 
- [**bin+prefix**] binary search with `prefix:wihle` instead of filtering

The speedup highly depends on the file sizes. The bigger/longer files the bigger win is

# Benchmark

## Kickstarter

|lin+filter|lin+prefix|bin+filter|bin+prefix|speedup|
|-|-|-|-|-|
|0.494|0.243|0.390|\***0.117\***|  ~4x |

## Swift

|lin+filter|lin+prefix|bin+filter|bin+prefix|speedup|
|-|-|-|-|-|
|1.739|0.740|1.273|\***0.103**\*| ~16x |

## WordPress
|lin+filter|lin+prefix|bin+filter|bin+prefix|speedup|
|-|-|-|-|-|
|1.270|0.526|0.918|0.148| ~8x |

# Testing code

This code was tested with these parts of code (in Release build)
```
fileprivate var counter = 0
fileprivate var times: [String: Double] = [:]
fileprivate let timesQueue = DispatchQueue.init(label: "benchmarks")

fileprivate func timeLog<T>(_ name: String, block: () -> T) -> T {
    let start = DispatchTime.now()
    let result = block()
    let end = DispatchTime.now()
    timesQueue.async {
        let oldValue = times[name, default:0.0]
        let diff = TimeInterval(end.uptimeNanoseconds - start.uptimeNanoseconds) / 1_000_000_000
        let newValue = oldValue + diff
        times[name] = newValue
        counter += 1
        if counter % 1000 * times.count == 0 {
            print("!!!!: \(times)")
        }
    }
    return result
}

    internal func tokens(inByteRange byteRange: NSRange) -> [SyntaxToken] {
        let new = timeLog("new") { tokensFast(inByteRange: byteRange) }
        let new2 = timeLog("old") { tokensOld(inByteRange: byteRange) }
        return arc4random() % 2 == 1 ? new : new2
    }

```
2019-11-06 15:21:38 -08:00
Norio Nomura 80d3813214
Add GitHub Actions Logging reporter (`github-actions-logging`)
Use [GitHub Actions Logging](https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#logging-commands) same as https://github.com/norio-nomura/action-swiftlint does.
2019-11-04 19:36:25 +09:00
MarkoPejovic 109899c56c Implement #2888 2019-10-20 19:19:54 -07:00
Marcelo Fabri f211694e7d
Merge pull request #2885 from realm/mf-flatmap
Add `flatmap_over_map_reduce` opt-in rule
2019-09-26 11:02:58 -07:00
Marcelo Fabri b9b0beb0c9 Fix localization warning 2019-09-26 10:15:26 -07:00
Marcelo Fabri d4ef1f0ad0 Add `flatmap_over_map_reduce` opt-in rule
Fixes #2883
2019-09-26 10:07:12 -07:00
Colton Schlosser 2c076151f4 Add `contains_over_range_not_nil` rule, make `contains_over_first_not_nil` also match == nil (#2811) 2019-09-03 12:03:00 -04:00
JP Simard ffb2f4f76d
Require Swift 5.0 to build (#2857)
* Require Swift 5.0 to build

* Update CI

* Stop testing with Swift 4.x & Xcode 10.0/10.1
* Use official Swift docker image instead of norionomura's
* Use Xcode 10.3 as latest stable version

* Update READMEs

* Fixup xcodeproj

* Fixup CI Swift container image tag

* Fixup changelog
2019-09-03 11:42:57 -04:00
Marcelo Fabri 40bc8de5c7 Add no_space_in_method_call rule (#2855)
* Add no_space_in_method_call rule

* Avoid false positive with typecasting
2019-09-03 10:03:21 -04:00
Colton Schlosser 130371b8cc Add `empty_collection_literal` rule 2019-08-28 21:57:02 -04:00
Marcelo Fabri 67526344ef Add `contains_over_filter_is_empty` opt-in rule 2019-08-25 20:22:41 -07:00
Marcelo Fabri 00d2b5d772 Add contains_over_filter_count opt-in rule
Fixes #2803
2019-08-25 20:00:50 -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 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 1c56d30db6 Add CollectingRuleTests 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
Marcelo Fabri 596bf8dbc8 Detect parameter attribute in vertical_parameter_alignment
Fixes #2792
2019-07-04 10:42:11 -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 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
Marcelo Fabri a3aa36757b Add `unowned_variable_capture` opt-in rule
Fixes #2097
2019-04-30 10:12:20 -07:00
Marcelo Fabri ad2733391a
Merge pull request #2666 from daltonclaybrook/dc-reduce-into-rule
Add reduce_into opt-in rule
2019-04-15 14:52:04 -07:00
Dalton Claybrook d8f671c315 WIP - create unused capture list rule 2019-04-13 23:12:25 -04:00
Marcelo Fabri 51d47d492c `contains_over_first_not_nil` rule now also checks for `firstIndex(where:)`
Fixes #2678
2019-04-09 10:53:42 -07:00
Matthew Healy 74b51c5d38 [nslocalizedstring_require_bundle] Add NSLocalizedStringRequireBundleRule description 2019-03-30 00:10:14 +01:00
Cihat Gündüz 311965f23c Fix issues after rebase 2019-03-27 10:34:58 +01:00
Cihat Gündüz 50fba286ab Add tests for different configurations in type_contents_order 2019-03-27 10:34:41 +01:00