Class: MarkdownLint::SarifFormatter
- Inherits:
-
Object
- Object
- MarkdownLint::SarifFormatter
- Defined in:
- lib/mdl/formatters/sarif.rb
Overview
SARIF formatter
Class Method Summary collapse
- .generate(rules, results) ⇒ Object
- .generate_sarif(rules, results) ⇒ Object
- .generate_sarif_results(rules, results) ⇒ Object
- .generate_sarif_rules(rules) ⇒ Object
Class Method Details
.generate(rules, results) ⇒ Object
9 10 11 12 13 |
# File 'lib/mdl/formatters/sarif.rb', line 9 def generate(rules, results) matched_rules_id = results.map { |result| result['rule'] }.uniq matched_rules = rules.select { |id, _| matched_rules_id.include?(id) } JSON.generate(generate_sarif(matched_rules, results)) end |
.generate_sarif(rules, results) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/mdl/formatters/sarif.rb', line 15 def generate_sarif(rules, results) { :'$schema' => 'https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json', :version => '2.1.0', :runs => [ { :tool => { :driver => { :name => 'Markdown lint', :version => MarkdownLint::VERSION, :informationUri => 'https://github.com/markdownlint/markdownlint', :rules => generate_sarif_rules(rules), }, }, :results => generate_sarif_results(rules, results), } ], } end |
.generate_sarif_results(rules, results) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/mdl/formatters/sarif.rb', line 63 def generate_sarif_results(rules, results) results.map do |result| { :ruleId => result['rule'], :ruleIndex => rules.find_index { |id, _| id == result['rule'] }, :message => { :text => "#{result['rule']} - #{result['description']}", }, :locations => [ { :physicalLocation => { :artifactLocation => { :uri => result['filename'], :uriBaseId => '%SRCROOT%', }, :region => { :startLine => result['line'], }, }, } ], } end end |
.generate_sarif_rules(rules) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/mdl/formatters/sarif.rb', line 35 def generate_sarif_rules(rules) rules.map do |id, rule| { :id => id, :name => rule.aliases.first.split('-').map(&:capitalize).join, :defaultConfiguration => { :level => 'note', }, :properties => { :description => rule.description, :tags => rule., :queryURI => rule.docs_url, }, :shortDescription => { :text => rule.description, }, :fullDescription => { :text => rule.description, }, :helpUri => rule.docs_url, :help => { :text => "More info: #{rule.docs_url}", :markdown => "[More info](#{rule.docs_url})", }, } end end |