SwiftLint icon indicating copy to clipboard operation
SwiftLint copied to clipboard

Add configure command

Open mildm8nnered opened this issue 1 year ago • 1 comments

Experimental

Implements a configuration "wizard" for SwiftLint

This will scan the current directory for swift files, and offer the user the choice of which directories to include.

Then configure will scan the chosen directories for violations, and suggest a configuration that disables all currently violated rules.

% swiftlint help configure
OVERVIEW: Configure SwiftLint

USAGE: swiftlint configure [--color] [--no-color] [--auto] [--overwrite]

OPTIONS:
  --color                 Colorize output regardless of terminal settings.
  --no-color              Do not colorize output regardless of terminal settings.
  --auto                  Complete setup automatically.
  --overwrite             In automatic mode, overwrite any existing configuration.
  --version               Show the version.
  -h, --help              Show help information.

Sample session:

% swiftlint configure
Welcome to SwiftLint! Do you want to continue? (Y/n) 
Checking for existing .swiftlint.yml configuration file.
Found an existing .swiftlint.yml configuration file - Do you want to continue? (Y/n) 
Do you want to you want to keep any custom configurations from .swiftlint.yml (Y/n) 
Checking for any other .swiftlint.yml configuration files.
Found existing child configurations:

Tests/SwiftLintFrameworkTests/Resources/ProjectMock/NestedConfig/Test/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/NestedConfig/Test/Sub/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/ChildConfig/Cycle1/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/ChildConfig/Cycle2/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/ChildConfig/Cycle3/Main/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/ParentConfig/Cycle1/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/ParentConfig/Cycle2/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/ParentConfig/Cycle3/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/RemoteConfig/LocalRef/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/RemoteConfig/Cycle/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/Level1/Level2/.swiftlint.yml
Tests/SwiftLintFrameworkTests/Resources/ProjectMock/Level1/Level2/Level3/.swiftlint.yml

Do you want to continue? (Y/n) 
Checking for .swift files.
Found .swift files in the following top level directories:

Plugins
Source
Tests

Do you want SwiftLint to scan all of those directories? (Y/n) 
Checking for violations. This may take some time.
Linting Swift files in current working directory
625 of 625 [==============================] ETA: 0s (3 files/s)
+-----------------------------------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| rule identifier                         | opt-in | correctable | custom | warnings | errors | total violations | number of files |
+-----------------------------------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| explicit_type_interface                 | yes    | no          | no     |    3,811 |      0 |            3,811 |             527 |
| explicit_acl                            | yes    | no          | no     |    3,028 |      0 |            3,028 |             537 |
| indentation_width                       | yes    | no          | no     |    1,784 |      0 |            1,784 |             327 |
| prefer_nimble                           | yes    | no          | no     |      856 |      0 |              856 |              62 |
| explicit_top_level_acl                  | yes    | no          | no     |      729 |      0 |              729 |             466 |
| multiline_arguments_brackets            | yes    | no          | no     |      699 |      0 |              699 |             120 |
| required_deinit                         | yes    | no          | no     |      603 |      0 |              603 |             309 |
| no_magic_numbers                        | yes    | no          | no     |      517 |      0 |              517 |              92 |
| no_extension_access_modifier            | yes    | no          | no     |        0 |    511 |              511 |             262 |
| type_contents_order                     | yes    | no          | no     |      443 |      0 |              443 |             276 |
| implicit_return                         | yes    | yes         | no     |      369 |      0 |              369 |             149 |
| multiline_parameters_brackets           | yes    | no          | no     |      231 |      0 |              231 |              63 |
| multiline_arguments                     | yes    | no          | no     |      223 |      0 |              223 |              58 |
| anonymous_argument_in_multiline_closure | yes    | no          | no     |      208 |      0 |              208 |              67 |
| no_grouping_extension                   | yes    | no          | no     |      207 |      0 |              207 |             192 |
| file_types_order                        | yes    | no          | no     |      183 |      0 |              183 |              76 |
| missing_docs                            | yes    | no          | no     |      173 |      0 |              173 |              25 |
| superfluous_else                        | yes    | no          | no     |      140 |      0 |              140 |              56 |
| sorted_enum_cases                       | yes    | no          | no     |      115 |      0 |              115 |              26 |
| multiline_literal_brackets              | yes    | no          | no     |      110 |      0 |              110 |              28 |
| force_unwrapping                        | yes    | no          | no     |      109 |      0 |              109 |              37 |
| vertical_whitespace_between_cases       | yes    | yes         | no     |      100 |      0 |              100 |              42 |
| explicit_enum_raw_value                 | yes    | no          | no     |       84 |      0 |               84 |              15 |
| switch_case_on_newline                  | yes    | no          | no     |       78 |      0 |               78 |              14 |
| conditional_returns_on_newline          | yes    | no          | no     |       73 |      0 |               73 |              50 |
| trailing_closure                        | yes    | no          | no     |       72 |      0 |               72 |              44 |
| prefixed_toplevel_constant              | yes    | no          | no     |       57 |      0 |               57 |              32 |
| convenience_type                        | yes    | no          | no     |       56 |      0 |               56 |              51 |
| strict_fileprivate                      | yes    | no          | no     |       54 |      0 |               54 |              22 |
| prefer_self_in_static_references        | yes    | yes         | no     |       48 |      0 |               48 |              23 |
| multiline_parameters                    | yes    | no          | no     |       46 |      0 |               46 |              30 |
| multiline_function_chains               | yes    | no          | no     |       41 |      0 |               41 |              28 |
| discouraged_optional_collection         | yes    | no          | no     |       32 |      0 |               32 |              19 |
| file_name                               | yes    | no          | no     |       21 |      0 |               21 |              21 |
| function_default_parameter_at_end       | yes    | no          | no     |       16 |      0 |               16 |              11 |
| closure_body_length                     | yes    | no          | no     |       13 |      1 |               14 |               5 |
| todo                                    | no     | no          | no     |       11 |      0 |               11 |               8 |
| type_name                               | no     | no          | no     |        8 |      0 |                8 |               8 |
| redundant_self_in_closure               | yes    | yes         | no     |        6 |      0 |                6 |               3 |
| file_header                             | yes    | no          | no     |        5 |      0 |                5 |               5 |
| implicitly_unwrapped_optional           | yes    | no          | no     |        5 |      0 |                5 |               4 |
| empty_xctest_method                     | yes    | no          | no     |        1 |      0 |                1 |               1 |
| legacy_objc_type                        | yes    | no          | no     |        1 |      0 |                1 |               1 |
| self_binding                            | yes    | yes         | no     |        1 |      0 |                1 |               1 |
+-----------------------------------------+--------+-------------+--------+----------+--------+------------------+-----------------+
| Total                                   |        |             |        |   15,367 |    512 |           15,879 |             605 |
+-----------------------------------------+--------+-------------+--------+----------+--------+------------------+-----------------+

Do you want to disable all of the SwiftLint rules with existing violations? (Y/n) 

Do you want to disable all (3) of the deprecated rules? (Y/n) 

Do you want to enable all (5) of the analyzer rules? (Y/n) 

Do you want to use the default (xcode) reporter? (Y/n) 
Proposed configuration

included:
  - Plugins
  - Source
  - Tests
opt_in_rules:
  - all
analyzer_rules:
  - explicit_self
  - typesafe_array_init
  - unused_declaration
  - capture_variable
  - unused_import
disabled_rules:
  - anonymous_argument_in_multiline_closure
  - anyobject_protocol
  - closure_body_length
  - conditional_returns_on_newline
  - convenience_type
  - discouraged_optional_collection
  - empty_xctest_method
  - explicit_acl
  - explicit_enum_raw_value
  - explicit_top_level_acl
  - explicit_type_interface
  - file_header
  - file_name
  - file_types_order
  - force_unwrapping
  - function_default_parameter_at_end
  - implicit_return
  - implicitly_unwrapped_optional
  - indentation_width
  - inert_defer
  - legacy_objc_type
  - missing_docs
  - multiline_arguments
  - multiline_arguments_brackets
  - multiline_function_chains
  - multiline_literal_brackets
  - multiline_parameters
  - multiline_parameters_brackets
  - no_extension_access_modifier
  - no_grouping_extension
  - no_magic_numbers
  - prefer_nimble
  - prefer_self_in_static_references
  - prefixed_toplevel_constant
  - redundant_self_in_closure
  - required_deinit
  - self_binding
  - sorted_enum_cases
  - strict_fileprivate
  - superfluous_else
  - switch_case_on_newline
  - todo
  - trailing_closure
  - type_contents_order
  - type_name
  - unused_capture_list
  - vertical_whitespace_between_cases
