Linting Blog Posts with Danger

I use Jekyll and GitHub Pages for blogging. One of the main benefits of these tools is using GitHub pull requests for reviews of my writing from both humans and robots. :robot:

I recently integrated Danger into my Jekyll site’s review process. Their thorough documentation guided me through creating a bot account, setting up a GitHub access token, creating a Dangerfile, and hooking it all up on Travis CI.

To lint my blog posts for misspelling and other prose issues, I added a couple gems to my Gemfile and ran bundle install:

# Gemfile
group :ci do
  gem 'danger'
  gem 'danger-prose'
end

Next, I updated my Dangerfile to run danger-prose on any new or modified blog post files:

# Dangerfile

# Collect a list of all new or modified blog posts
posts = (git.modified_files + git.added_files).select {
  |file| file.start_with? "_posts/"
}

# Ignore some common words / abbreviations
# danger-prose doesn't need to warn me
# that my GitHub username is misspelled, for example
prose.ignored_words = [
  "macklinu",
  "npm",
  "es2015"
]

# Lint the blog posts!
prose.lint_files posts
prose.check_spelling posts

After enabling the Travis CI job for my repo, the .travis.yml file simply executes danger as its main script:

# .travis.yml
language: ruby
rvm:
  - 2.4.0
cache:
  - bundler
script:
  - bundle exec danger

Now Danger will comment with any prose issues on blog post pull requests.

Danger comment

Check out the PR for this blog post as an example.