Commit Graph

982 Commits

Author SHA1 Message Date
JP Simard f0f0086aca
Merge pull request #3443 from realm/remove-info.plist-files
Remove Info.plist files
2020-11-23 10:47:36 -05:00
Frederick Pietschmann 26aae94f1b Drop unneeded import statement 2020-11-21 00:58:24 +01:00
Frederick Pietschmann 28cb43afa9 Fix test resources access on Linux 2020-11-21 00:35:34 +01:00
Frederick Pietschmann 715a8db2db Adjust file naming in child / parent config tests 2020-11-21 00:20:40 +01:00
Frederick Pietschmann 495d742f65 Fix issues originating from new set semantics 2020-11-21 00:05:42 +01:00
Frederick Pietschmann 4c5a3f0577 Add remote, parent & child configuration features 2020-11-20 23:08:37 +01:00
JP Simard e143a18e5c
Remove Info.plist files
These are no longer needed now that we removed the Xcode project.
2020-11-20 15:01:09 -05:00
JP Simard cd9cf682e7
Merge pull request #3441 from realm/fix-how-test-failures-are-rendered
Fix how test failures are rendered
2020-11-20 11:55:02 -05:00
JP Simard 5a077d9f3f
Fix how test failures are rendered 2020-11-20 11:19:27 -05:00
Keith Smiley b7ec75b68b Add support for testing Examples with configuration
This was extracting from another change that no longer needed it. It
should be helpful for anyone testing custom configuration with their
non-analyzer rules.

