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

Unable to set type_body_length function_body_length file_length only as warnings with no error. #5822

Closed
2 tasks done
uevs opened this issue Oct 10, 2024 · 8 comments
Closed
2 tasks done
Labels
help Questions or user problems that require more explanation rather than code changes. repro-needed Issues that cannot be reproduced or miss proper descriptive examples.

Comments

@uevs
Copy link

uevs commented Oct 10, 2024

New Issue Checklist

Bug Description

I'm trying to set type_body_length function_body_length file_length to be warning only with custom length. I want to have a warning if the length reaches a certain limit, but no errors.

This is not clearly documented, but should be available #1647 #1691

I'm testing this by running:

swiftlint --quiet | grep -E 'error.*(type_body_length|function_body_length|file_length)'

And I would expect no errors in the output, but I do get errors using the default error limit of the respective rule.

I tried the following variations:

type_body_length: 400
type_body_length:
  warning: 400
type_body_length:
  - 400
type_body_length:
  warning: 400
  error: null
type_body_length:
  warning: 400
  error: nil
type_body_length:
  warning: 400
  error: ~

but none is working. It either gets the defults value of the rule:

error: Type Body Length Violation: Type body should span 500 lines or less excluding comments and whitespace: currently spans 528 lines (type_body_length)

or gives me:

warning: Invalid configuration for 'type_body_length' rule. Falling back to default.

Environment

  • SwiftLint version: 0.57.0
  • Xcode version: 16.0
  • Installation method used: Homebrew
  • Configuration file:
only_rules:
  - superfluous_disable_command
  - type_body_length
  - function_body_length
  - line_length
  - file_length
  # auto-correctable rules:
  - leading_whitespace
  - trailing_whitespace
  - trailing_comma
  - trailing_newline
  - colon
  - trailing_semicolon
  - opening_brace
  - closing_brace
  - return_arrow_whitespace
  - comma
  - empty_enum_arguments
  - empty_parameters
  - void_return

excluded:
  - fastlane/.tempbuild
  - Package/**/*/PreviewAssets.swift
  - Package/.build
type_body_length: 400
function_body_length: 91
file_length: 610
line_length:
  warning: 400
  error: 500
@SimplyDanny
Copy link
Collaborator

Can you provide a small reproducer? For me, this works. The configurations

type_body_length:
  warning: 40

type_body_length:
  warning: 40
  error: 50

type_body_length: 40

type_body_length: [40, 50]

work as I'd expect.

@SimplyDanny SimplyDanny added repro-needed Issues that cannot be reproduced or miss proper descriptive examples. help Questions or user problems that require more explanation rather than code changes. labels Oct 11, 2024
@uevs
Copy link
Author

uevs commented Oct 18, 2024

Can't reproduce either outside of the main project, the same file that fails on the main project does't if isolated. I also noticed that it doesn't happen on our CI.

I wonder if it's due to some caching or derived data issue? It's a very large project.

Anyways I think the issue is solved, as it doesn't happen on CI where we enforce the linting. Do you have any insights on why this might happen locally and how to avoid it? Just to leave some pointers to other folks having similar issues.

Thanks @SimplyDanny!

@SimplyDanny
Copy link
Collaborator

How do you call SwiftLint in all these cases? Command line, plugin, Bazel, ...?

Can it be that the configuration isn't read at all in your main project? Or are other options considered?

@uevs
Copy link
Author

uevs commented Oct 21, 2024

When testing locally I just run the above command on cli, which doesn't work as expected for some reason.

On CI we use GitHub actions with Danger, which works as expected.

In both cases I'm sure the config is read.

@SimplyDanny
Copy link
Collaborator

Something must be different though. Hard to believe, that the same tool version with the same configuration and code base behaves differently. Did you try running SwiftLint from the command line in CI as well?

@uevs
Copy link
Author

uevs commented Oct 23, 2024

Without even getting CI involved, all I have to do is copy the same file + config in a new folder and it will work, while it wouldn't on the main project. I wonder if SwiftLint takes advantage of Xcode derived data or some other caching that could explain this?

@SimplyDanny
Copy link
Collaborator

Without even getting CI involved, all I have to do is copy the same file + config in a new folder and it will work, while it wouldn't on the main project. I wonder if SwiftLint takes advantage of Xcode derived data or some other caching that could explain this?

It shouldn't as it builds its own cache. However, caching is a good point. Try running the command with the --no-cache argument.

@uevs
Copy link
Author

uevs commented Oct 25, 2024

I found the culprit: we had a duplicated and outdated config file in a subfolder of a test target. Apparently SwiftLint from the cli was picking that up instead than the main one. Since the limits were the same of the default config, I assumed it was picking up the default config instead.

This explains also why on CI it was working, since there we explicitly set the path for the config.

I'll close this, thanks for your help and insights @SimplyDanny

@uevs uevs closed this as completed Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help Questions or user problems that require more explanation rather than code changes. repro-needed Issues that cannot be reproduced or miss proper descriptive examples.
Projects
None yet
Development

No branches or pull requests

2 participants