analyzer_rules:
  - capture_variable
  - explicit_self
  - typesafe_array_init
  - unused_declaration
  - unused_import
reporter: xcode


attributes:
    severity: warning
    attributes_with_arguments_always_on_line_above: true
    always_on_same_line: ["@IBAction", "@NSManaged"]
    always_on_line_above: ["@ConfigurationElement", "@OptionGroup", "@RuleConfigurationDescriptionBuilder"]

balanced_xctest_lifecycle:
    severity: warning
    test_parent_classes: ["QuickSpec", "SwiftLintTestCase", "XCTestCase"]

empty_xctest_method:
    severity: warning
    test_parent_classes: ["QuickSpec", "SwiftLintTestCase", "XCTestCase"]

function_body_length:
    warning: 60

large_tuple:
    warning: 3

number_separator:
    severity: warning
    minimum_length: 5
    exclude_ranges: []

single_test_class:
    severity: warning
    test_parent_classes: ["QuickSpec", "SwiftLintTestCase", "XCTestCase"]

type_body_length:
    warning: 400

unused_import:
    severity: warning
    require_explicit_imports: false
    allowed_transitive_imports: []
    always_keep_imports: ["SwiftSyntaxBuilder", "SwiftLintFramework"]

Does that look good? (Y/n) 
Found an existing configuration.
Do you want to exit without overwriting the existing configuration? (Y/n) n
Do you want to overwrite the existing configuration? (Y/n) 
Saving configuration to .swiftlint.yml

mildm8nnered avatar May 30 '23 21:05 mildm8nnered

2 Warnings
:warning: If this is a user-facing change, please include a CHANGELOG entry to credit yourself!
You can find it at CHANGELOG.md.
:warning: This PR may need tests.
17 Messages
:book: Linting Aerial with this PR took 0.63s vs 0.61s on main (3% slower)
:book: Linting Alamofire with this PR took 0.83s vs 0.83s on main (0% slower)
:book: Linting Brave with this PR took 4.81s vs 4.77s on main (0% slower)
:book: Linting DuckDuckGo with this PR took 3.05s vs 3.09s on main (1% faster)
:book: Linting Firefox with this PR took 7.76s vs 7.78s on main (0% faster)
:book: Linting Kickstarter with this PR took 6.83s vs 6.84s on main (0% faster)
:book: Linting Moya with this PR took 0.4s vs 0.39s on main (2% slower)
:book: Linting NetNewsWire with this PR took 1.7s vs 1.68s on main (1% slower)
:book: Linting Nimble with this PR took 0.53s vs 0.53s on main (0% slower)
:book: Linting PocketCasts with this PR took 6.01s vs 5.9s on main (1% slower)
:book: Linting Quick with this PR took 0.33s vs 0.33s on main (0% slower)
:book: Linting Realm with this PR took 3.21s vs 3.15s on main (1% slower)
:book: Linting Sourcery with this PR took 1.62s vs 1.59s on main (1% slower)
:book: Linting Swift with this PR took 2.85s vs 2.86s on main (0% faster)
:book: Linting VLC with this PR took 0.87s vs 0.84s on main (3% slower)
:book: Linting Wire with this PR took 11.41s vs 11.42s on main (0% faster)
:book: Linting WordPress with this PR took 7.45s vs 7.41s on main (0% slower)

Here's an example of your CHANGELOG entry:

* Add configure command.  
  [mildm8nnered](https://github.com/mildm8nnered)
  [#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)

note: There are two invisible spaces after the entry's text.

Generated by :no_entry_sign: Danger

SwiftLintBot avatar May 30 '23 21:05 SwiftLintBot