Skip to content

Commit

Permalink
Merge pull request #29 from razeware/WEB-3514
Browse files Browse the repository at this point in the history
WEB-3514: Adding a framework for linting markdown content
  • Loading branch information
sammyd authored Jul 28, 2020
2 parents fadc9dc + b60f6b2 commit 7db4504
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/lib/linting/image/attachable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def lint_attachments
end
end

def locate_errors(image)
def locate_errors(_image)
[{
start_line: 1,
end_line: 1
Expand Down
4 changes: 4 additions & 0 deletions app/lib/linting/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def lint_with_ui(options:, show_ui: true) # rubocop:disable Metrics/MethodLength
end
return unless annotations.blank?

with_spinner(title: 'Validating markdown', show: show_ui) do
annotations.concat(Linting::MarkdownLinter.new(book: book).lint)
end

with_spinner(title: 'Validating image references', show: show_ui) do
annotations.concat(Linting::ImageLinter.new(book: book).lint)
end
Expand Down
23 changes: 23 additions & 0 deletions app/lib/linting/markdown/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Linting
module Markdown
# Lint the markdown associated with a book
class Book
include Linting::Markdown::Renderable

def self.lint(book)
new(book).lint
end

def lint
[].tap do |annotations|
annotations.concat(lint_markdown_attributes)
object.sections.each do |section|
annotations.concat(Linting::Markdown::Section.lint(section))
end
end
end
end
end
end
20 changes: 20 additions & 0 deletions app/lib/linting/markdown/chapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Linting
module Markdown
# Lint the markdown associated with a chapter
class Chapter
include Linting::Markdown::Renderable

def self.lint(chapter)
new(chapter).lint
end

def lint
[].tap do |annotations|
annotations.concat(lint_markdown_attributes)
end
end
end
end
end
25 changes: 25 additions & 0 deletions app/lib/linting/markdown/renderable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Linting
module Markdown
# Check that the attributes marked as markdown renderable are valid
module Renderable
include Linting::FileExistenceChecker

attr_reader :object

def initialize(object)
@object = object
end

def lint_markdown_attributes
object.markdown_render_loop do |content, is_file|
markdown = is_file ? File.read(content) : content
# TODO: Do some checking here
content
end
[]
end
end
end
end
23 changes: 23 additions & 0 deletions app/lib/linting/markdown/section.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Linting
module Markdown
# Lint the markdown associated with a section
class Section
include Linting::Markdown::Renderable

def self.lint(section)
new(section).lint
end

def lint
[].tap do |annotations|
annotations.concat(lint_markdown_attributes)
object.chapters.each do |chapter|
annotations.concat(Linting::Markdown::Chapter.lint(chapter))
end
end
end
end
end
end
16 changes: 16 additions & 0 deletions app/lib/linting/markdown_linter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Linting
# Lints the markdown in a book
class MarkdownLinter
attr_reader :book

def initialize(book:)
@book = book
end

def lint
Linting::Markdown::Book.lint(book)
end
end
end

0 comments on commit 7db4504

Please sign in to comment.