Skip to content

Commit

Permalink
Merge pull request #206 from jaymzh/json
Browse files Browse the repository at this point in the history
JSON formatter
  • Loading branch information
psyomn committed Jun 20, 2018
2 parents e3dbc76 + 92a669c commit 104bd85
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/mdl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'mdl/style'
require 'mdl/version'

require 'json'
require 'kramdown'

module MarkdownLint
Expand Down Expand Up @@ -69,6 +70,7 @@ def self.run(argv=ARGV)
cli.cli_arguments.flatten!

status = 0
results = []
cli.cli_arguments.each do |filename|
puts "Checking #{filename}..." if Config[:verbose]
doc = Doc.new_from_file(filename, Config[:ignore_front_matter])
Expand All @@ -86,7 +88,15 @@ def self.run(argv=ARGV)
status = 1
error_lines.each do |line|
line += doc.offset # Correct line numbers for any yaml front matter
if Config[:show_aliases]
if Config[:json]
results << {
'filename' => filename,
'line' => line,
'rule' => id,
'aliases' => rule.aliases,
'description' => rule.description,
}
elsif Config[:show_aliases]
puts "#{filename}:#{line}: #{rule.aliases.first || id} #{rule.description}"
else
puts "#{filename}:#{line}: #{id} #{rule.description}"
Expand All @@ -95,7 +105,9 @@ def self.run(argv=ARGV)
end
end

if status != 0
if Config[:json]
puts JSON.generate(results)
elsif status != 0
puts "\nA detailed description of the rules is available at "\
"https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md"
end
Expand Down
6 changes: 6 additions & 0 deletions lib/mdl/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class CLI
:proc => Proc.new { puts MarkdownLint::VERSION },
:exit => 0

option :json,
:short => '-j',
:long => '--json',
:description => "JSON output",
:boolean => true

def run(argv=ARGV)
parse_options(argv)

Expand Down

0 comments on commit 104bd85

Please sign in to comment.