Commit Graph

317 Commits

Author SHA1 Message Date
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
JP Simard b83e0991b9 Remove all file headers
The MIT license doesn't require that all files be prepended with this
licensing or copyright information. Realm confirmed that they're ok with this
change. This will enable some companies to contribute to SwiftLint and the
date & authorship information will remain accessible via git source control.
2018-05-04 13:42:02 -07:00
JP Simard 382263868e Tweak code format for arrays 2018-04-28 15:28:13 -07:00
Daniel Metzing 9a7005912a Add modifiers_order rule 2018-04-26 20:25:58 +02:00
Daniel Metzing b2bb9d6c89 Merge remote-tracking branch 'upstream/master' into upstream_master 2018-04-26 15:10:14 +02:00
Daniel Metzing 5283598794 Merge remote-tracking branch 'upstream/master' into upstream_master 2018-04-25 12:43:06 +02:00
Marcelo Fabri e2b195a4e2 Use SwiftDeclarationAttributeKind instead of string constants 2018-04-24 22:23:36 -07:00
Daniel Metzing c68a28dba5 Adding rule 2018-04-10 22:52:16 +02:00
Marcelo Fabri 1a9a4f7516 Add redundant_set_access_control rule
Fixes #1869
2018-04-08 21:54:50 -07:00
Norio Nomura 133cef8df1 ObjCBool is no longer implicitly converted to Bool on Linux 2018-04-08 13:28:09 +09:00
Norio Nomura 2a0ac455bc 'flatMap' is deprecated: renamed to 'compactMap(_:)' 2018-04-08 13:28:09 +09:00
Norio Nomura 7d0f239e2a Update dependencies
- Update SourceKitten from 0.19.1 to 0.20.0
- Update SWXMLHash from 4.3.6 to 4.6.0
- Update Yams from 0.5.0 to 0.7.0
2018-04-08 13:28:08 +09:00
Ash Furrow 7ed962d1ee Adds force-exclusion config. 2018-03-22 09:42:56 -07:00
Frederick Pietschmann fdbc391e52 Improve all keyword-related code
As per PR #2095 review, suggested by @marcelofabri
2018-03-21 07:42:46 +01:00
Frederick Pietschmann 0ad2488d7e Add all keyword 2018-03-21 07:42:46 +01:00
Cyril Lashkevich 10ba712748 Fix for crash on Linux on sources with surrogate characters
Because of the bug https://bugs.swift.org/browse/SR-5971 SwiftLint
crashes when linting on Linux files like https://github.com/xmartlabs/Eureka/blob/master/Example/Example/ViewController.swift
2018-03-17 19:51:24 +01:00
Norio Nomura 85542a6f8d Remove DispatchQueue.sync from Array.parallelMap
`DispatchQueue.sync` was required to avoid CoW on calling `subscript` from multiple copied instances of `Array`.
Since `UnsafeMutableBufferPointer` does not cause CoW on same situation, `DispatchQueue.sync` can be removed.
2018-03-08 15:56:28 +09:00
JP Simard a7a8a69fa2 Improve Array.parallelMap
By applying concepts from Swift Talk 90: https://talk.objc.io/episodes/S01E90-concurrent-map

Notably:
* Removing `@escaping` from block parameter
* Avoiding Array.append & sorting
* Using a constant DispatchQueue label
2018-03-07 09:27:35 -08:00
Jamie Edge 0a4b562452 Removed dependency upon non-Linux NSString method. 2018-02-11 18:01:09 -08:00
Jamie Edge b80798b875 Fix directories with a '.swift' suffix being treated as files. 2018-02-11 18:01:09 -08:00
Marcelo Fabri 5eb48d69b7 Merge pull request #2030 from mshibanami/ignoring_functions_of_line_length
Fix ignores_function_declarations of line_length doesn't work in some cases
2018-02-03 23:05:53 -08:00
Manabu Nakazawa 9677c92285 Fix ignores_function_declarations of line_length doesn't work in some cases 2018-02-04 15:44:35 +09:00
Marcelo Fabri 03b4d6b020 Fix violations introduced when linting with Swift 4.1
Part of #2021
2018-02-03 22:23:48 -08:00
JP Simard 623590acd1 Update dependencies 2018-02-01 15:35:41 -08:00