Commit Graph

73 Commits

Author SHA1 Message Date
Andyy Hope 5e15039554
Move `excludedPaths` out of iteration loop to speed up lint times (#4955) 2023-05-06 16:43:33 -04:00
Chris White 71b89e66de
Prepend `warning: ` to error messages (#4927) 2023-05-01 18:26:25 +02:00
Danny Mösch 500f143c7d
Remove unused code (#4729) 2023-01-28 19:50:22 +01:00
JP Simard e0f23fa8e9
Add `--progress` flag to lint and analyze commands (#4147)
Inspired by https://github.com/jkandzi/Progress.swift

```
4948 of 29100 [=====                         ] ETA: 44s (540 files/s)
```

Demo:

[![asciicast](https://asciinema.org/a/517985.svg)](https://asciinema.org/a/517985)
2022-08-31 18:26:17 -04:00
JP Simard a97718f4c6
Replace incrementer dispatch queue with an actor (#4073)
To support this, we first must use an async entrypoint to the CLI, which
we do by changing the lint and analyze commands to conform to
`AsyncParsableCommand`.

The in order to map over the closures with suspension points, we pull in
CollectionConcurrencyKit as a new dependency.

This change does not touch SwiftLintFramework, only the CLI target.
2022-08-09 13:06:08 +00:00
JP Simard 2b00164081
Remove uses of `Result` in CLI target (#4071)
Which will make it easier to adopt some structured concurrency features
in the future.
2022-08-08 23:04:20 -04:00
JP Simard 559470a245
Integrate OS Signposts to help profile SwiftLint performance (#3535)
* Integrate OS Signposts to help profile SwiftLint performance

* Split LintOrAnalyzeCommand.lintOrAnalyze(_:) into two functions

Using a builder reference type to share common mutable state.
2021-02-24 10:03:53 -08:00
JP Simard fa55508668
Migrate from Commandant to swift-argument-parser 2020-12-14 15:51:04 -05:00
JP Simard f926cfaabd
fixup! fixup! Fix logging linting the current working directory 2020-12-01 14:47:25 -05:00
JP Simard 0019c61de7
fixup! Fix logging linting the current working directory 2020-12-01 14:46:46 -05:00
JP Simard b73673ab01
Fix logging linting the current working directory
Fixes log messages saying `Linting files at path ''` that should have
said `Linting files in current working directory`.
2020-12-01 14:34:16 -05:00
Frederick Pietschmann 4c5a3f0577 Add remote, parent & child configuration features 2020-11-20 23:08:37 +01:00
Seth Friedman 6d77deb359
Use working directory as root path instead of trying to calculate it (#3384)
We currently try to derive the root path by using the path passed in. However, this doesn't allow us to actually get the root, just the containing directory of the path passed in. We also don't currently have a heuristic to use for deriving the root path for multiple paths passed in.

The fix (which fixes #3383) is to remove our root path calculation and just use the current working directory as the root instead.
2020-11-07 23:51:44 -05:00
Seth Friedman e316bd693d
Fix finding the nested config when a single file path is passed (#3379)
This was previously attempted in #3342, but produced a bug in the case where `--config` is used to specify a config from outside of the source tree. The `--config` argument wasn't always being used as an override, and was being merged with the config in the source tree. This has now been addressed and reverts the revert done in #3362. 

Fixes #3341
2020-11-07 23:07:03 -05:00
Mikhail Monakov fc0092dc8c
Add excluding by prefix option (#3345)
As we discussed here https://github.com/realm/SwiftLint/pull/3325 sometimes current excluding algorithm maybe slower than excluding paths by absolute prefix. So I added option for such cases.

Based on what I've checked it works faster for next scenarios:
- the number of input files is relatively small (e.g. when using `use-script-input-files`) and excluded directories contain relatively big number of lintable files
- the number of excluded directories relatively small (e.g. Pods + ThirdParty) and globs not used
2020-11-07 10:54:06 -08:00
Marcelo Fabri f8ef7d649c Enable legacy_multiple and prefer_self_type_over_type_of_self in our codebase 2020-08-05 01:11:17 -07: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
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
JP Simard b7c1db7245 Fix duplicate path printing 2019-07-18 14:59:42 -07:00
JP Simard 08816840ef Re-add outputFilename 2019-07-18 14:59:42 -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 97f8d4803d Break Configuration.visit into multiple functions and fix index bug
The post-collection visitor in `Configuration.visit` was iterating over
the total fileCount given, not just the files that could be collected.
This meant than when a file was skipped, the visitor would end up
referencing a linter past the end of its array, causing a crash.
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 c338f292c3 Make shim autorelease function generic over its return value 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
Keith Smiley 6ac0894a40 Print relative path for duplicate filenames (#2768)
In projects with multiple Swift targets, it's possible to have multiple
Swift files with the same name. In this case you can't differentiate
from the log, which one SwiftLint is printing about. Now in this case it
prints the relative (to your pwd) path of the file.
2019-07-08 06:56:04 -07:00
JP Simard a97487f3e1
Refactor `Configuration.groupFiles(...)` for style and performance (#2707)
* Move changelog entry to appropriate section

* Refactor file exclusion from groupedFiles for performance and style
2019-04-07 16:59:44 -07:00
Dylan Bruschi 9396a0a32b Fix bug where nested configuration excluded files are ignored (#2648)
Fixes #2447

When SwiftLint is linting files in `visitLintableFiles` in `Configuration+CommandLine`, it:

1. Gathers all lintable files in `getFiles`. This is where the exclusion of files occurs based on the parent configuration's exclusion list.
2. These files are grouped by their specific configuration in `groupFiles`. This is where configurations for each available file are determined (and if nested configurations exist, merged). After these configurations are determined and the files are grouped accordingly, no more files are excluded from the lintable files list. Even though a file's configuration thinks it should be excluded, these files are not removed from the list of lintable files, generating the bug.
3. Finally, each file is visited by the linter.

My solution is to skip files whose merged configurations specify they should be excluded in step 2 or `groupFiles`. Therefore, they will not be visited in step 3.
2019-04-07 15:43:29 -07: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 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
Ben Asher 7a32b8d4c2 Support for multiple paths 2018-07-23 10:13:55 -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
Norio Nomura 2a0ac455bc
'flatMap' is deprecated: renamed to 'compactMap(_:)' 2018-04-08 13:28:09 +09:00
Ash Furrow 63658418c4 Adds unit test for force-exclude flag. 2018-03-22 09:42:56 -07:00
Ash Furrow 7ed962d1ee Adds force-exclusion config. 2018-03-22 09:42:56 -07:00
JP Simard b2227accc3
Avoid calling `cacheDescription` when the cache is disabled
This skips an expensive JSON serialization call.
2017-11-09 12:28:45 -08:00
JP Simard 3a32d6b479
Speed up reading cached results by about 200%
also slightly speed up writing to the cache.

For example, on the Lyft codebase with 1,500 Swift files:

```bash
$ time swiftlint lint --quiet
swiftlint --quiet  3.53s user 0.27s system 388% cpu 0.979 total
$ rm -rf ~/Library/Caches/SwiftLint && time swiftlint lint --quiet
swiftlint --quiet  35.20s user 1.22s system 371% cpu 9.806 total
$ time swiftlint lint --quiet
swiftlint lint --quiet  0.90s user 0.13s system 218% cpu 0.472 total
$ rm -rf ~/Library/Caches/SwiftLint && time swiftlint lint --quiet
swiftlint lint --quiet  31.78s user 1.18s system 360% cpu 9.146 total
```
2017-10-19 23:17:01 -07:00
Marcelo Fabri 68c1f3c1ab Fix configuration issue when using custom paths
Fixes #1631
2017-06-24 22:54:10 +02:00
Marcelo Fabri 33955234b3 Skip files with valid cache & no violations when auto correcting 2017-05-28 12:47:52 +02:00
JP Simard 97bdac211a
keep a single cache file for all of SwiftLint 2017-05-18 14:45:46 -07:00
JP Simard 9b51973961
actualy pass enableAllRules value to Configuration initializer 2017-01-12 14:13:48 -08:00
Marcelo Fabri b7b905c3e5 Merge branch 'master' into cache 2017-01-10 14:33:04 -02:00
JP Simard 9db40bf3e1
update swiftlint/Extensions to follow Swift 3 API Design Guidelines 2017-01-10 08:00:17 -08:00
Marcelo Fabri e1e2369c5f Merge branch 'master' into cache 2017-01-10 12:54:30 -02:00
JP Simard c5c2e21120
update SwiftLintFramework/Models to follow Swift 3 API Design Guidelines 2017-01-09 19:05:29 -08:00
Marcelo Fabri 119c214492 Merge remote-tracking branch 'upstream/master' into cache 2017-01-02 16:29:32 -02:00
JP Simard 3608cf4675
re-add autoreleasepool around visitorBlock invocation 2017-01-01 10:50:10 -08:00
JP Simard 8774a921a6
use DispatchQueue.concurrentPerform rather than rolling our own
also remove parallelForEach from SwiftLintFramework's public interface
since calling the GCD API is almost as concise and avoids polluting the
public API.

Finally, also remove the "fast" path for parallelMap since GCD should
do the reasonable thing for us here.
2016-12-31 17:06:02 -08:00