Module: MarkdownLint
- Defined in:
- lib/mdl.rb,
lib/mdl/cli.rb,
lib/mdl/doc.rb,
lib/mdl/style.rb,
lib/mdl/config.rb,
lib/mdl/ruleset.rb,
lib/mdl/version.rb
Defined Under Namespace
Modules: Config Classes: CLI, Doc, Rule, RuleSet, Style
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
Class Method Details
.run ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mdl.rb', line 12 def self.run cli = MarkdownLint::CLI.new cli.run rules = RuleSet.load_default Style.load(Config[:style], rules) # Rule option filter if Config[:rules] rules.select! {|r| Config[:rules][:include].include?(r) } \ unless Config[:rules][:include].empty? rules.select! {|r| not Config[:rules][:exclude].include?(r) } \ unless Config[:rules][:exclude].empty? end # Tag option filter if Config[:tags] rules.select! {|r, v| not (v. & Config[:tags][:include]).empty? } \ unless Config[:tags][:include].empty? rules.select! {|r, v| (v. & Config[:tags][:exclude]).empty? } \ unless Config[:tags][:exclude].empty? end if Config[:list_rules] puts "Enabled rules:" rules.each do |id, rule| if Config[:verbose] puts "#{id} (#{rule..join(', ')}) - #{rule.description}" else puts "#{id} - #{rule.description}" end end exit 0 end # Recurse into directories cli.cli_arguments.each_with_index do |filename, i| if Dir.exist?(filename) if Config[:git_recurse] Dir.chdir(filename) do cli.cli_arguments[i] = %x(git ls-files '*.md').split("\n") end else cli.cli_arguments[i] = Dir["#{filename}/**/*.md"] end end end cli.cli_arguments.flatten! status = 0 cli.cli_arguments.each do |filename| puts "Checking #{filename}..." if Config[:verbose] doc = Doc.new_from_file(filename) filename = '(stdin)' if filename == "-" if Config[:show_kramdown_warnings] status = 2 if not doc.parsed.warnings.empty? doc.parsed.warnings.each do |w| puts "#{filename}: Kramdown Warning: #{w}" end end rules.sort.each do |id, rule| puts "Processing rule #{id}" if Config[:verbose] error_lines = rule.check.call(doc) next if error_lines.nil? or error_lines.empty? status = 1 error_lines.each do |line| puts "#{filename}:#{line}: #{id} #{rule.description}" end end end exit status end |