Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configure command #5041

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from

Conversation

mildm8nnered
Copy link
Collaborator

@mildm8nnered mildm8nnered commented May 30, 2023

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 mildm8nnered marked this pull request as draft May 30, 2023 21:27
@mildm8nnered mildm8nnered changed the title Mildm8nnered add configure command Add configure command May 30, 2023
@SwiftLintBot
Copy link

SwiftLintBot commented May 30, 2023

1 Error
🚫 Could not build branch
2 Warnings
⚠️ If this is a user-facing change, please include a CHANGELOG entry to credit yourself!
You can find it at CHANGELOG.md.
⚠️ This PR may need tests.

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 🚫 Danger

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch 3 times, most recently from d0cad84 to c899767 Compare June 27, 2023 08:26
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch 2 times, most recently from 6cdca48 to 7f38ff8 Compare July 7, 2023 17:05
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch 2 times, most recently from 2c4db32 to 48335bc Compare July 15, 2023 10:27
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch 2 times, most recently from a0f3570 to b7fc998 Compare July 19, 2023 18:14
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch from b7fc998 to 5912752 Compare July 26, 2023 21:10
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch from 5912752 to 9f4dba6 Compare August 6, 2023 17:14
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch 4 times, most recently from a9af9b1 to 0bf20a0 Compare September 3, 2023 10:46
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch 4 times, most recently from ca9fb51 to c2563f2 Compare September 9, 2023 03:24
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch 4 times, most recently from 7ca876c to 2ca307d Compare October 1, 2023 10:43
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch from 2ca307d to 49b9af2 Compare October 3, 2023 21:33
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch from 4b1f483 to dba08a5 Compare October 13, 2023 22:22
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-configure-command branch from ab2dfb6 to 35efd4e Compare January 19, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants