DEV Community

Cover image for Proofreading Text with textlint and reviewdog on CircleCI
Kenta Takeuchi
Kenta Takeuchi

Posted on • Originally published at bmf-tech.com

Proofreading Text with textlint and reviewdog on CircleCI

This article was originally published on bmf-tech.com.

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
Enter fullscreen mode Exit fullscreen mode

Installing npm Packages

Initial setup.

npm init -y
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
  }
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Running the CI

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

Screenshot 2021-10-09 22 38 19

References

Top comments (0)