Commit Graph

340 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
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
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` https://github.com/apple/swift-corelibs-foundation/blob/cae5eaca63cd57f64a93b4d5de87a4ffc04466d5/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
JP Simard 0e01e07326 #2441 - Fix inaccessible custom rules in nested configurations (#2556)
* #2441 - Pass custom rules identifiers to the enableRules function to consider custom rules of a parent of a nested configuration

* #2441 - Add custom rules merge

* #2441 - Fix line length violation

* #2441 - Add nested configutaion mocks with custom rules

* #2441 - Add nested configurations tests for custom rules

* #2441 - Disable function body length check

* #2441 - Update changelog

* Move changelog to appropriate position

* Split up and refactor Configuration.init to avoid being too long

* Add tests to LinuxMain.swift

* Remove redundant protocol conformances

Hashable implies Equatable

* Fix typo in changelog entry and add another fixed issue URL
2019-01-13 15:07:27 -08: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 e6ff3521c8 Run analyze on CI with --strict (#2524)
and whitelist two intentional violations
2018-12-23 18:22:41 -08:00
JP Simard ce8ea70492 Stringify swiftlint_version (#2523)
to treat any specified value that doesn't match the version string
to fail the lint.
2018-12-23 16:29:42 -08:00
Kim de Vos d62e187b5c Add Legacy Hashing rule (#2496) 2018-12-05 15:43:39 -08:00
JP Simard 0e862ca9c4 Enable vertical whitespace rules in SwiftLint
and fix violations
2018-12-02 14:01:23 -08:00
JP Simard 7afd7ccaf8 Rename cleanedKeysDict() to removingViolationMarkers() 2018-12-02 13:52:41 -08:00
Cihat Gündüz 89c88517e1 Vertical whitespace opening & closing braces (#2291)
* Add VerticalWhitespaceOpening/ClosingBraces rules with description

* Implement validate, correct & add rules to lists

* Fix minor issues & update docs

* Fix copy & paste issue

* Improve autocorrection + Cleanup triggering examples

* Update changelog with new rule entries

* Add more validation examples

* [CHANGELOG.md] Mark new rules as opt-in

* Point to exact location of violation + update tests

* Make rules severity configurable

* Fix issues after rebasing

* Fix issue with CHANGELOG.md

* Add more violating examples, improve pattern to catch more cases

* Move changelog entries to new version

* Fix issues after rebase

* Move Changelog entry to current master

* Fix failing tests

* Fixes after refactoring

* Fix changelog entry position

* Make range unicode-safe (as suggested by @jpsim)

* Share duplicate Dictionary extension code
2018-12-02 13:41:50 -08:00
Marcelo Fabri 85b61e7fcc Fix false positive in nimble_operator rule
Fixes #2489
2018-11-27 21:08:28 -08:00
JP Simard d1109da326 Parallelize iterating over subpaths (#2475)
This has a very small performance improvement on multi-core machines
2018-11-21 22:38:05 -08:00
Norio Nomura ea171fbbf2 Add SWIFTLINT_DISABLE_SOURCEKIT environment variable (#2473)
This can be used for avoid "Test::Unit::AssertionFailedError" error in `libxpc.dylib` on calling `sourcekitd_send_request_sync` in sandbox environment.
2018-11-21 17:03:42 -08:00
JP Simard db2fbad7fd Use CommonCrypto if available to compute MD5 hash (#2474)
It's significantly faster than CryptoSwift: 3% vs 19% of cached lint time for Lyft's iOS codebase.

### Before (CryptoSwift)

![CryptoSwift](https://user-images.githubusercontent.com/474794/48873531-3f2a7780-eda3-11e8-9cd9-c0ef796b061b.png)

### After (CommonCrypto)

![CommonCrypto](https://user-images.githubusercontent.com/474794/48873539-481b4900-eda3-11e8-8605-4fd009da3eb1.png)
2018-11-21 16:19:10 -08:00
Marcelo Fabri cf0c7b7b21 Use default Equatable and Hashable implementations 2018-11-19 09:51:12 -08:00
JP Simard 5901d3075f Require Swift 4.2 (#2466)
This bumps the minimum version required to build SwiftLint to 4.2. The primary motivating factor to drop support for Swift 4.0-4.1.x is that SwiftLint now uses CryptoSwift, which requires 4.2.

* Add changelog entry

* Remove --allow-warnings flag from CocoaPods commands

* Update CryptoSwift to 0.13.0

* Migrate to Swift 4.2

* Remove CircleCI tests for Swift < 4.2

* Update English and Chinese README

Korean README doesn't yet have a version table like this.

* Update gems

* Add changelog entry for fixed compiler warnings

* Update CocoaPods to 1.6.0.beta.2

To work around https://github.com/CocoaPods/CocoaPods/issues/7708
2018-11-18 17:32:25 -08:00
JP Simard d768897f1d Improve performance of collecting files to lint and lint cache lookups (#2465)
Performance has gotten pretty bad for complex SwiftLint configurations like the one used for Lyft's iOS code base involving lots of files in the directories being linted, large configuration files and many nested configuration files.

Two main areas were particularly ripe for improvement were:

1. Collecting which files to lint
2. Lint cache lookups

### Collecting which files to lint

Improve this by:

* using an NSOrderedSet to remove excluded paths instead of `Array.filter`
* parallelizing calls to `filesToLint` for all paths to lint and exclude
* using `FileManager.subpaths(atPath:)` instead of `enumerator(atPath:)`

|Change|Before|After|Speed up|
|-|-|-|-|
|NSOrderedSet|2.438s|0.917s|2.659x|
|Parallel Flat Map|2.438s|2.248s|1.085x|
|Subpaths|0.939s|0.867s|1.083x|
|**Total**|**2.438s**|**0.720s**|**3.386x**|

### Lint cache lookups

By using an MD5 hash of the Configuration description from CryptoSwift as the cache key instead of instead the full description, we can drastically speed up cache lookups for projects with complex SwiftLint configurations. I think the dictionary lookup for very large string keys doesn't perform very well.

---

* Speed up Configuration.lintablePaths

* Improve cache lookup performance by up to 10x

By using an MD5 hash of the Configuration description from CryptoSwift
as the cache key instead of instead the full description.

* Add changelog entries

* Swift 4.0 & Linux compatibility

* os(Darwin) isn't a thing

* Allow warnings in pod lib lint

SwiftLint supports building with Swift 4.0 to 4.2.

There is no version of CryptoSwift to support both Swift 4.0 and
Swift 4.2.

So allow warnings for now. We'll make one more Swift 4.0 compatible
release, then we'll bump the build requirements to Swift 4.2 and
remove the `--allow-warnings` flag.
2018-11-18 14:39:02 -08:00
JP Simard dcc85fb0f3 Remove unused imports (#2382) 2018-09-02 14:09:04 -07:00
JP Simard 2bcea4b04d Add ability for SwiftLint to lint files with full type-checked AST awareness (#2379)
* Add LintableFilesVisitor

* Move LintCommand logic into LintOrAnalyzeCommand

to prepare for the upcoming analyze command

* Add AnalyzeCommand (not fully implemented yet in SwiftLintFramework)

* Add analyzerRules configuration member

* Add AnalyzerRule protocol

* Pass compiler arguments to validate/correct

* Add requiresFileOnDisk member to RuleDescription

This will be used by AnalyzerRules because they need a file on disk
to pass in the compiler arguments to SourceKit.

* Exclusively run AnalyzerRules when the Linter has compiler arguments

* Enable testing AnalyzerRules in TestHelpers

* Add ExplicitSelfRule

* Update documentation

* Fix `analyze --autocorrect`

* Improve performance of CompilerArgumentsExtractor

* Fix lint command actually running analyze

* Move File operations in TestHelpers into a private extension

* Add analyzer column to rules command and markdown documentation

* Use a Set literal

* Make AnalyzerRule inherit from OptInRule

* Mention analyzer_rules in readme

* Mention that analyzer rules are slow
2018-09-02 00:13:27 -07:00
Marcelo Fabri f7f3f3dee5 Merge pull request #2318 from mattremmel/nef10_missing_docs
Added back 'missing_docs' (Nef10)
2018-07-30 00:05:05 -07:00
Keith Smiley 97dc3b69e5 Rename function 2018-07-26 10:21:13 -07:00
Keith Smiley b21307530c Move glob to its own struct 2018-07-26 10:21:13 -07:00
Keith Smiley a807d723e4 Add support for globs in excluded paths 2018-07-26 10:21:13 -07:00
Matthew Remmel 89adc4224c Patch created from Nef10 (https://github.com/Nef10/SwiftLint.git) missing_docs branch, to remove merge commits that were preventing merging the PR (https://github.com/realm/SwiftLint/pull/2172) 2018-07-25 11:34:53 -04:00
Cihat Gündüz c02dd17155 Add prefix_pattern and suffix_pattern options to file_name rule 2018-07-24 16:35:38 +02:00
Marcelo Fabri 12305a8227 Fix closure-related rules when using Swift 4.2 2018-06-24 11:18:31 -07:00
Marcelo Fabri fb0241ecb1 Fix implicit_return when linting with Swift 4.2 2018-06-24 02:05:45 -07:00
Marcelo Fabri 6e987a763e Fix a false positive in unused_closure_parameter rule
Fixes #2062
2018-06-02 20:56:24 -07:00
JP Simard e2b74bd867 Require Swift 4.0 or higher to build. 2018-05-30 14:00:17 +10:00
Marcelo Fabri f2297d7387 Fix false positives in prohibited_super_call rule
Fixes #2212
2018-05-21 20:50:34 -07:00
JP Simard 84bfdca774 Enable File Name rule for SwiftLint & fix violations 2018-05-11 22:17:40 -07:00
JP Simard 6f0318e1b3 Another attempt to fix compiler issues with CocoaPods 2018-05-05 16:57:13 -07:00
JP Simard 6ff33e675b Refactor 2018-05-05 16:24:54 -07:00
JP Simard 22a6187553 Merge branch 'master' into attibute_and_modifier_order
* master:
  Remove all file headers
  Make fallthrough rule opt-in
  Update the swift file and run the unit tests
  Fix a typo
2018-05-05 15:25:43 -07:00