Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Add markdown linter and style check
Browse files Browse the repository at this point in the history
  • Loading branch information
dshevtsov committed Jul 11, 2019
1 parent c1e2737 commit a63a118
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style '_checks/md_style'
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem 'wdm', platform: :mswin

group :test do
gem 'html-proofer'
gem "mdl"
gem 'launchy'
end

Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,18 @@ GEM
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
mdl (0.5.0)
kramdown (~> 1.12, >= 1.12.0)
mixlib-cli (~> 1.7, >= 1.7.0)
mixlib-config (~> 2.2, >= 2.2.1)
mercenary (0.3.6)
mini_portile2 (2.3.0)
minitest (5.11.3)
multipart-post (2.1.1)
netrc (0.11.0)
mixlib-cli (1.7.0)
mixlib-config (2.2.18)
tomlrb
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
octokit (4.14.0)
Expand All @@ -137,6 +144,7 @@ GEM
faraday (> 0.8, < 2.0)
thor (0.20.3)
thread_safe (0.3.6)
tomlrb (1.2.8)
typhoeus (1.3.1)
ethon (>= 0.9.0)
tzinfo (1.2.5)
Expand Down Expand Up @@ -168,6 +176,7 @@ DEPENDENCIES
launchy
wdm
whatsup_github
mdl

BUNDLED WITH
1.17.3
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ task :whatsnew do
print 'Generating data for the weekly digest: $ '.magenta
sh 'whatsup_github'
end
desc 'Run linters'
task lint: %w[lint:md]
19 changes: 19 additions & 0 deletions _checks/md-check-hook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This Jekyll hook runs Markdown linter (https://github.com/markdownlint/markdownlint)
# on .md files that git tracks as 'modified' ('git ls-files -m').
# '_checks/md_style' sets a style (https://github.com/markdownlint/markdownlint/blob/master/docs/creating_styles.md)
# that is a set of rules to be applied when linting (https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md).
# '.mdlrc' sets linting configuration (https://github.com/markdownlint/markdownlint/blob/master/docs/configuration.md).
#
# The plugin runs in serving mode only.
#
Jekyll::Hooks.register :site, :post_write do |site|
next unless site.config['serving']
puts 'Checking Markdown syntax.'.blue
staged_files = `git ls-files -m`.split("\n")
staged_md_files = staged_files.select { |file| File.extname(file) == '.md' }
next if staged_md_files.empty?
staged_md_files_as_a_string = staged_md_files.join(' ')
report = `mdl #{staged_md_files_as_a_string}`
puts report.yellow
puts 'The rules are defined in _checks/md_style'
end
6 changes: 6 additions & 0 deletions _checks/md_style
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
all

exclude_rule 'MD002'
exclude_rule 'MD013'
exclude_rule 'MD041'
exclude_rule 'MD034'
29 changes: 29 additions & 0 deletions bin/mdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'mdl' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("mdl", "mdl")
17 changes: 17 additions & 0 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace :lint do
desc 'Check Markdown syntax in a file or directory by path (e.g. path=mftf)'
task :md do
path = ENV['path']
unless path
staged_files = `git ls-files -m`.split("\n")
staged_md_files = staged_files.select { |file| File.extname(file) == '.md' }
abort 'Cannot find any modified .md files.' if staged_md_files.empty?
path = staged_md_files.join(' ')
end
# require 'pry'
# binding.pry
report = `mdl #{path}`
puts report.yellow
puts 'The rules are defined in _checks/md_style'
end
end

0 comments on commit a63a118

Please sign in to comment.