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

Commit

Permalink
[site] Update Markdown linting tasks (#5320)
Browse files Browse the repository at this point in the history
* Update Markdown linting implementation

* Remove obsolete rake tasks
  • Loading branch information
dshevtsov authored and hguthrie committed Sep 26, 2019
1 parent 4bf90bb commit 1cb8fb2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
12 changes: 6 additions & 6 deletions _checks/md_check_hook.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# This Jekyll hook runs Markdown linter (https://github.com/markdownlint/markdownlint)
# on .md files that git tracks as 'modified' ('git ls-files -m').
# on modified '.md' files.
# '_checks/styles/style-rules-dev' 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).
Expand All @@ -11,13 +11,13 @@
Jekyll::Hooks.register :site, :post_write do |site|
next unless site.config['serving']

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?
modified_files = `git ls-files --modified --others --exclude-standard`.split("\n")
modified_md_files = modified_files.select { |file| File.extname(file) == '.md' }
next if modified_md_files.empty?

puts 'Checking Markdown syntax...'.blue
staged_md_files_as_a_string = staged_md_files.join(' ')
report = `bin/mdl #{staged_md_files_as_a_string}`
modified_md_files_as_a_string = modified_md_files.join(' ')
report = `bin/mdl #{modified_md_files_as_a_string}`
puts report.yellow
puts 'The style is defined in _checks/styles/style-rules-dev'.yellow
end
18 changes: 9 additions & 9 deletions rakelib/check.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ namespace :check do
puts 'Running image optimizer...'.magenta
path = ENV['path']
unless path
staged_files = `git ls-files --modified --others --exclude-standard`.split("\n")
# staged_md_files = staged_files.select { |file| File.extname(file) == '.md' }
abort 'Didn\'t find any modified files.'.blue if staged_files.empty?
path = staged_files.join(' ')
modified_files = `git ls-files --modified --others --exclude-standard`.split("\n")
abort 'Didn\'t find any modified files.'.blue if modified_files.empty?
path = modified_files.join(' ')
end
system "bin/image_optim --no-pngout --no-svgo --recursive #{path}"
end

desc 'Check Markdown syntax in modified files or in a particular file or directory by path (e.g. path=mftf)'
task :mdl do
puts 'Running Markdown linter ...'.magenta

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.'.magenta if staged_md_files.empty?
path = staged_md_files.join(' ')
modified_files = `git ls-files --modified --others --exclude-standard`.split("\n")
modified_md_files = modified_files.select { |file| File.extname(file) == '.md' }
abort 'Cannot find any modified .md files.'.magenta if modified_md_files.empty?
path = modified_md_files.join(' ')
end
puts 'Running Markdown linter ...'.magenta
report = `bin/mdl #{path}`
puts report.yellow
puts 'The rules are defined in _checks/styles/style-rules-dev'.magenta
Expand Down
3 changes: 0 additions & 3 deletions rakelib/test.rake
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,4 @@ namespace :test do
abort "The Markdown linter has found #{output.lines.count} issues".red unless output.empty?
puts 'No issues found'.magenta
end

task style: %w[md]
task cicd: %w[html]
end

0 comments on commit 1cb8fb2

Please sign in to comment.