danger-ruby-swiftformat icon indicating copy to clipboard operation
danger-ruby-swiftformat copied to clipboard

Error running SwiftFormat: (RuntimeError)

Open EgaSetya opened this issue 1 year ago • 5 comments
trafficstars

Hi @garriguv, I encountered a runtime error like the following when attempting to integrate danger-swiftformat on GitLab.

Error

bundler: failed to load command: danger (/builds/technology/ios/project/.bundle/ruby/2.7.0/bin/danger)
/builds/technology/ios/project/.bundle/ruby/2.7.0/gems/danger-swiftformat-0.9.0/lib/swiftformat/swiftformat.rb:31:in `check_format': \e[31m (Danger::DSLError)
[!] Invalid `Dangerfile` file: Error running SwiftFormat:
Error: \e[0m./swiftformat: line 1: syntax error: unexpected word (expecting ")")\e[0m
 #  from Dangerfile:6
 #  -------------------------------------------
 #  swiftformat.binary_path = "./swiftformat"
 >  swiftformat.check_format
 #  -------------------------------------------
	from /builds/technology/ios/project/.bundle/ruby/2.7.0/gems/danger-swiftformat-0.9.0/lib/swiftformat/plugin.rb:59:in `check_format'
	from Dangerfile:6:in `eval_file'
Screenshot 2024-02-02 at 15 12 09

Dangerfile

require "gitlab-dangerfiles"

Gitlab::Dangerfiles.for_project(self, &:import_defaults)

swiftformat.binary_path = "./swiftformat"
swiftformat.check_format

.swiftformat

# file options

--exclude Tests/XCTestManifests.swift,Tests/BadConfig,Snapshots,Build,PluginTests,Pods

# format options

--guardelse same-line
--lineaftermarks false
--emptybraces spaced
--patternlet inline
--marktypes never
--markextensions never
--redundanttype inferred
--trailingclosures filter,map,compactMap
--commas inline
--stripunusedargs closure-only
--wraparguments before-first
--wrapparameters before-first
--wrapreturntype if-multiline
--wrapconditions after-first
--trimwhitespace nonblank-lines


# rules

--enable spaceAroundBraces
--enable wrapConditionalBodies
--enable redundantOptionalBinding
--disable initCoderUnavailable

What can I do to fix this issue? Is there anything that I missed?

EgaSetya avatar Feb 01 '24 16:02 EgaSetya

Hmm, It's hard to say. It

I see that you're running ruby 2.7.0, any change you could upgrade to 3.4.0 or later?

garriguv avatar Feb 02 '24 13:02 garriguv

Hmm, It's hard to say. It

I see that you're running ruby 2.7.0, any change you could upgrade to 3.4.0 or later?

Let me try it first. I'll get back to you later with the result.

EgaSetya avatar Feb 04 '24 02:02 EgaSetya

I'm seeing this as well running Ruby 3.2.3 from the Danger action in GitHub Actions.

bundler: failed to load command: danger (/home/runner/work/ensemble-swift/ensemble-swift/vendor/bundle/ruby/3.2.0/bin/danger)
/home/runner/work/ensemble-swift/ensemble-swift/vendor/bundle/ruby/3.2.0/gems/danger-swiftformat-0.8.1/lib/swiftformat/swiftformat.rb:31:in `check_format':  (Danger::DSLError)
[!] Invalid `Dangerfile` file: Error running SwiftFormat:
Error: /home/runner/.local/share/mise/installs/swiftformat/0.52.11/bin/swiftformat: 1: Syntax error: "(" unexpected
 #  from Dangerfile:9
 #  -------------------------------------------
 #  swiftformat.additional_message = 'run `make format` on your branch to fix the SwiftFormat failures.'
 >  swiftformat.check_format(fail_on_error: true)
 #  
 #  -------------------------------------------

jsorge avatar Feb 20 '24 16:02 jsorge

As another data point, this action works when running on a Mac, but not on Linux (using ubuntu-latest).

jsorge avatar Feb 24 '24 05:02 jsorge