I added a random example of something that wasn't previously tested as
an example.
2020-11-16 15:37:15 -08:00
Keith Smiley 866102c3fc
Add XCTestCase examples to unused declaration rule (#3192) 2020-11-16 15:32:51 -08:00
Keith Smiley 3151e6c45f
Add NonPrivateXCTestMembersRule (#3248)
Co-authored-by: JP Simard <jp@jpsim.com>
2020-11-16 09:50:56 -08:00
JP Simard 07f559549a
Rename OverridenSuperCallConfiguration to fix typo (#3426)
* BREAKING CHANGE: As `OverridenSuperCallConfiguration` is a
publicly-exposed struct, this rename should be considered breaking.

* Fix consoleDescription for OverriddenSuperCallConfiguration
2020-11-11 13:37:12 -05:00
Jan-Otto Kröpke 874cacbd1f
Add codeclimate reporter (#3425) 2020-11-11 10:29:00 -08:00
Bryan Ricker 8a0eb67561 chore: rename OverridenSuperCallConfiguration to OverriddenSuperCallConfiguration
BREAKING CHANGE: As `OverridenSuperCallConfiguration` is a
publicly-exposed struct, this rename should be considered breaking.
2020-11-10 20:40:41 -08:00
Noah Gilmore 6d4487c517 Fix a few test which failed due to comment_spacing being a default rule 2020-11-10 16:08:25 -08:00
JP Simard bf2790df54
Enable CommentSpacingRule by default
And fix violations in SwiftLint
2020-11-10 12:50:39 -05:00
Noah Gilmore dd5c0d3599 Add CommentSpacingRule (#3233) 2020-11-09 21:54:14 -08:00
Skoti b9841595a5
Separated nesting level counting for types and functions in `nesting` rule (fixes #1151). Enhanced `nesting` rule to search for nested types and functions within closures and statements. Enhanced `nesting` rule to allow for one nested type within a function even if breaking a maximum type level nesting (fixes #1151). 2020-11-09 12:06:34 -05:00
JP Simard 76708d88f7
Remove Xcode project & Drop Carthage Support
Xcode has supported Swift Package Manager projects natively since Xcode
11, which has been out for over a year, where you can use Xcode by
having it open the `Package.swift` manifest rather than a `.xcodeproj`
or `.xcworkspace`.

I've been primarily developing SwiftLint in Xcode using this approach
for over a year, and despite a few nitpicks I have, it's been a joy to
use.

So I'd like to completely remove the Xcode project along with things
that support it:

* `SwiftLint.xcworkspace`/`SwiftLint.xcodeproj`: Neither of these are
  needed if we use `xed .` or `xed Package.swift` to develop SwiftLint
  in Xcode.
* `Cartfile`/`Cartfile.private`/`Cartfile.resolved`/`.gitmodules`/`Carthage/`:
  These were used to manage dependencies as git submodules for use in
  the Xcode workspace, but that's no longer necessary if Xcode delegates
  to SwiftPM to manage dependencies for us.
* Some scripts can be simplified, cleaned up or even completely removed.

* **Reduce duplication:** Rather than update dependencies or files in
  multiples places, there will only be the package manifest and the
  Podfile
* **Reduce merge conflicts:** This hasn't been too bad, but it's
  occasionally a pain when trying to land old PRs
* **Reduce development overhead:** No need to manually make sure that
  files in the Xcode project are sorted alphabetically
* **Reduce clone time:** No need to run
  `git submodules update --init --recursive` anymore

I think this breaks Carthage users that pull in SwiftLintFramework as a
dependency in a Cartfile.

However I can't find any references to [`SwiftLintFramework` in any
`Cartfile` files on GitHub](https://github.com/search?q=swiftlintframework+filename%3ACartfile&type=Code&ref=advsearch&l=&l=)
so this doesn't appear to be worth continuing to maintain.

Resolves https://github.com/realm/SwiftLint/issues/3412
2020-11-08 13:32:07 -05:00
Marcelo Fabri c8596a647a Add prefer_nimble opt-in rule
Fixes #3293
2020-11-08 00:09:51 -08: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
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
JP Simard 390e9a2423
Remove UnneededNotificationCenterRemovalRule (#3407)
See https://github.com/realm/SwiftLint/issues/3338 for detailed
motivation.
2020-11-07 18:59:33 -05:00
JP Simard 35ad3f941c
Add 5.3.1 to testDetectSwiftVersion() 2020-11-07 16:58:12 -05:00
JP Simard 2dcce6b184
[AttributesRule] Fix parameterized attributes (#3405)
Some attributes are parameterized, such as `@objc(name)`. Previously
these reported `attributes` violations because their contents weren't
included in the configuration, which would just have `@objc`.
2020-11-07 16:57:57 -05:00
Zsolt Kovács ac2c5e4054
Allow opening brace on newline in case of multiline function (#3068) 2020-11-07 16:02:17 -05:00
JP Simard b005920cc5
Improve compilation times (#3404)
By speeding up a handful of the longest expressions to compile.
2020-11-07 12:16:25 -08: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
JP Simard d628c41665
[IdentifierNameRule] Allow "allowed symbols" as first character (#3403)
This means that if `allowed_symbols` contains `_`, you can now write
identifiers like `let _myLet`.

Fixes https://github.com/realm/SwiftLint/issues/3306
2020-11-07 09:54:04 -08:00
Keith Smiley 5d6e25ae5f
Add TestCaseAccessibilityRule (#3376)
Co-authored-by: JP Simard <jp@jpsim.com>
2020-10-12 08:59:45 -07:00
JP Simard a67b0f26e7
Revert "Fix finding the nested config when a single file path is passed (#3342)" (#3362)
This reverts commit ea06b79e0d.
2020-09-22 08:30:52 -07:00
Seth Friedman ea06b79e0d
Fix finding the nested config when a single file path is passed (#3342)
Fixes #3341

When SwiftLint searches for nested configurations and only one file has been passed in via the `paths` argument, SwiftLint returns early after inadvertently comparing the containing directory of the file-to-be-linted to itself. This happens because `rootDirectory` is calculated from `rootPath`, which is set to the file being linted in this scenario.
2020-09-22 07:24:52 -07:00
JP Simard 6d2e8cfc06
Skip correcting files with parser diagnostics (#3349)
* Skip correcting files with parser diagnostics

Also fix many rule examples with parser diagnostics.

* Sourcery

* Link to issue in changelog entry
2020-09-17 18:14:00 -04:00
Ryan Demo 51544bb4cc
Add `excluded_match_kinds` custom rule config parameter (#3336)
This allows custom rules to define an `excluded_match_kinds` array instead of listing out all but one or a few of the `SyntaxKind`s in `match_kinds`. Rules that include both `match_kinds` and `excluded_match_kinds` will be invalid, since there's not an obvious way to resolve the two without an arbitrary priority between them.
2020-09-10 21:08:41 -04:00
cfiken 1b95821205 Fix: testDetectSwiftVersion for Swift 5.2.5 2020-08-13 12:48:33 +09:00
Marcelo Fabri 5e1c13be52 Add `unneeded_notification_center_removal` rule
Fixes #2755
2020-08-10 07:46:51 -07:00
Marcelo Fabri 6dbc0523fa Rename file 2020-08-05 20:13:53 -07:00
Marcelo Fabri 2b7230709d Move tests 2020-08-05 20:13:03 -07:00
Adrian Bolinger c156af86bc Add tests for AccessControlLevel
- add assertions for `description`
- add assertions to test 'priority'
2020-08-05 20:10:51 -07:00
antonnazarov 63bd8ce7a5 Add PreferZeroOverExplicitInitRule 2020-08-05 15:05:02 -07:00
Keith Smiley cf94d5d8ea
Add IBInspectableInExtensionRule (#3174) 2020-08-04 14:15:40 -07:00
Marcelo Fabri 9e5557fbc5
Merge pull request #3160 from realm/mf-computed_accessors_order
Add computed_accessors_order rule
2020-08-04 05:04:45 -07:00
Marcelo Fabri 0219584605 Update LinuxMain to add missing test 2020-08-04 03:24:15 -07:00
Marcelo Fabri 240e25232f Add computed_accessors_order rule
Fixes #3158
2020-08-04 03:23:36 -07:00
Marcelo Fabri 1f5ee4d9fd Run tests on Xcode 12 as well 2020-08-04 02:45:42 -07:00
Frederick Pietschmann eaff622233 Add support for Xcode 11.5 and Swift 5.2.4 2020-06-18 14:52:20 -05:00
Noah Gilmore bda1cd56e0
#3167: Fixes false positives for multiline_parameters_brackets and multiline_arguments_brackets (#3171)
* Issue #3167: Fixes false positives for multiline_parameters_brackets and multiline_arguments_brackets

* Add changelog entry

* Fix trailing comma in MultilineParametersBracketsRule nontriggering examples

* Remove header comments from ExtendedStringTests.swift

Co-authored-by: Paul Taykalo <ptaykalo@macpaw.com>
2020-05-29 11:59:02 +03:00
JP Simard 345933ebb1
Run CI on Linux Swift 5.2 (#3199)
* Run CI on Linux Swift 5.2

* fixup! Run CI on Linux Swift 5.2

* Move SwiftVersion tests to its own file
2020-05-06 14:16:17 -07:00
JP Simard 52cd6ebe06
Fix `@available` attribute to work around SR-12500
https://bugs.swift.org/browse/SR-12500
2020-05-06 13:33:10 -07:00
Cihat Gündüz 5a22b94ec6
Add new file_content_type for PreviewProvider subclasses (#3063)
Fixes #2860.

Co-authored-by: Paul Taykalo <tt.kilew@gmail.com>
2020-04-24 13:21:24 +03:00
JP Simard 889dc49bb6
Remove support for compiling with 5.0.x (#3180)
* Remove support for compiling with 5.0.x

* fixup! Remove support for compiling with 5.0.x
2020-04-14 08:46:23 -07:00
Alexander Chapliuk ef4a37ee1e
JUnit reporter for GitLab artifact:report:junit (#3177)
* Add JUnit reporter for GitLab artifact:report:junit

* Added CHANGELOG entry

Co-authored-by: Alexander Chapliuk <2318002+krin-san@users.noreply.github.com>
2020-04-12 17:14:52 +03:00
JP Simard bc4b7d2962
Update CI to run jobs with Xcode 11.0 to 11.4 (#3168)
* Update CI to run jobs with Xcode 11.0 to 11.4

In the process, remove CI jobs running with Swift 5.0.x and indicate
in the changelog that the next release will be the last one to support
building with Swift 5.0.x.

* fixup! Update CI to run jobs with Xcode 11.0 to 11.4

* fixup! Update CI to run jobs with Xcode 11.0 to 11.4

* fixup! Update CI to run jobs with Xcode 11.0 to 11.4

* fixup! Update CI to run jobs with Xcode 11.0 to 11.4

* Disable Swift 5.2 tests on Linux due to SR-12500

* Update ruby gems

Mostly to get jazzy 0.13.2 with Swift 5.2 bug fixes.
2020-04-03 18:06:22 -07:00
JP Simard c201ae43e6
Simplify regex (#3145)
* Simplify regex

`\w` already includes `_`

* Fix test
2020-03-18 16:23:52 -07:00
JP Simard d10ccacb45
Add unused_import config options to require imports for each module used (#3123)
For example, if `CGFloat` is used in a file where only `UIKit` is imported but not `CoreGraphics`, this will be a violation even if the file previously compiled.

This is because Swift allows referencing some declarations that are only transitively imported.

Enabling the `require_explicit_imports` configuration option will require that the module of every declaration referenced in a source file be explicitly imported.

This will add significant noise to the imports list, but has a few advantages:

1. It will be easier to understand all the dependencies explicitly referenced in a source file.
2. Correcting the `unused_import` rule will no longer introduce compilation errors in files that compiled prior to the correction.

If missing imports are added to a file when correcting it, the `sorted_imports` rule will be automatically run on that file.

If you with to allow some imports to be implicitly importable transitively, you may specify the `allowed_transitive_imports` configuration:

```yaml
unused_import:
  require_explicit_imports: true
  allowed_transitive_imports:
    - module: Foundation
      allowed_transitive_imports:
        - CoreFoundation
        - Darwin
        - ObjectiveC
```
2020-02-22 14:39:07 -08:00
JP Simard b744cf08f1
Temporarily remove all SwiftSyntax rules and support (#3107)
The new rules introduced in 0.39.0 that depend on SwiftSyntax have been temporarily removed as we work out release packaging issues.

* `prohibited_nan_comparison`
* `return_value_from_void_function`
* `tuple_pattern`
* `void_function_in_ternary`

See https://github.com/realm/SwiftLint/issues/3105 for details.
2020-02-11 13:40:04 -08:00
Marcelo Fabri c47db1b093 Fix testDetectSwiftVersion with Swift 5.2 (#3093) 2020-02-09 16:20:52 -08:00
Marcelo Fabri fdd16a6853
Add `prohibited_nan_comparison` opt-in rule (#3089)
Fixes #2086
2020-02-09 15:13:25 -08:00
Zsolt Kovács ab8cd43e67 Empty count configuration (#3052)
* Add `only_after_dot` configuration option to `empty_count` rule

* Update CHANGELOG.md

* Adopt Example wrapper

* Change severity level to error
2020-02-09 15:12:54 -08:00
Marcelo Fabri f95768d2e6 Add `tuple_pattern` opt-in rule (#3086)
* Add `tuple_pattern` opt-in rule

Fixes #2203

* Remove unused import
2020-02-08 13:57:17 -08: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
Marcelo Fabri 1d39071dfd
Add `void_function_in_ternary` opt-in rule (#3085)
* Add `void_function_in_ternary` opt-in rule

Fixes #2358

* Remove unused import and improve description
2020-02-08 13:23:02 -08:00
Marcelo Fabri 8d9c501cb8
Add optional return_value_from_void_function rule using SwiftSyntax (#3054)
* Add optional return_value_from_void_function rule using SwiftSyntax

* Use Script/bootstrap in CI

* Make SwiftSyntax optional

* Make SwiftSyntax optional in SPM

* Fix Package.swift

* Try again

* Add minSwiftVersion

* Fix thread sanitizer issue

* Take 2

* Fix false positive on nested computed variables

* Remove support for Xcode 10.x

* Fix rule description

* Enable opt-in rule in configuration file

* Extract code into `SyntaxRule` protocol

* nit: make property private

* Missing docs

* Fix MasterRuleList.swift

* Update CHANGELOG

* Remove unused imports

* Use Example type

* Change rule kind to .idiomatic

* Update CHANGELOG

* Bump deployment target to macOS 10.12

* Simplify SyntaxRule.validate(file:visitor)

* Make TSan happy

* Use script/bootstrap in the README
2020-02-08 02:43:40 -08:00
Marcelo Fabri 0991ede1ed
Fix tests on Linux (#3084) 2020-02-08 02:05:35 -08:00
Marcelo Fabri 5d3403a615
Fix master (#3069) 2020-02-02 16:50:07 -08:00
John Mueller be44017675
Fix false positives when line ends with carriage return + line feed (#3061)
Fixes: #3060
2020-02-02 15:37:49 -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
Steven 325af44c36 Add deinitializer to type_contents_order (#3042)
Add `deinitializer` type content to `type_contents_order` rule instead of grouping it with initializers. This allows the common use case of putting the deinitializer at the end of the class.
2020-01-16 16:49:37 -08: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
Frederick Pietschmann 3d0b568e2c Fix bug with no-syntax-kind lines (e. g. "[") 2020-01-06 10:24:13 +01:00
Frederick Pietschmann 385b6c6548 Drop unused import statement 2020-01-06 08:30:49 +01:00
Frederick Pietschmann 5c08e330d2 Update LinuxMain.swift 2020-01-06 08:30:49 +01:00
Frederick Pietschmann eb92e0b3a1 Fix wrong spacesEquivalent implementation; simplify validate method 2020-01-06 08:30:49 +01:00
Frederick Pietschmann bc6396d516 Keep linting even when seeing mixed indentation 2020-01-06 08:30:49 +01:00
Frederick Pietschmann 0bed014cba Add extensive tests for indentation_rule; fix duplicate warning avoidance mechanism 2020-01-06 08:30:49 +01:00
Frederick Pietschmann 35cd789ba1 Restructure indentation_width tests 2020-01-06 08:30:49 +01:00
Frederick Pietschmann 8c245c7581 Add new indentation_width rule 2020-01-06 08:30:49 +01:00
Marcelo Fabri c2bdb589df
Add orphaned_doc_comment rule (#3014)
* Add orphaned_doc_comment rule

Fixes #2989

* Don’t trigger on lines with only “/“
2020-01-05 20:45:06 -08:00
Pyry Jahkola 805b9ab3ba
Add capture_group option to custom_rules
This option allows for more fine-grained placement of the location
marker for code violating a custom rule, e.g.:

```swift
print("Hello world.")
             ^~~~~
```

for this `.swiftlint.yml`:

```yaml
custom_rules:
  world_preceded_by_hello:
    name: "World Preceded by Hello"
    included: ".+\\.swift"
    message: "The word World predeced by the word hello should be capitalised."
    severity: warning
    regex: "(?i:hello)\\s+(world)"
    match_kinds: [string]
    capture_group: 1
```
2020-01-05 15:24:11 -08:00
Sven Münnich 72e2063531
Include functions and getters in rule `implicit_return` 2020-01-05 15:04:35 -08:00
JP Simard cb325512fb
Run `make sourcery` 2020-01-03 19:56:18 -08:00
JP Simard 40ade98710
Update SourceKitten to 0.28.0 (#3011) 2020-01-03 16:47:18 -08:00
timcmiller 4112816077 Added 'file_name_no_space' rule (#3008)
* Added 'file_name_no_space' rule

* Removed unused var, and added to changelog

* Remove custom suffix from 'file-name-no-space' rule

* Fixed LinuxMain

* Switched to use a CharacterSet over Regex
2020-01-03 15:45:30 -08:00
Marcelo Fabri 093370c2b3
Add opt-in `prefer_self_type_over_type_of_self` rule (#3006)
Fixes #3003
2020-01-03 12:33:04 -08:00
Sven Münnich fb5361e37b Fix parsing of rule disable comments containing a URL (#2985) 2020-01-03 09:36:16 -08:00
Marcelo Fabri 2c3411dc88
Add optional_enum_case_matching rule (#3002) 2020-01-03 00:50:47 -08:00
Marcelo Fabri fbbd3fc08e
Add AutomaticTestableRule conformance to EnumCaseAssociatedValuesLengthRule (#3005) 2020-01-03 00:34:29 -08:00
ldindu 2ccb33b111 Add `enum_case_associated_values_count` opt-in rule 2020-01-02 23:24:06 -08:00
JP Simard 9ecefbd969
[UnusedImportRule] Handle comments after the import statement (#2993)
* [UnusedImportRule] Handle comments after the import statement

* fixup! [UnusedImportRule] Handle comments after the import statement

* Use \s+ to capture whitespace in regex

Co-Authored-By: Dave Lee <davelee.com@gmail.com>

* Fix testDetectSwiftVersion() with Swift 5.1.3

* fixup! Fix testDetectSwiftVersion() with Swift 5.1.3

* Handle @_exported imports

* Work around SR-11099

* Unescape newline
2019-12-18 11:30:41 -08:00
Dan Loman cc57ed3d69 Add ExpiringTodoRule (#2911)
* Add expiring todos rule

* Fix default dateFormat

* Fix date regex to handle 2-4 at beginning/end of string

* Clean up/improve clarity

* Add tests for ExpiringTodoRule

* Add output from make sourcery

* Add output from make sourcery

* Update documentation

* Enable updating of all configuration properties

* Add back Foundation import

* Add changelog entry

* Add 2 spaces after changelog entry

* Add return for legacy swift compatibility

* Add unwrapping to switch statement

* Use disable:next

* Add default values to severity config init; Add public delimiter init

* Add tests for various custom configurations

* Remove unused funcs

* Add extra tests to LinuxMain file

* Update File type -> SwiftLintFile

* Move Changelog entry

* Shorten changelog entry line length

* Fix changelog
2019-11-20 16:50:29 -08:00
JP Simard 5f66704a1a
Improve compilation time (#2965)
* Improve compilation time

Before this change, `trailingClosure` took 8.6s to type check.
After this change, it takes 31ms.

* Speed up type checking `isDecimal(number:)`

Before: 377ms
After: 2ms

* Speed up type checking testViolationMessageForExpressibleByIntegerLiteral()

Before: 285ms
After: 175ms

* Fix OSSCheck

More than just rules are in `Source/SwiftLintFramework/Rules/`

* Shim XCTUnwrap for Swift 5.0
2019-11-15 11:36:25 -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
Norio Nomura 80d3813214
Add GitHub Actions Logging reporter (`github-actions-logging`)
Use [GitHub Actions Logging](https://help.github.com/en/github/automating-your-workflow-with-github-actions/development-tools-for-github-actions#logging-commands) same as https://github.com/norio-nomura/action-swiftlint does.
2019-11-04 19:36:25 +09:00
MarkoPejovic 109899c56c Implement #2888 2019-10-20 19:19:54 -07:00
Marcelo Fabri 31ca623eb0 Fix unit test 2019-10-13 23:43:07 -07:00
Marcelo Fabri f211694e7d
Merge pull request #2885 from realm/mf-flatmap
Add `flatmap_over_map_reduce` opt-in rule
2019-09-26 11:02:58 -07:00
Marcelo Fabri 2457843c7c Generate docs with Xcode 11 2019-09-26 10:11:38 -07:00
Marcelo Fabri d4ef1f0ad0 Add `flatmap_over_map_reduce` opt-in rule
Fixes #2883
2019-09-26 10:07:12 -07:00
Nathan Van Fleet 406a8f20f8 Add Mark rule for triple slash Mark comments (#2868)
* Add Mark rule for triple slash Mark comments

* Move changelog entry to appropriate section

* Re-add Package.resolved

* Fix trailing comma

* Rebuild Rules.md using Xcode 10.3

* Combine two regexes into one
2019-09-18 17:21:13 -07:00
Colton Schlosser 2c076151f4 Add `contains_over_range_not_nil` rule, make `contains_over_first_not_nil` also match == nil (#2811) 2019-09-03 12:03:00 -04:00
JP Simard ffb2f4f76d
Require Swift 5.0 to build (#2857)
* Require Swift 5.0 to build

* Update CI

* Stop testing with Swift 4.x & Xcode 10.0/10.1
* Use official Swift docker image instead of norionomura's
* Use Xcode 10.3 as latest stable version

* Update READMEs

* Fixup xcodeproj

* Fixup CI Swift container image tag

* Fixup changelog
2019-09-03 11:42:57 -04:00
Marcelo Fabri 40bc8de5c7 Add no_space_in_method_call rule (#2855)
* Add no_space_in_method_call rule

* Avoid false positive with typecasting
2019-09-03 10:03:21 -04:00
Colton Schlosser 130371b8cc Add `empty_collection_literal` rule 2019-08-28 21:57:02 -04:00
Marcelo Fabri 3e115835b1
Merge pull request #2846 from realm/mf-contains_over_filter_is_empty
Add `contains_over_filter_is_empty` opt-in rule
2019-08-25 20:55:11 -07:00
Marcelo Fabri 67526344ef Add `contains_over_filter_is_empty` opt-in rule 2019-08-25 20:22:41 -07:00
Marcelo Fabri 759ccd8a1e Avoid false positives in contains_over_filter_count 2019-08-25 20:11:23 -07:00
Marcelo Fabri 00d2b5d772 Add contains_over_filter_count opt-in rule
Fixes #2803
2019-08-25 20:00:50 -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 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 ddee9c8e6b Refactor spacing, indenting, and rename collect to collectInfo 2019-07-18 14:59:42 -07:00
Elliott Williams 7f0302f89a Test that CollectionCorrectableRule is called correctly 2019-07-18 14:59:42 -07:00
Elliott Williams 1c56d30db6 Add CollectingRuleTests 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
JP Simard 18c78684b0
Remove unused declarations (#2816) 2019-07-18 13:52:57 -07:00
JP Simard 3a0c2b0c05
Migrate LinterCache to use Codable models (#2799)
* Migrate LinterCache to use Codable models

improving performance and type safety

* Fix Linux

* Avoid creating a Decoder if it won't be used

For example if the file doesn't exist or can't be read.

* Use corelibs plist coder if available

It's available in the Swift 5.1 branch: https://github.com/apple/swift-corelibs-foundation/pull/1849

* Remove unused error case
2019-07-07 00:35:10 -07:00
Marcelo Fabri 596bf8dbc8 Detect parameter attribute in vertical_parameter_alignment
Fixes #2792
2019-07-04 10:42:11 -07:00
Marcelo Fabri 6be5bf74c3
Add legacy_multiple opt-in rule (#2771)
Fixes #2612.
2019-06-01 22:49:23 -07:00
Marcelo Fabri 90cb1349c0
Add `duplicate_enum_cases` rule (#2777)
Fixes #2676
2019-06-01 20:32:55 -07:00
Marcelo Fabri 862913f0c0
Don't trigger no_fallthrough_only if next case is @unknown (#2770)
* Don't trigger no_fallthrough_only if next case is @unknown

Fixes #2696
2019-05-25 21:53:23 -07:00
JP Simard c216ccc1e5
Remove WeakComputedProperyRule (#2761)
* Remove WeakComputedProperyRule

Addresses https://github.com/realm/SwiftLint/issues/2712

* fixup! Remove WeakComputedProperyRule
2019-05-16 02:19:01 -07:00
Kevin Randrup d7439410e9 Introduce " - " delimiter to allow rules to be commented (#2721)
* Introduce " - " delimiter to allow rules to be commented
Ex. swiftlint:disable:next force_try - Explanation here

* Fix changelog formatting
2019-05-12 21:40:12 -07:00
Marcelo Fabri a3aa36757b Add `unowned_variable_capture` opt-in rule
Fixes #2097
2019-04-30 10:12:20 -07:00
Frederick Pietschmann 3b9917f89d Add nested type handling specification to file_name rule (#2718)
* Add nestedTypeSeparator to FileNameConfiguration

* Add tests for nested_type_separator configurability of file_name rule

* Add changelog entry

* Fix changelog position after rebase
2019-04-30 08:12:43 -07:00
Norio Nomura 0de15e119d
Make `testSimulateHomebrewTest()` test opt-in
because it may fail on unknown condition.
Set `SWIFTLINT_FRAMEWORK_TEST_ENABLE_SIMULATE_HOMEBREW_TEST` environment variable to test like following:
```terminal.sh-session
$ SWIFTLINT_FRAMEWORK_TEST_ENABLE_SIMULATE_HOMEBREW_TEST=1 \
swift test --filter testSimulateHomebrewTest
```
2019-04-30 08:55:01 +09:00
Marcelo Fabri 3a36212b94 Swift 5 support (#2720)
* Update project to compile with Xcode 10.2

* Fix explicit_acl with Swift 5

* Update macOS VM image

* Fix ConfigurationTests on Swift 5

* Update Podspec

* Workaround SR-10486 to fix validation tests

* Fix testDetectSwiftVersion on Swift 5

* Update specs repo when validating CocoaPods spec

* Fix redundant_set_access_control tests

* Manually update Package.resolved

* Use .upToNextMinor

* [Azure Pipelines] Add `sw_vers`

* Relax expecting conditions for crashing output in `testSimulateHomebrewTest()`

Because TSAN makes `swiflint` to produce additional output on crashing.

* Add CHANGELOG entry

* Ignore extensions in explicit ACL rules

* Work around SR-10486 for Sourcery
2019-04-28 21:10:06 -07:00
Marcelo Fabri ad2733391a
Merge pull request #2666 from daltonclaybrook/dc-reduce-into-rule
Add reduce_into opt-in rule
2019-04-15 14:52:04 -07:00
Dalton Claybrook d8f671c315 WIP - create unused capture list rule 2019-04-13 23:12:25 -04:00
Frederick Pietschmann 43e18458de Update file headers for new sourcery version 2019-04-12 17:13:27 +02:00
Frederick Pietschmann 71d4fe9a24 Adjust disable all / superfluous_disable_command test 2019-04-12 17:13:13 +02:00
Frederick Pietschmann 4cd6cafcbf Make sourcery 2019-04-12 16:27:54 +02:00
Frederick Pietschmann 81abf9f3f2 Let "disable all" command override "superfluous_disable_command" rule 2019-04-12 16:27:43 +02:00
Frederick Pietschmann 70d9eef09b Add test whether superfluous disable command respects disable all command 2019-04-12 15:53:34 +02:00
Marcelo Fabri 51d47d492c `contains_over_first_not_nil` rule now also checks for `firstIndex(where:)`
Fixes #2678
2019-04-09 10:53:42 -07:00
Matthew Healy eecf27ede8 [nslocalizedstring_require_bundle] Run make sourcery 2019-03-30 00:10:14 +01:00
Cihat Gündüz 311965f23c Fix issues after rebase 2019-03-27 10:34:58 +01:00
Cihat Gündüz 4f2f0ac350 Fix issue with missing types in older Swift versions 2019-03-27 10:34:41 +01:00
Cihat Gündüz f3ccc8cd4c Regenerate file for Linux testing & fix leftover 2019-03-27 10:34:41 +01:00
Cihat Gündüz 50fba286ab Add tests for different configurations in type_contents_order 2019-03-27 10:34:41 +01:00
Cihat Gündüz bea1d31937 Add tests for different configurations in file_types_order 2019-03-27 10:34:41 +01:00
Cihat Gündüz 38277b75b5 Cleanup after rebase 2019-03-27 10:34:41 +01:00
Cihat Gündüz 7b94984175 Split new rule up into two separate rules 2019-03-27 10:34:40 +01:00
Cihat Gündüz f379fdef77 Define new rule file_content_order with examples & tests 2019-03-27 10:34:40 +01:00
Dalton Claybrook 87dbf8e3d7 Fix Changelog issue, Sourcery version mismatch, and package.resolved issue 2019-03-24 16:22:19 -04:00
Dalton Claybrook 7c2e4dfd19 Add ReduceIntoRule 2019-03-24 16:22:19 -04:00
Xaver Lohmüller 57af7f0e30 Add ReduceBooleanRule (#2675)
* [reduce_boolean] Implement rule

* [reduce_boolean] Improve reason text

* [reduce_boolean] Fix new violations

* [reduce_boolean] Add CHANGELOG.md entry

* [reduce_boolean] Shorten rule name

* [reduce_boolean] Use regular map instead of compactMap

* [reduce_boolean] Match only possible syntax kinds
2019-03-10 10:54:14 -07:00
Matthew Healy a75198f9d0 [nsobject_prefer_isequal] Add autogenerated documentation 2019-03-01 21:15:03 +01:00