class Danger::DangerGolint
Lint javascript files using [golint](golint.org/). Results are send as inline commen.
@example Run golint with changed files only
golint.filtering = true golint.lint
@see leonhartX/danger-golint @tags lint, golang, golint
Constants
- MARKDOWN_TEMPLATE
Attributes
base_dir[W]
Root directory from where golint will run. Defaults to current directory. @return [String]
Public Instance Methods
base_dir()
click to toggle source
# File lib/golint/plugin.rb, line 23 def base_dir @base_dir || '.' end
lint()
click to toggle source
Lints go files. Generates `errors` and `warnings` due to golint's config. Will try to send inline comment if supported(Github)
@return [void]
# File lib/golint/plugin.rb, line 33 def lint errors = lint_results.reject(&:nil?) return if errors.empty? print_markdown_table(errors) end
Private Instance Methods
golint_installed?()
click to toggle source
Check existing status golint toolchain # @return [bool]
# File lib/golint/plugin.rb, line 46 def golint_installed? `which golint`.strip.empty? == false end
lint_results()
click to toggle source
Get lint result regards the filtering option
return [Hash]
# File lib/golint/plugin.rb, line 53 def lint_results bin = 'golint' system 'go get -u golang.org/x/lint/golint' unless golint_installed? run_lint(bin, base_dir) end
print_markdown_table(errors=[])
click to toggle source
Print markdown string
@param [List<string>] errors
@return [string]
# File lib/golint/plugin.rb, line 77 def print_markdown_table(errors=[]) report = errors.inject(MARKDOWN_TEMPLATE) do |out_line, error_line| file, line, column, reason = error_line.split(':') out_line += "| #{short_link(file, line)} | #{line} | #{column} | #{reason.strip.tr('\'', '`')} |\n" out_line end markdown(report) end
run_lint(bin, dir)
click to toggle source
Run golint aginst a single dir.
@param [String] bin
The binary path of golint
@param [String] dir
Dir to be linted
@return [Output]
# File lib/golint/plugin.rb, line 68 def run_lint(bin, dir) `#{bin} #{dir}`.split("\n") end
short_link(file, line)
click to toggle source
# File lib/golint/plugin.rb, line 87 def short_link(file, line) if danger.scm_provider.to_s == 'github' return github.html_link("#{file}#L#{line}", full_path: false) end file end