realm / SwiftLint

A tool to enforce Swift style and conventions.

Home Page:https://realm.github.io/SwiftLint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Strict" param seems to break pipeline

wolfAle opened this issue · comments

Describe the bug

I've setup a Gitlab pipeline that executes the fastlane swiftlint command as follows:

lane :lint do |options|
    swiftlint(
      mode: :lint,
      output_file: "swiftlint.result.html",
      config_file: ".swiftlint.yml",
      strict: true,
      files: options[:swiftLintFiles],
      ignore_exit_status: false,
      raise_if_swiftlint_error: true,
      reporter: "html",
      executable: "Pods/SwiftLint/swiftlint"
    )
  end

The command gets correctly executed as follow:

Pods/SwiftLint/swiftlint lint --strict --config .swiftlint.yml --reporter html --use-script-input-files > swiftlint.result.html
`

##### Complete output when running SwiftLint, including the stack trace and command used

```bash
DEBUG [2024-02-12 10:16:15.58]: All plugins are up to date
bundler: failed to load command: fastlane (/Users/macstudio1-teammobile/.gem/bin/fastlane)
/Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane_core/lib/fastlane_core/ui/interface.rb:141:in `user_error!': [!] SwiftLint finished with errors (exit code: 0) (FastlaneCore::Interface::FastlaneError)
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane_core/lib/fastlane_core/ui/ui.rb:17:in `method_missing'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/actions/swiftlint.rb:238:in `handle_swiftlint_error'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/actions/swiftlint.rb:45:in `rescue in run'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/actions/swiftlint.rb:42:in `run'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/runner.rb:263:in `block (2 levels) in execute_action'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/actions/actions_helper.rb:69:in `execute_action'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/runner.rb:255:in `block in execute_action'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/runner.rb:229:in `chdir'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/runner.rb:229:in `execute_action'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/runner.rb:157:in `trigger_action_by_name'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/fast_file.rb:159:in `method_missing'
	from ../../../../../../../../var/folders/88/8x9qkqds4kqd9tp06fspnkh00000gn/T/fl_clone20240212-61397-fa3v5x/CiCd.git/Fastfile:110:in `block (2 levels) in parsing_binding'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/lane.rb:41:in `call'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/runner.rb:49:in `block in execute'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/runner.rb:45:in `chdir'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/runner.rb:45:in `execute'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/lane_manager.rb:46:in `cruise_lane'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/command_line_handler.rb:34:in `handle'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/commands_generator.rb:110:in `block (2 levels) in run'
	from /Users/macstudio1-teammobile/.gem/gems/commander-4.6.0/lib/commander/command.rb:187:in `call'
	from /Users/macstudio1-teammobile/.gem/gems/commander-4.6.0/lib/commander/command.rb:157:in `run'
	from /Users/macstudio1-teammobile/.gem/gems/commander-4.6.0/lib/commander/runner.rb:444:in `run_active_command'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:124:in `run!'
	from /Users/macstudio1-teammobile/.gem/gems/commander-4.6.0/lib/commander/delegates.rb:18:in `run!'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/commands_generator.rb:354:in `run'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/commands_generator.rb:43:in `start'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/fastlane/lib/fastlane/cli_tools_distributor.rb:123:in `take_off'
	from /Users/macstudio1-teammobile/.gem/gems/fastlane-2.219.0/bin/fastlane:23:in `<top (required)>'
	from /Users/macstudio1-teammobile/.gem/bin/fastlane:23:in `load'
	from /Users/macstudio1-teammobile/.gem/bin/fastlane:23:in `<top (required)>'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:58:in `load'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/cli/exec.rb:23:in `run'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/cli.rb:492:in `exec'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/cli.rb:34:in `dispatch'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/cli.rb:28:in `start'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/exe/bundle:37:in `block in <top (required)>'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/macstudio1-teammobile/.gem/gems/bundler-2.4.22/exe/bundle:29:in `<top (required)>'
	from /usr/local/bin/bundle:23:in `load'
	from /usr/local/bin/bundle:23:in `<main>'

Environment

  • SwiftLint version (run swiftlint version to be sure)?
    SwiftLint (0.54.0)

  • Installation method used (Homebrew, CocoaPods, building from source, etc)?
    Cocoapods

Ad additional info: the analysis gets correctly executed, the output file created and the warnings are considered as errors, but the pipeline fails with that error.
If I remove the strict param then it doesn't raise an error, but of course the pipeline job completes successfully because the warnings are not considered errors.

Thanks for your help,
Alessandro

This is the expected behavior. If SwiftLint found errors, it also exits with an error code other than 0 (2 actually).

According to that, it doesn't break the pipeline, but the pipeline decided to break when it got an error code other than 0 from SwiftLint.

Ok, I see your point. Problem with that is that the pipeline is considered failed (and that's fine) but in that case no artifacts are available, hence neither the swiflint's output (html in my case) is available. And I can't see the result of the linting.

How'd you suggest to proceed in this case?

This still sounds to me like this should be fixable in the pipeline configuration. But that's just guessing.

On the SwiftLint side, I wouldn't dare to change the behavior as other folk might rely on it. Also, I think it's reasonable to exit with a non-zero error code in --strict mode.

Perhaps for you it's possible to go without --strict and just configure certain (or all) rules to emit errors. Then, SwiftLint will exit with 0 and you still get (some) errors in the log or the output file.

Perhaps for you it's possible to go without --strict and just configure certain (or all) rules to emit errors. Then, SwiftLint will exit with 0 and you still get (some) errors in the log or the output file.

This part is interesting, is it possible to configure rules to emit errors? is there documentation about it? or can you explain me how?

Thanks!

In the configuration file, to every rule, you can add a severity option than can be set to error or warning. For example:

force_try:
  severity: error

Oh that's just great, I didn't know 😄
I'll give it a go and I'll close the issue if everything goes as expected, thanks for your help, appreciated! 😉