Commit Graph

190 Commits

Author SHA1 Message Date
Vasiliy Kattouf 129a55fb74
Add ability to filter rules for `generate-docs` subcommand (#4195)
Added rules filtering options, like in the `rules` subcommand.

<img width="880" alt="generate-docs--help" src="https://user-images.githubusercontent.com/7829589/189372666-2f5aba62-57a1-49dc-9155-c60f9e085984.png">

To achieve reuse with `rules` subcommand:
- extracted filtering logic into `RulesFilter` (and write tests)
- extracted filtering command line parameters into `RulesFilterOptions: ParsableArguments`
2022-10-04 18:45:52 +00:00
JP Simard 4fb5ebe19b
Docker: Update to Swift 5.7 & Ubuntu Jammy (#4241)
And apply workaround for https://github.com/apple/swift/issues/59961 to
all commands.
2022-09-24 15:09:41 -04: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 4bc6588f38
Add `--output` option to lint and analyze commands (#4148)
To write to a file instead of to stdout.

Addresses https://github.com/realm/SwiftLint/issues/4048
2022-08-31 17:34:37 -04:00
JP Simard 73c88c3af0
Add `version --verbose` command (#4102)
Prints out something like this on macOS:

```
Version: 0.49.0-rc.1
Build ID: B43931F3-D096-3704-B41C-FC40673A3F96
```

This can be used to determine if two `swiftlint` executables are
identical.
2022-08-16 14:12:44 +00: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 ec8ba17388
Use `@main` attribute (#4072)
This will allow us to have an async entrypoint and use structured
concurrency features in the future.
2022-08-09 03:48:12 +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 24735ef4d3
Add support for building with Bazel (#4038) 2022-07-26 07:09:02 -04:00
Danny Mösch 86e765c418
Deprecate the `--path` option in favor of the positional `paths` argument (#3952)
There is no real benefit for this option. Files and folders to lint/analyze
can be passed to `swiftlint` as last arguments. There cannot be multiple
`--path` arguments. If there is more than one only the last path is considered.
2022-06-14 23:10:28 +02:00
Marcelo Fabri 4382ef49b9
Use URL(fileURLWithPath:isDirectory) to avoid file system call (#3976) 2022-05-26 21:54:23 +02:00
Danny Mösch 291b500269
Analyze all files listed in the command even if the `--path` option is used (#3951) 2022-04-15 10:36:29 -04:00
coffmark 564c6ddb55
Lint all files listed in the command even if the `--path` option is used (#3923) 2022-04-13 15:13:08 -04:00
Juozas Valančius 62cc0f1a32
Add `--in-process-sourcekit` command line flag 2022-03-31 09:46:21 -04:00
JP Simard 60ec029e1b
Re-add --format flag to reformat Swift files using SourceKit (#3573)
Missed during the migration from Commandant to swift-argument-parser in
https://github.com/realm/SwiftLint/pull/3465.

Fixes https://github.com/realm/SwiftLint/issues/3571.
2021-03-15 11:15:09 -04:00
JP Simard 5134545093
Make `--strict` mutually exclusive with `--lenient` 2020-12-14 15:54:08 -05:00
JP Simard 7351648590
Fix paths argument handling 2020-12-14 15:53:50 -05:00
JP Simard 6bad2eccdf
Remove unused imports 2020-12-14 15:53:49 -05:00
JP Simard fa55508668
Migrate from Commandant to swift-argument-parser 2020-12-14 15:51:04 -05:00
JP Simard 82b00bf4b5
Rename command files 2020-12-14 15:51:04 -05:00
Frederick Pietschmann 4c5a3f0577 Add remote, parent & child configuration features 2020-11-20 23:08:37 +01:00
JP Simard 8bf8ca482a
Fix deprecation compiler warnings on Linux for ShowDocsCommand.swift 2020-11-20 15:00:54 -05:00
Dalton Claybrook d305e03905
Add `inclusive_language` rule (#3243)
Current events have renewed the conversation in our community about the roles of terminology with racist connotations in our software. Many companies and developers are now taking appropriate steps to remove this terminology from their codebases and products. (e.g. [GitHub](https://twitter.com/natfriedman/status/1271253144442253312)) This small rule prevents the use of declarations that contain any of the terms: whitelist, blacklist, master, and slave. It may be appropriate to add more terms to this list now or in the future.
2020-11-07 22:03:08 -05:00
Cihat Gündüz 81942449d3
Adjust --strict to treat warnings as errors instead of only altering exit code (#3372) 2020-11-07 15:47:38 -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 e6d9f72cad Rename command 2020-08-05 20:37:49 -07:00
417-72KI 6c0f8365b3 Remove backquotes and "Framework" from the sentence 2020-08-05 20:34:33 -07:00
417-72KI 6e237f77b8 Fix URL 2020-08-05 20:34:33 -07:00
417-72KI 623e69e623 Add `show-docs` command 2020-08-05 20:34:33 -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
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
Optional Endeavors 8fb900650b
Add support for showing only correctable rules, and a switch for ignoring the width of the terminal so full configuration detail is always shown. 2020-01-05 15:19:45 -08:00
Dave Lee 36e8d9f581 Add support for compilation databases (#2962)
* Add --compile-commands flag

* Implement support for --compile-commands

* Turns out you can't use yaml to read compile_commands.json

* refactor all the things

* Add changelog entry

* formatting

* Add comment and typealiases

* typo

* fix bool logic

* support directory field in compile commands

* remove "directory" field support

* filter compilation database args too

* Remove initial `swiftc` from args

* grammar
2019-12-03 10:36:18 -08:00
JP Simard beaa2a8a87
Update Commandant and SourceKitten, drop Result (#2947) 2019-11-07 10:59:16 -08:00
JP Simard e312b06f71
Fix `swiftlint rules` output table formatting (#2828)
Fixes https://github.com/realm/SwiftLint/issues/2787

Broken since https://github.com/realm/SwiftLint/pull/2379
2019-07-28 16:12:27 -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
Jim Hildensperger c3d72c2442
Only mark custom rules as enabled in your config when custom rules are configured. 2018-11-28 13:42:11 -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
Ornithologist Coder 371e7b4995 Run format before autocorrect (#2383) 2018-09-02 14:35:39 -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
JP Simard b38758b902
Completely remove deprecated `--use-tabs` option (#2376) 2018-09-01 12:50:31 -07:00
Ben Asher 32e8c5bbc3 Fix extra array copies 2018-07-23 10:13:55 -07:00
Ben Asher 7f86dc4c44 Fix paths arg eating other params 2018-07-23 10:13:55 -07:00
Ben Asher 3f1acd6ca1 Prefer single path, if it's provided; fix multi-path 2018-07-23 10:13:55 -07:00
Ben Asher 7a32b8d4c2 Support for multiple paths 2018-07-23 10:13:55 -07:00
Marcelo Fabri 701abbea94 Don’t overwrite file when formatting if not needed
Fixes #2249
2018-06-24 11:38:38 -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
John Szumski a1f5fb9ee0 Fixed issue where the autocorrect done message used the plural form of "files" even if only 1 file changed. 2018-03-27 21:49:00 -04:00