Application 2021-10-09 ⏱ 2 min read

Proofreading Text with textlint and reviewdog on CircleCI

An article on how I automated text proofreading on CircleCI using textlint and reviewdog. For text managed on GitHub, it sets up CI to run textlint and feed the warnings back onto the pull request via reviewdog, which is handy when writing long-form articles.

Read in: ja
Proofreading Text with textlint and reviewdog on CircleCI

Overview

I wanted to automate text proofreading when writing long documents, so I gave it a try.

Structure

The text is managed on GitHub, and the directory structure is as follows:

├── .circleci
│   └── config.yml
├── README.md
├── documents
│   ├── はじめに.md
│   └── おわりに.md
├── images
├── .textlintrc
├── package-lock.json
└── package.json

Installing npm Packages

Initial setup.

npm init -y

Install textlint and the rules used by textlint.

npm install --save-dev  textlint  textlint-rule-preset-ja-spacing     textlint-rule-preset-ja-technical-writing     textlint-rule-spellcheck-tech-word textlint-rule-preset-jtf-style textlint-rule-preset-japanese

Setting textlint Rules

.textlintrc

{
  "filters": {},
  "rules": {
    "preset-ja-spacing": true,
    "preset-ja-technical-writing": true,
	"preset-japanese": true,
	"preset-jtf-style": true,
    "spellcheck-tech-word": true
  }
}

CircleCI Configuration

Generate a token that only allows repo on GitHub and set it as an environment variable named REVIEWDOG_GITHUB_API_TOKEN.

The config.yml settings are as follows:

version: 2
jobs:
  build:
    docker:
      - image: vvakame/review:latest
        environment:
          REVIEWDOG_VERSION: latest
    steps:
      - checkout
      - restore_cache:
          keys:
            - npm-cache-{{ checksum "package-lock.json" }}
      - run:
          name: Setup
          command: npm install
      - save_cache:
          key: npm-cache-{{ checksum "package-lock.json" }}
          paths:
            - ./node_modules
      - run:
          name: install reviewdog
          command: "curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh| sh -s $REVIEWDOG_VERSION"
      - run:
          name: lint for ja
          command: "$(npm bin)/textlint -f checkstyle documents/*.md | tee check_result"
      - run:
          name: reviewdog
          command: >
              if [ -n "$REVIEWDOG_GITHUB_API_TOKEN" ]; then
                cat check_result | ./bin/reviewdog -f=checkstyle -name=textlint -reporter=github-pr-review
              fi
          when: on_fail

Running the CI

If textlint catches any issues, reviewdog will comment on them.

Screenshot 2021-10-09 22 38 19

References

Tags: CircleCI npm textlint
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles