class Danger::DangerFlutterLint
Attributes
only_modified_files[RW]
Enable only_modified_files
Only show messages within changed files.
report_path[RW]
Report path You should set output from `flutter analyze` here
Public Instance Methods
lint(inline_mode: false)
click to toggle source
# File lib/flutter_lint/plugin.rb, line 13 def lint(inline_mode: false) if flutter_exists? lint_if_report_exists(inline_mode: inline_mode) else fail("Could not find `flutter` inside current directory") end end
Private Instance Methods
filtered_violations(violations)
click to toggle source
# File lib/flutter_lint/plugin.rb, line 71 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
flutter_exists?()
click to toggle source
# File lib/flutter_lint/plugin.rb, line 78 def flutter_exists? `which flutter`.strip.empty? == false end
lint_if_report_exists(inline_mode:)
click to toggle source
# File lib/flutter_lint/plugin.rb, line 23 def lint_if_report_exists(inline_mode:) if !report_path.nil? && File.exist?(report_path) report = File.open(report_path) violations = FlutterAnalyzeParser.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:)
click to toggle source
# File lib/flutter_lint/plugin.rb, line 33 def lint_mode(inline_mode:, violations:) if inline_mode send_inline_comments(violations) else markdown(summary_table(violations)) end end
markdown_table(violations)
click to toggle source
# File lib/flutter_lint/plugin.rb, line 59 def markdown_table(violations) table = "### Flutter Analyze found #{violations.length} issues ❌\n\n" table << "| File | Line | Rule |\n" table << "| ---- | ---- | ---- |\n" return violations.reduce(table) { |acc, violation| acc << table_row(violation) } end
send_inline_comments(violations)
click to toggle source
# File lib/flutter_lint/plugin.rb, line 41 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)
click to toggle source
# File lib/flutter_lint/plugin.rb, line 49 def summary_table(violations) filtered_violations = filtered_violations(violations) if filtered_violations.empty? return "### Flutter Analyze found #{filtered_violations.length} issues ✅" else return markdown_table(filtered_violations) end end
table_row(violation)
click to toggle source
# File lib/flutter_lint/plugin.rb, line 67 def table_row(violation) "| `#{violation.file}` | #{violation.line} | #{violation.rule} |\n" end