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

failed to load command: danger #34

Open
VladimirHorky opened this issue Dec 1, 2020 · 4 comments
Open

failed to load command: danger #34

VladimirHorky opened this issue Dec 1, 2020 · 4 comments

Comments

@VladimirHorky
Copy link

Hi, I am having trouble producing a coverage report.

|           xcov Coverage Report           |
+---------------------------------+--------+
| VHNetworking.framework        | 57.45% |
| TvOSNetworkingKit.framework   | 89.85% |
| KeychainAccess.framework      | 25.26% |
+---------------------------------+--------+

[09:29:51]: Actual Code Coverage (57.52%) below threshold of 90.00%
[09:29:51]: The build has been marked as failed because minimum overall coverage has not been reached.
[!] The exception involves the following plugins:
 -  danger-xcov

bundler: failed to load command: danger (/Users/distiller/output/vendor/bundle/ruby/2.7.0/bin/danger)
Danger::DSLError: 
[!] Invalid `Dangerfile` file: Error creating your coverage report - see the log above
 #  from Dangerfile:59
 #  -------------------------------------------
 #  
 >  report = xcov.produce_report(
 #      scheme: 'TvOSNetworkingKit-Package',
 #  -------------------------------------------

  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/xcov-1.7.5/lib/xcov/error_handler.rb:20:in `handle_error'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/xcov-1.7.5/lib/xcov/error_handler.rb:25:in `handle_error_with_custom_message'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/xcov-1.7.5/lib/xcov/manager.rb:175:in `validate_report'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/xcov-1.7.5/lib/xcov/manager.rb:34:in `run'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-xcov-0.5.0/lib/danger_plugin.rb:66:in `produce_report'
  Dangerfile:59:in `eval_file'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/lib/danger/danger_core/dangerfile.rb:307:in `eval'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/lib/danger/danger_core/dangerfile.rb:307:in `eval_file'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/lib/danger/danger_core/dangerfile.rb:200:in `block in parse'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/lib/danger/danger_core/dangerfile.rb:197:in `instance_eval'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/lib/danger/danger_core/dangerfile.rb:197:in `parse'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/lib/danger/danger_core/dangerfile.rb:283:in `run'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/lib/danger/danger_core/executor.rb:29:in `run'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/lib/danger/commands/runner.rb:73:in `run'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/claide-1.0.3/lib/claide/command.rb:334:in `run'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/gems/danger-8.2.1/bin/danger:5:in `<top (required)>'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/bin/danger:23:in `load'
  /Users/distiller/output/vendor/bundle/ruby/2.7.0/bin/danger:23:in `<top (required)>'

Exited with code exit status 1
CircleCI received exit code 1

The Dangerfile:


files_to_check = (git.modified_files + git.added_files).uniq
(files_to_check - %w(Dangerfile)).each do |file|
	next unless File.file?(file)
	# Only check for classes inside swift files
	next unless File.extname(file).include?(".swift")
  	
  	# Will be used to check if we're inside a comment block.
	isCommentBlock = false

	# Will be used to track if we've placed any marks inside our class.
	foundMark = false 

	# Collects all disabled rules for this file.
	disabled_rules = []

	filelines = File.readlines(file)
	filelines.each_with_index do |line, index|
		if isCommentBlock
			if line.include?("*/")
				isCommentBlock = false
			end
		elsif line.include?("/*")
			isCommentBlock = true
		elsif line.include?("danger:disable")
			rule_to_disable = line.split.last
			disabled_rules.push(rule_to_disable)
		else
			# Start our custom line checks
			## Check for the usage of final class
			if disabled_rules.include?("final_class") == false and line.include?("class") and not line.include?("final") and not line.include?("func") and not line.include?("//") and not line.include?("protocol")
				warn("Consider using final for this class or use a struct (final_class)", file: file, line: index+1) 
			end

			## Check for the usage of unowned self
			if line.include?("unowned self")
				warn("It's safer to use weak instead of unowned", file: file, line: index+1) 
			end

			## Check for methods that only call the super class' method
			if line.include?("override") and line.include?("func") and filelines[index+1].include?("super") and filelines[index+2].include?("}")
				warn("Override methods which only call super can be removed", file: file, line: index+3) 
			end

			## Check if our line includes a MARK:
			if line.include?("MARK:") and line.include?("//")
				foundMark = true
			end
		end 
	end

	## Check wether our file is larger than 200 lines and doesn't include any Marks
	if filelines.count > 200 and foundMark == false 
		warn("Consider to place some `MARK:` lines for files over 200 lines big.")
	end
end

report = xcov.produce_report(
    scheme: 'TvOSNetworkingKit-Package',
    project: './TvOSNetworkingKit.xcodeproj',
    minimum_coverage_percentage: 90.0
)

if report.coverage < 0.900
    fail("Coverage is less than 90.0%.")
end

warn("#{report.create_displayable_coverage}")

xcov.output_report(report)
@gustavoSAS
Copy link

Hello VladimirHorkym, did you get any solution for this problem?

@bfaganello
Copy link

Any update?
I'm having the same problem

@netbe
Copy link

netbe commented Jul 4, 2022

me too

@DanielCreagh
Copy link

I think this is because your test coverage percentage is below the threshold. It's not a great fail message but I think that's all that causes it.

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

No branches or pull requests

5 participants