Skip to content

feat: exclude linters from severity-rules #4434

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

Closed
wants to merge 1 commit into from
Closed

feat: exclude linters from severity-rules #4434

wants to merge 1 commit into from

Conversation

ealves-pt
Copy link

@ealves-pt ealves-pt commented Mar 2, 2024

Currently when configuring severity-rules we lose the granularity provided by more advanced linters.

A good use case is revive that allows us to customize the severity per linter. Considering the configuration below all the revive issues will have info severity instead of the severity defined in revive.

I already brought this to discussion in the past, #1860, and I accepted the limitation. But now I'm trying to work on a more precise coding standard for my teams and having the ability to control this would be perfect.

linters:
  disable-all: true
  enable:
    - errcheck
    - gosimple
    - govet
    - ineffassign
    - staticcheck
    - unused
    - revive
 
linters-settings:
  revive:
    severity: error
    rules:
      - name: cognitive-complexity
        arguments: [15]
      - name: cyclomatic
        arguments: [12]
        severity: warning

severity:
  default-severity: info
  rules:
    - linters:
      - errcheck
      - gosimple
      - govet
      - ineffassign
      - staticcheck
      - unused
      severity: warning
Output before the proposal

<?xml version="1.0" encoding="UTF-8"?>

<checkstyle version="5.0">
  <file name="internal/slack/slack_test.go">
    <error column="1" line="402" message="cognitive-complexity: function okFileUpload has cognitive complexity 17 (&gt; max enabled 15)" severity="info" source="revive">
    <error column="1" line="402" message="cyclomatic: function okFileUpload has cyclomatic complexity 14 (&gt; max enabled 12)" severity="info" source="revive">
    </error>
  </file>
</checkstyle>

With this proposal we add an exclude-linters to skip the default-severity

linters:
  disable-all: true
  enable:
    - errcheck
    - gosimple
    - govet
    - ineffassign
    - staticcheck
    - unused
    - revive
 
linters-settings:
  revive:
    severity: error
    rules:
      - name: cognitive-complexity
        arguments: [15]
      - name: cyclomatic
        arguments: [12]
        severity: warning

severity:
  default-severity: info
  exclude-linters:
    - revive
  rules:
    - linters:
      - errcheck
      - gosimple
      - govet
      - ineffassign
      - staticcheck
      - unused
      severity: warning
Output after the proposal

<?xml version="1.0" encoding="UTF-8"?>

<checkstyle version="5.0">
  <file name="internal/slack/slack_test.go">
    <error column="1" line="402" message="cognitive-complexity: function okFileUpload has cognitive complexity 17 (&gt; max enabled 15)" severity="error" source="revive">
    <error column="1" line="402" message="cyclomatic: function okFileUpload has cyclomatic complexity 14 (&gt; max enabled 12)" severity="warning" source="revive">
    </error>
  </file>
</checkstyle>

I didn't write any tests for this yet, I simply tested it locally to validate the output files.

Let me know if this is something worth to put more effort and I will happily finalize the work.

Copy link

boring-cyborg bot commented Mar 2, 2024

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Mar 2, 2024

CLA assistant check
All committers have signed the CLA.

@ealves-pt ealves-pt marked this pull request as ready for review March 2, 2024 20:34
@ealves-pt ealves-pt marked this pull request as draft March 2, 2024 20:34
@ldez ldez self-requested a review March 2, 2024 20:44
@ldez ldez added the blocked Need's direct action from maintainer label Mar 2, 2024
@ldez
Copy link
Member

ldez commented Mar 4, 2024

Hello,

The only linter that produces severity is revive.
The revive has its system to define and set severities.

I think it's better not to override severities when severity already exists like that:

	return transformIssues(issues, func(i *result.Issue) *result.Issue {
		if i.Severity != "" {
			return i
		}

In this context, we don't need a new option but just to add the previous 3 lines.

@ldez
Copy link
Member

ldez commented Mar 4, 2024

I created PR #4451 to simplify the severity processor code.

After that, I will create a PR that adds the option keep-linter-severity.
If set to true, the severities from linters are not overridden.
This option is just to be non-breaking.

severity:
  default-severity: tomato
  keep-linter-severity: true # <--

--> #4452

@ealves-pt
Copy link
Author

Awesome @ldez!

Thank you so much for the feedback and the speed tackling it.

@ealves-pt ealves-pt deleted the severity-rules-exclude-linters branch March 4, 2024 19:11
@ldez ldez added area: severity declined and removed blocked Need's direct action from maintainer labels Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants