Commit Graph

37 Commits

Author SHA1 Message Date
Danny Mösch fe312a06fe
Rely on pre-defined issues and allow to print them directly to the console (#5013)
Advantages of having typical errors at a common place:
* Error message styling can be harmonized
* Existing messages can be reused
* Overview of prefixes ('error: ', 'warning: ')
* Manage how to print them to the console
2023-05-16 20:15:14 +02:00
Danny Mösch 1fa8e484c4 Add expiring TODO comments on deprecation warnings 2023-05-10 21:44:20 +02:00
Chris White 71b89e66de
Prepend `warning: ` to error messages (#4927) 2023-05-01 18:26:25 +02:00
JP Simard 603fff9a82
Make `Correction` and `CorrectableRule` declarations public (#4937)
The CLI target shouldn't be importing SwiftLintFramework with
`@_spi(TestHelper)`. If the CLI target needs to access something in
SwiftLintFramework, that declaration should be `public`.
2023-04-26 12:17:10 -04:00
Danny Mösch e64e82d80d Get rid of periods finishing rule descriptions 2023-01-10 22:29:13 +01:00
Ryan Aveo 92304cdd98
Fix building tests in Xcode (#4607)
Co-authored-by: JP Simard <jp@jpsim.com>
2022-11-30 10:33:33 -05:00
César Pinto Castillo c56e19a0c2
Fix SwiftLint support on Xcode Cloud (#4485)
Fixes #4484 by checking the process environment for all the expected
environment variables set by Xcode Cloud.
2022-11-01 13:00:50 -04:00
JP Simard 359699cea7
Report memory usage when `--benchmark` is specified (#4442)
With the memory increase related to
https://github.com/apple/swift-syntax/issues/921,
I wanted a way to quickly know how much memory was being used by
SwiftLint.

Here's how much memory it took to lint SwiftLint itself at various
versions in the last few weeks:

* 0.49.1: 223 MB
* 0.50.0-rc.1: 356 MB
* 0.50.0-rc.2: 444 MB
* main (458916174): 464 MB

```console
$ swiftlint --progress --benchmark
Linting Swift files in current working directory
529 of 529 [==============================] ETA: 0s (121 files/s)
Done linting! Found 0 violations, 0 serious in 529 files.
Memory used: 464 MB
$ swiftlint --progress --benchmark
Linting Swift files in current working directory
529 of 529 [==============================] ETA: 0s (16220 files/s)
Done linting! Found 0 violations, 0 serious in 529 files.
Memory used: 55.8 MB
```
2022-10-21 19:04:43 +00:00
JP Simard de0b91cd5a
Print violations in realtime if progress with an output file (#4362) 2022-10-13 06:23:24 +00:00
Danny Mösch 9db88947b9
Fix bugs when auto-correcting content given via stdin (#4212)
Fixes #4211.
Fixes #4234.
Fixes #4347.
2022-10-13 00:34:48 -04: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
Danny Mösch 9875ab904b
Print autocorrected STDIN input to STDOUT (#4132) 2022-08-28 23:17:20 +02:00
JP Simard cf764e7b90
Fix hang after linting or analyzing on Linux (#4123)
Fixes https://github.com/realm/SwiftLint/issues/4117
2022-08-23 13:45:10 -04:00
JP Simard ac23f2e89a
Log time spent in each custom rule (#4100) 2022-08-15 22:03:06 -04:00
JP Simard 21ba7c8280
Update SourceKitten to 0.33.0 (#4085)
https://github.com/jpsim/SourceKitten/releases/tag/0.33.0
2022-08-11 21:04:32 +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 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 e92a3aeae9
fixup! fixup! Add `--in-process-sourcekit` command line flag 2022-03-31 12:49:12 -04:00
JP Simard 4c14678d77
fixup! Add `--in-process-sourcekit` command line flag 2022-03-31 11:42:42 -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 706abfe9e3
Tweak the auto-correction result console output for clarity (#3522)
A colleague was confused by the output of `swiftlint autocorrect`, she
couldn't understand why SwiftLint told her it corrected thousands of
files when she only touched one.

The "Done correcting \(files.count) ..." output made her think that a
change was made on each of the `files`, when really they had only been
inspected.

A good solution would be to adopt a similar approach as the `lint`
command does.

Not being familiar with the codebase, I though a good first step could
have been to tweak the message a bit, making it clearer that the count
printed to the console is the inspected files.
2021-02-25 17:20:58 -05: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
Gio Lodi 8248178213
Tweak the auto-correction result console output for clarity
A colleague was confused by the output of `swiftlint autocorrect`, she
couldn't understand why SwiftLint told her it corrected thousands of
files when she only touched one.

The "Done correcting \(files.count) ..." output made her think that a
change was made on each of the `files`, when really they had only been
inspected.

A good solution would be to adopt a similar approach as the `lint`
command does.

Not being familiar with the codebase, I though a good first step could
have been to tweak the message a bit, making it clearer that the count
printed to the console is the inspected files.
2021-02-16 20:41:04 +11:00
JP Simard fa55508668
Migrate from Commandant to swift-argument-parser 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
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
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
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
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
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
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