Class: Danger::DangerDartLinter
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerDartLinter
- Defined in:
- lib/dart_linter/plugin.rb
Instance Attribute Summary collapse
-
#only_modified_files ⇒ Object
Enable only_modified_files Only show messages within changed files.
-
#report_path ⇒ Object
Report path You should set output from
dart analyzehere.
Instance Method Summary collapse
- #filtered_violations(violations) ⇒ Object
- #level_icon(level) ⇒ Object
- #lint(inline_mode: false) ⇒ Object
- #lint_mode(inline_mode:, violations:) ⇒ Object
- #markdown_table(violations) ⇒ Object
- #send_inline_comments(violations) ⇒ Object
- #summary_table(violations) ⇒ Object
- #table_row(violation) ⇒ Object
Instance Attribute Details
#only_modified_files ⇒ Object
Enable only_modified_files Only show messages within changed files.
7 8 9 |
# File 'lib/dart_linter/plugin.rb', line 7 def only_modified_files @only_modified_files end |
#report_path ⇒ Object
Report path
You should set output from dart analyze here
11 12 13 |
# File 'lib/dart_linter/plugin.rb', line 11 def report_path @report_path end |
Instance Method Details
#filtered_violations(violations) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/dart_linter/plugin.rb', line 70 def filtered_violations(violations) target_files = (git.modified_files - git.deleted_files) + git.added_files filtered_violations = violations.select { |violation| target_files.include? violation.file } return only_modified_files ? filtered_violations : violations end |
#level_icon(level) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/dart_linter/plugin.rb', line 57 def level_icon(level) case level when "info" then "ℹ️" when "warning" then "⚠️" when "error" then "⛔" else "" end end |
#lint(inline_mode: false) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/dart_linter/plugin.rb', line 13 def lint(inline_mode: false) if !report_path.nil? && File.exist?(report_path) report = File.open(report_path) violations = DartAnalyzeParser.violations(report) lint_mode(inline_mode: inline_mode, violations: violations) else fail("Could not run lint without setting report path or report file doesn't exists") end end |
#lint_mode(inline_mode:, violations:) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/dart_linter/plugin.rb', line 23 def lint_mode(inline_mode:, violations:) if inline_mode send_inline_comments(violations) else markdown(summary_table(violations)) end end |
#markdown_table(violations) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/dart_linter/plugin.rb', line 49 def markdown_table(violations) table = "### Dart Analyze found #{violations.length} issues ❌\n\n" table << "| Level | File | Line | Rule |\n" table << "| ----- | ---- | ---- | ---- |\n" return violations.reduce(table) { |acc, violation| acc << table_row(violation) } end |
#send_inline_comments(violations) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/dart_linter/plugin.rb', line 31 def send_inline_comments(violations) filtered_violations = filtered_violations(violations) filtered_violations.each do |violation| send("warn", violation.description, file: violation.file, line: violation.line) end end |
#summary_table(violations) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/dart_linter/plugin.rb', line 39 def summary_table(violations) filtered_violations = filtered_violations(violations) if filtered_violations.empty? return "### Dart Analyze found #{filtered_violations.length} issues ✅" else return markdown_table(filtered_violations) end end |
#table_row(violation) ⇒ Object
66 67 68 |
# File 'lib/dart_linter/plugin.rb', line 66 def table_row(violation) "| #{level_icon(violation.level)} | `#{violation.file}` | #{violation.line} | #{violation.rule} |\n" end |