Commit Graph

214 Commits

Author SHA1 Message Date
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
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
John Buckley efe8816315
ImplicitReturnConfiguration description now reports current config (#3083)
* ImplicitReturnConfiguration description now reports current config.

Previously only the default config was reported.

* Updating CHANGELOG.md
2020-02-08 01:55:58 -08: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 399f5b7df6
Fix docstring formatting issues using DrString (#3032)
Using command:
$ drstring check -i 'Source/**/*.swift' --first-letter lowercase --vertical-align
2020-01-12 11:19:33 -08:00
JP Simard 37167a8a35
Add documentation comments to all public declarations (#3027) 2020-01-08 09:47:10 -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 98e870e726 Fix modifier order 2020-01-06 08:30:49 +01:00
Frederick Pietschmann 3a8ad943c3 Add configuration option whether to consider comment lines for indentation_width rule 2020-01-06 08:30:49 +01:00
Frederick Pietschmann 8c245c7581 Add new indentation_width rule 2020-01-06 08:30:49 +01: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
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
timcmiller 29bff89a29 File name console description (#3010)
* Added parameters to FileNameConfiguration.consoleDescription

* Added bugfix to CHANGELOG

* Fix indentation

Co-authored-by: JP Simard <jp@jpsim.com>
2020-01-03 14:00:17 -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
Paul Taykalo ac40778cb3 Use SwiftLintFile wrapper over the File 2019-11-07 15:19:17 +02: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 3879151abf Enable some opt-in rules (#2801) 2019-08-28 14:49:23 -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
JP Simard 7f4b736ea3
Synthesize Equatable implementations where possible (#2790) 2019-07-01 17:22:18 -04: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
Cihat Gündüz b145d666d0 Fix issues after rebasing to master 2019-03-27 11:54:56 +01:00
Cihat Gündüz 7d43a71510 Add more specific instance property type ib_inspectable 2019-03-27 10:34:41 +01:00
Cihat Gündüz 99f60685a3 Implement equatable protocols manually for Swift 4.0 conformance 2019-03-27 10:34:41 +01:00
Cihat Gündüz ea7f5e6b47 Fix configuration naming issue 2019-03-27 10:34:41 +01:00
Cihat Gündüz e0fb65624b Add configurations for both rules 2019-03-27 10:34:41 +01:00
Cihat Gündüz 3ab600f5a2 [number_separator] Add more non-triggering examples + Rename option to exclude_ranges 2019-02-14 21:19:15 +01:00
Cihat Gündüz 57fe9947a6 [number_separator] Add valid_ranges option instead of ignoring years by default 2019-02-14 21:19:15 +01:00
Marcelo Fabri 293805cf11 Remove unused import 2019-01-24 22:28:45 -08:00
Marcelo Fabri 6fadf80eae Add `deployment_target` rule
Fixes #2589
2019-01-24 21:42:11 -08:00
Marcelo Fabri f8dda65637 Add `only_single_muted_parameter` configuration on `trailing_closure 2019-01-17 22:02:47 -08:00
JP Simard 0e01e07326
#2441 - Fix inaccessible custom rules in nested configurations (#2556)
* #2441 - Pass custom rules identifiers to the enableRules function to consider custom rules of a parent of a nested configuration

* #2441 - Add custom rules merge

* #2441 - Fix line length violation

* #2441 - Add nested configutaion mocks with custom rules

* #2441 - Add nested configurations tests for custom rules

* #2441 - Disable function body length check

* #2441 - Update changelog

* Move changelog to appropriate position

* Split up and refactor Configuration.init to avoid being too long

* Add tests to LinuxMain.swift

* Remove redundant protocol conformances

Hashable implies Equatable

* Fix typo in changelog entry and add another fixed issue URL
2019-01-13 15:07:27 -08:00
JP Simard 0e862ca9c4
Enable vertical whitespace rules in SwiftLint
and fix violations
2018-12-02 14:01:23 -08:00
Marcelo Fabri cf0c7b7b21 Use default Equatable and Hashable implementations 2018-11-19 09:51:12 -08:00
Marcelo Fabri 1f121b1ef7 Enable static_operator opt-in rule in SwiftLint 2018-09-16 20:33:28 -07:00
Dalton Claybrook a71bb4dd48 Add more triggering and non-triggering examples 2018-09-10 23:45:56 -04:00
Dalton Claybrook 0597df5b8c Add support for colon alignment 2018-09-10 23:45:56 -04:00
Dalton Claybrook d8a043f84b Create CollectionAlignmentConfiguration 2018-09-10 23:45:56 -04:00
Marcelo Fabri c9f315a798
Merge pull request #2372 from marcelofabri/identical_operands
Add identical_operands opt-in rule
2018-09-09 20:47:49 -07:00
JP Simard dcc85fb0f3
Remove unused imports (#2382) 2018-09-02 14:09:04 -07:00
Marcelo Fabri be60504dad Enable identical_operands rule on the project 2018-08-30 23:12:44 -07:00
JP Simard 1f9a0017e6
Refactor a rule disable command 2018-08-06 14:26:17 -07:00
JP Simard 3961d6482b
Organize rules by kind in Xcode project (#2341) 2018-08-05 18:54:05 -07:00
Marcelo Fabri 88f4c8be6f Minor changes after merging #2318 2018-07-30 00:12:02 -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
Cihat Gündüz b4f960bd48 Add config option allow_redundancy 2018-07-27 11:12:46 +02: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
Keith Smiley 6eedf5d73c
Add private_only to prefixed_toplevel_constant (#2315)
* Add private_only to prefixed_toplevel_constant

This allows users to opt in to only validate top level constants have
the given prefix if the constant is private or fileprivate.
2018-07-24 12:38:01 -07:00
Marcelo Fabri 8a686dac2a
Merge pull request #2310 from Dschee/file-name
Add options `prefix_pattern` and `suffix_pattern` to `file_name` rule
2018-07-24 09:46:28 -07:00
Cihat Gündüz bacc3ddaca Add default suffixPattern value directly in configuration initalizer 2018-07-24 17:34:17 +02:00