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 ability to customize severity via config file #880

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

bkolb
Copy link
Contributor

@bkolb bkolb commented Nov 21, 2024

In order to customize the severity of rules, I added
the possibility to do so via the configuration files.
If no severity is specified, we use the one pre-determined
by the Rule itself.

Example:

    {
        "ruleSeverity": {
            "AlwaysUseLowerCamelCase": "warning",
            "AmbiguousTrailingClosureOverload": "error",
        }
    }

Issue: #879

Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

It looks like there's some noise in it from other merge commits (like the CMake and Package.swift files), can you rebase your changes on top of main and push that?

In general, I agree that we need a way to do this, but I don't think adding a separate dictionary for rule severity is the right answer here. The configuration file has already grown to be a bit of a mess as more and more settings have been added to it, and I'd like to revisit it holistically instead of continuing to graft more things on top of it. Overall, I think we need to remove the distinction between "rules" (in the swift-syntax visitor/rewriter sense) and the settings that affect the pretty-printer.

In order to customize the severity of rules, I added
the possibility to do so via the configuration files.
If no severity is specified, we use the one pre-determined
by the Rule itself.

Example:
```
{
    "ruleSeverity": {
        "AlwaysUseLowerCamelCase": "warning",
        "AmbiguousTrailingClosureOverload": "error",
    }
}
```

Issue: swiftlang#879
@bkolb
Copy link
Contributor Author

bkolb commented Nov 21, 2024

Thanks for the quick feedback. I rebased on top of main.

I would agree that the config file can use some improvement. Generally, I don't think the separation between linting and formatting makes a lot of sense. There are linting rules that can/could provide rewrites as well (e.g the position of let in a case). This goes all the way up to the cli, where you can either specify -i or lint. To me this sounds like a significant change, likely leading to a v2 of the config file?

That being said, I think it is not bad to have a section in which you enable and configure the rules and a section that configure the severity.

@allevato
Copy link
Member

I would agree that the config file can use some improvement. Generally, I don't think the separation between linting and formatting makes a lot of sense. There are linting rules that can/could provide rewrites as well (e.g the position of let in a case). This goes all the way up to the cli, where you can either specify -i or lint. To me this sounds like a significant change, likely leading to a v2 of the config file?

Yes, it would (and it would be the first one, since we've never done a breaking format change before).

That being said, I think it is not bad to have a section in which you enable and configure the rules and a section that configure the severity.

Since the configuration is user-facing, I want to be extremely cautious about introducing large new capabilities in a format that we don't think is ideal if we plan to change the format later, because that makes it more difficult for end-users to work with. We've been somewhat relaxed about simple boolean or integer values for the pretty printer, but this is a much bigger change and I don't want to create churn for users by getting them accustomed to one format and then changing it under them shortly after.

I might be able to take a look at redesigning the configuration in the coming weeks as other things slow down before the holidays.

In order to check during CI for propper formatting,
it is now also possible to specify severity for
the formating rules.

Issue: swiftlang#879
@bkolb
Copy link
Contributor Author

bkolb commented Nov 24, 2024

I changed my approach a little bit. This way, the configuration is still backward compatible.

@bkolb bkolb force-pushed the addSeverity branch 2 times, most recently from 7a2aff7 to 1f8e4f0 Compare November 25, 2024 09:09
In order to customize the severity of rules, I added
the possibility to do so via the configuration files.
If no severity is specified, we use the one pre-determined
by the Rule itself.

Example:
```
{
    "rules": {
        "AlwaysUseLowerCamelCase": "warning",
        "AmbiguousTrailingClosureOverload": "error",
        "UseLetInEveryBoundCaseVariable": "true", // use rule default
        "UseWhereClausesInForLoops": "false", // disabled
    }
}
```

In addition, one can now control how pretty-print violations
should be treated in the same way

Example:
```
{
    "rules": {
        "TrailingComma": "warning",
        "LineLength": "error",
        "Indentation": "true", // use rule default
        "TrailingWhitespace": "false", // disabled
    }
}
```

Issue: swiftlang#879
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