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

Commit c4200fa

Browse files
authored
Merge pull request #4568 from magento/ds_lint-md
Add markdown linting
2 parents 23c961f + d074e14 commit c4200fa

File tree

8 files changed

+116
-1
lines changed

8 files changed

+116
-1
lines changed

.mdlrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style '_checks/md_style'

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gem 'wdm', platform: :mswin
1010

1111
group :test do
1212
gem 'html-proofer'
13+
gem 'mdl'
1314
gem 'launchy'
1415
end
1516

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,16 @@ GEM
106106
rb-fsevent (~> 0.9, >= 0.9.4)
107107
rb-inotify (~> 0.9, >= 0.9.7)
108108
ruby_dep (~> 1.2)
109+
mdl (0.5.0)
110+
kramdown (~> 1.12, >= 1.12.0)
111+
mixlib-cli (~> 1.7, >= 1.7.0)
112+
mixlib-config (~> 2.2, >= 2.2.1)
109113
mercenary (0.3.6)
110114
mini_portile2 (2.3.0)
111115
minitest (5.11.3)
116+
mixlib-cli (1.7.0)
117+
mixlib-config (2.2.18)
118+
tomlrb
112119
multipart-post (2.1.1)
113120
netrc (0.11.0)
114121
nokogiri (1.8.5)
@@ -137,6 +144,7 @@ GEM
137144
faraday (> 0.8, < 2.0)
138145
thor (0.20.3)
139146
thread_safe (0.3.6)
147+
tomlrb (1.2.8)
140148
typhoeus (1.3.1)
141149
ethon (>= 0.9.0)
142150
tzinfo (1.2.5)
@@ -166,6 +174,7 @@ DEPENDENCIES
166174
jekyll-sitemap
167175
jekyll-titles-from-headings
168176
launchy
177+
mdl
169178
wdm
170179
whatsup_github
171180

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ desc 'Pull docs from external repositories'
6262
task init: %w[multirepo:init]
6363

6464
desc 'Run checks (image optimization).'
65-
task check: %w[check:image_optim]
65+
task check: %w[check:image_optim check:mdl]
6666

6767
desc 'Generate data for the weekly digest.'
6868
task :whatsnew do

_checks/md-check-hook.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This Jekyll hook runs Markdown linter (https://github.com/markdownlint/markdownlint)
2+
# on .md files that git tracks as 'modified' ('git ls-files -m').
3+
# '_checks/md_style' sets a style (https://github.com/markdownlint/markdownlint/blob/master/docs/creating_styles.md)
4+
# that is a set of rules to be applied when linting (https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md).
5+
# '.mdlrc' sets linting configuration (https://github.com/markdownlint/markdownlint/blob/master/docs/configuration.md).
6+
#
7+
# The plugin runs in serving mode only.
8+
#
9+
Jekyll::Hooks.register :site, :post_write do |site|
10+
next unless site.config['serving']
11+
staged_files = `git ls-files -m`.split("\n")
12+
staged_md_files = staged_files.select { |file| File.extname(file) == '.md' }
13+
next if staged_md_files.empty?
14+
puts 'Checking Markdown syntax...'.blue
15+
staged_md_files_as_a_string = staged_md_files.join(' ')
16+
report = `bin/mdl #{staged_md_files_as_a_string}`
17+
puts report.yellow
18+
puts 'The style is defined in _checks/md_style'.yellow
19+
end

_checks/md_style

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Approved style
2+
rule 'MD001'
3+
exclude_rule 'MD002'
4+
rule 'MD003', :style => :atx
5+
rule 'MD004'
6+
rule 'MD005'
7+
rule 'MD006'
8+
rule 'MD009'
9+
rule 'MD010'
10+
rule 'MD011'
11+
rule 'MD012'
12+
exclude_rule 'MD013'
13+
exclude_rule 'MD014'
14+
rule 'MD018'
15+
rule 'MD019'
16+
exclude_rule 'MD020'
17+
exclude_rule 'MD021'
18+
rule 'MD022'
19+
rule 'MD023'
20+
rule 'MD024', :allow_different_nesting => true
21+
rule 'MD025'
22+
23+
# The following rules still require Docs team review and approval
24+
exclude_rule 'MD007'
25+
exclude_rule 'MD026'
26+
exclude_rule 'MD027'
27+
exclude_rule 'MD028'
28+
exclude_rule 'MD029'
29+
exclude_rule 'MD030'
30+
exclude_rule 'MD031'
31+
exclude_rule 'MD032'
32+
exclude_rule 'MD033'
33+
exclude_rule 'MD034'
34+
exclude_rule 'MD035'
35+
exclude_rule 'MD036'
36+
exclude_rule 'MD037'
37+
exclude_rule 'MD038'
38+
exclude_rule 'MD039'
39+
exclude_rule 'MD040'
40+
exclude_rule 'MD041'
41+
exclude_rule 'MD046'

bin/mdl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
#
5+
# This file was generated by Bundler.
6+
#
7+
# The application 'mdl' is installed as part of a gem, and
8+
# this file is here to facilitate running it.
9+
#
10+
11+
require "pathname"
12+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13+
Pathname.new(__FILE__).realpath)
14+
15+
bundle_binstub = File.expand_path("../bundle", __FILE__)
16+
17+
if File.file?(bundle_binstub)
18+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19+
load(bundle_binstub)
20+
else
21+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23+
end
24+
end
25+
26+
require "rubygems"
27+
require "bundler/setup"
28+
29+
load Gem.bin_path("mdl", "mdl")

rakelib/check.rake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,19 @@ namespace :check do
1111
end
1212
system "bin/image_optim --no-pngout --no-svgo --recursive #{path}"
1313
end
14+
15+
desc 'Check Markdown syntax in modified files or in a particular file or directory by path (e.g. path=mftf)'
16+
task :mdl do
17+
path = ENV['path']
18+
unless path
19+
staged_files = `git ls-files -m`.split("\n")
20+
staged_md_files = staged_files.select { |file| File.extname(file) == '.md' }
21+
abort 'Cannot find any modified .md files.'.magenta if staged_md_files.empty?
22+
path = staged_md_files.join(' ')
23+
end
24+
puts 'Running Markdown linter ...'.magenta
25+
report = `bin/mdl #{path}`
26+
puts report.yellow
27+
puts 'The rules are defined in _checks/md_style'.magenta
28+
end
1429
end

0 commit comments

Comments
 (0)