Commit Graph

372 Commits

Author SHA1 Message Date
Marcelo Fabri 07824e7106 Dynamically load lib_InternalSwiftSyntaxParser.dylib 2020-02-12 00:10:26 -08:00
JP Simard b6c0c7e374 Revert "Temporarily remove all SwiftSyntax rules and support (#3107)"
This reverts commit b744cf08f1.
2020-02-11 13:40:26 -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
David Harris 8c789bb3e2 feature: add config setting to exist successfully in case of no lintable (#2732)
files
2020-02-08 13:33:50 -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
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 fe5baca7cd
Migrate to use SourceKitten's new ByteCount/ByteRange types (#3037)
New APIs were introduced in SourceKitten to allow for a more typesafe distinction between integers meaning NSString-based distances and byte-based distances.

* https://github.com/jpsim/SourceKitten/pull/639
* https://github.com/jpsim/SourceKitten/pull/642

This PR migrates SwiftLint's use of those APIs.
2020-01-16 15:18:37 -08:00
JP Simard 399f5b7df6
Fix docstring formatting issues using DrString (#3032)
Using command:
$ drstring check -i 'Source/**/*.swift' --first-letter lowercase --vertical-align
2020-01-12 11:19:33 -08:00
JP Simard 37167a8a35
Add documentation comments to all public declarations (#3027) 2020-01-08 09:47:10 -08: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
Pyry Jahkola 805b9ab3ba
Add capture_group option to custom_rules
This option allows for more fine-grained placement of the location
marker for code violating a custom rule, e.g.:

```swift
print("Hello world.")
             ^~~~~
```

for this `.swiftlint.yml`:

```yaml
custom_rules:
  world_preceded_by_hello:
    name: "World Preceded by Hello"
    included: ".+\\.swift"
    message: "The word World predeced by the word hello should be capitalised."
    severity: warning
    regex: "(?i:hello)\\s+(world)"
    match_kinds: [string]
    capture_group: 1
```
2020-01-05 15:24:11 -08:00
JP Simard 40ade98710
Update SourceKitten to 0.28.0 (#3011) 2020-01-03 16:47:18 -08:00
Sven Münnich fb5361e37b Fix parsing of rule disable comments containing a URL (#2985) 2020-01-03 09:36:16 -08:00
Paul Taykalo 3cb318e42f
Update Source/SwiftLintFramework/Extensions/Dictionary+SwiftLint.swift
Co-Authored-By: JP Simard <jp@jpsim.com>
2019-11-12 01:27:02 +02:00
Paul Taykalo 61a6a278a5 add byterange to the dictionary and breadthfirst algorithm 2019-11-10 23:53:59 +02:00
Paul Taykalo 73802c285d Add own wrappers over syntax tokens and syntax map 2019-11-10 22:55:54 +02:00
JP Simard 4aad7e14b4
Space between ':' and 'inout' 2019-11-09 14:19:01 -08:00
JP Simard 067b1e075f
Docstring edits 2019-11-09 13:39:05 -08:00
Paul Taykalo f569e3d973
Rename Traverse to Traverse with Parent 2019-11-09 13:29:43 -08:00
Paul Taykalo c85d3099a1
Update documentation 2019-11-09 13:29:43 -08:00
Paul Taykalo a52a94c987
Use Generic Dictionary Traversing for multiple cases 2019-11-09 13:29:43 -08:00
Paul Taykalo d771d223e3 Remove unused imports 2019-11-07 16:20:18 +02:00
Paul Taykalo ac40778cb3 Use SwiftLintFile wrapper over the File 2019-11-07 15:19:17 +02:00
Paul Taykalo ec6d82af56 Cache Access Control Level property 2019-11-07 11:52:50 +02:00
Paul Taykalo b1cdc119ec Use swift enums instead of raw values 2019-11-07 11:05:19 +02:00
Paul Taykalo 4fff698c09 Update UnusedDeclarationRule to use SourceKittenDictionary 2019-11-07 10:28:30 +02:00
Paul Taykalo 18a3896f97 Update swift structure dictionary 2019-11-07 08:51:16 +02:00
Paul Taykalo f0ad230e81 fix linting issues 2019-11-07 08:50:50 +02:00
Paul Taykalo b901c670d4 Cache file structure dictionary 2019-11-07 08:50:50 +02:00
Paul Taykalo 8c963d2c15 Working solution with SouceKittenDictionary wrapper 2019-11-07 08:50:50 +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
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 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
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](5add168042/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
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 512e06a4e4 Update tests to compile and pass
Publicize Array extensions

Address linting violations
2019-07-18 14:59:42 -07:00
JP Simard 18c78684b0
Remove unused declarations (#2816) 2019-07-18 13:52:57 -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
Keith Smiley dd39c438e1 Return false for isFile for empty strings
As of Swift 5, corelibs-foundation crashes if you pass an empty string
to `fileExists` cae5eaca63/Foundation/FileManager.swift (L2033)
2019-04-02 18:15:40 -07:00
Paul Taykalo f1fd6cec3a Update group Array extension to faster implementation (#2654) 2019-02-20 19:33:19 -08:00
Marcelo Fabri 7ecfce34c7 Warn if a configured rule is not enabled.
Fixes #1350
2019-02-03 14:43:00 -08:00
JP Simard 18ad2473d0
Remove unnecessary backticks (#2601)
These were once required but now that we only support Swift 4.2 or later, they're unnecessary.
2019-01-27 20:19:49 -08:00
JP Simard f08c3e4239
Use firstIndex(where:) instead of index(where:) (#2600)
to silence a Swift 5 warning. This is compatible with Swift 4.2.
2019-01-27 20:19:16 -08:00
Marcelo Fabri a1b659aa1b
Merge pull request #2588 from dirtydanee/bugfix/explicit-type-interface-in-groups-and-stmts
Fix ExplicitTypeInterfaceRule in groups and statements
2019-01-25 13:37:44 -08:00
Marcelo Fabri 7b84e2bf66 Extract two common operations to extensions 2019-01-24 21:14:10 -08:00
Daniel Metzing 4634467644 Fix ExplicitTypeInterfaceRule in groups and statements 2019-01-24 20:37:42 +01:00
Luis Valdés 80a44bcf8c Exclude files defined in `excluded` when using the `--use-script-input-files` and `--force-exclude` options (#2574) 2019-01-22 12:28:34 -08:00