Proofreading Text with textlint and reviewdog on CircleCI
Source: Dev.to
Overview
Automate Japanese text proofreading for documents stored in a GitHub repository using textlint, reviewdog, and CircleCI.
Directory Structure
.
├── .circleci
│ └── config.yml
├── README.md
├── documents
│ ├── はじめに.md
│ └── おわりに.md
├── images
├── .textlintrc
├── package-lock.json
└── package.jsonInitial Setup
npm init -yInstall textlint and Required Rules
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.textlintrc Configuration
{
"filters": {},
"rules": {
"preset-ja-spacing": true,
"preset-ja-technical-writing": true,
"preset-japanese": true,
"preset-jtf-style": true,
"spellcheck-tech-word": true
}
}CircleCI Configuration (.circleci/config.yml)
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 Japanese documents
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_failHow It Works
- textlint scans all Markdown files under
documents/and outputs results in Checkstyle format. - The output is saved to
check_result. - reviewdog reads
check_resultand posts comments on the associated GitHub Pull Request (if theREVIEWDOG_GITHUB_API_TOKENenvironment variable is set).