Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update lint:text command for incoming document #454

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions beta/.husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ yarn generate-ids
git add -u src/pages/**/*.md
yarn prettier
yarn lint:fix
yarn lint-staged
19 changes: 19 additions & 0 deletions beta/.textlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"rules": {
"preset-jtf-style": {
"1.1.3.箇条書き": false,
"1.2.1.句点(。)と読点(、)": false,
"1.2.2.ピリオド(.)とカンマ(,)": false,
"3.1.1.全角文字と半角文字の間": false,
"4.2.1.感嘆符(!)": false,
"4.2.2.疑問符(?)": false
},
"@textlint-rule/no-invalid-control-character": {
"checkCode": true
},
"prh": {
"severity" : "warning",
"rulePaths" :["./prh.yml"]
}
}
}
10 changes: 10 additions & 0 deletions beta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "next build && node ./scripts/generateRSS.js",
"lint": "next lint",
"lint:fix": "next lint --fix",
"lint:text": "textlint --rulesdir=./textlint src/pages/*.md src/pages/{blog,community,learn,reference}/*.md \"src/pages/blog/{2018,2019,20[2-9]*}/**/*.md\"",
"format:source": "prettier --config .prettierrc --write \"{plugins,src}/**/*.{js,ts,jsx,tsx}\"",
"nit:source": "prettier --config .prettierrc --list-different \"{plugins,src}/**/*.{js,ts,jsx,tsx}\"",
"prettier": "yarn format:source",
Expand Down Expand Up @@ -40,6 +41,7 @@
},
"devDependencies": {
"@mdx-js/loader": "^1.6.16",
"@textlint-rule/textlint-rule-no-invalid-control-character": "^2.0.0",
"@types/body-scroll-lock": "^2.6.1",
"@types/classnames": "^2.2.10",
"@types/github-slugger": "^1.3.0",
Expand All @@ -66,6 +68,7 @@
"gray-matter": "^4.0.2",
"husky": "^7.0.4",
"is-ci": "^3.0.1",
"lint-staged": "^12.1.2",
"mdast-util-to-string": "^1.1.0",
"npm-run-all": "^4.1.5",
"patch-package": "^6.2.2",
Expand All @@ -84,6 +87,8 @@
"retext-smartypants": "^4.0.0",
"rss": "^1.2.2",
"tailwindcss": "^2.2.7",
"textlint": "^12.1.0",
"textlint-rule-preset-jtf-style": "^2.3.12",
"typescript": "^4.0.2",
"unist-util-visit": "^2.0.3",
"webpack-bundle-analyzer": "^4.5.0"
Expand All @@ -95,5 +100,10 @@
"budget": null,
"budgetPercentIncreaseRed": 10,
"showDetails": true
},
"lint-staged": {
"*.md": [
"textlint --rulesdir=./textlint"
]
}
}
76 changes: 76 additions & 0 deletions beta/prh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# prh version
version: 1
rules:

- expected: ください
pattern: 下さい
prh: 補助動詞はかな書きにします

- expected: てみる
pattern: て見る
prh: 補助動詞はかな書きにします

- expected: てくる
pattern: て来る
prh: 補助動詞はかな書きにします

- expected: てしまう
pattern: /て(仕舞|終|蔵|了)う/
prh: 補助動詞はかな書きにします

- expected: ついに
pattern: /(遂|終)に/
prh: 語彙化した副詞はなるべくかな書きにします

- expected: まれに
pattern: /(希|稀)に/
prh: 語彙化した副詞はなるべくかな書きにします

- expected: $1とき
pattern: /(な|の)時(?!点|代|々|間|計)/
prh: 語彙化した副詞はなるべくかな書きにします
specs:
- from: その時
to: そのとき
- from: その時点
to: その時点
- from: その時代
to: その時代
- from: それまでの時間
to: それまでの時間
- from: 同時
to: 同時
- from: 実行時
to: 実行時
- from: 利用時
to: 利用時
- from: 開発時
to: 開発時
- from: 時点
to: 時点
- from: 時代
to: 時代
- from: 時間
to: 時間
- from: 時計
to: 時計

- expected: ようやく
pattern: 漸く
prh: 語彙化した副詞はかな書きにします

- expected: おそらく
pattern: 恐らく
prh: 語彙化した副詞はかな書きにします

- expected: ユーザ
pattern: ユーザー
prh: 3音以上の語の最後の長音府は原則として省略します

- expected: リスナ
pattern: リスナー
prh: 3音以上の語の最後の長音府は原則として省略します

- expected: ハンドラ
pattern: ハンドラー
prh: 3音以上の語の最後の長音府は原則として省略します
102 changes: 102 additions & 0 deletions beta/textlint/jp-reactjs-org-lint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const toString = require('mdast-util-to-string');

module.exports = context => {
return {
// [context.Syntax.Header]: node => {},

[context.Syntax.Paragraph]: node => {
// Checks against paragraph-based rules.

// Convert a paragraph to plain text, stripping any markups
const text = toString(node);

enforceSpaceAfterQuestionOrExclamation(node, text, context);
noHanPunctSpace(node, text, context);
enforceZenHanSpace(node, text, context);
noLineEndSpace(node, text, context);
noConflictMarker(node, text, context);
},

[context.Syntax.Str]: node => {
const text = toString(node);
const index = text.indexOf(' ');
if (index >= 0) {
context.report(
node,
new context.RuleError(
'いかなる場合も全角スペースは使用しないでください。',
{index},
),
);
}
},
};
};

const enforceSpaceAfterQuestionOrExclamation = (node, text, context) => {
const markReg = /[!?](\u3000|[A-Za-z0-9]|[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[ぁ-んァ-ヶ])/;
if (markReg.exec(text)) {
context.report(
node,
new context.RuleError(
'全角の「!」「?」と次の文の間には半角スペースを挿入してください。',
),
);
}
};

const noHanPunctSpace = (node, text, context) => {
const match = /(.{0,3})[、。]( |\u3000)/.exec(text);
if (match) {
context.report(
node,
new context.RuleError(
`全角の句読点の直後にスペースを入れてはいけません("${match[0]}")。`,
),
);
}
};

const enforceZenHanSpace = (node, text, context) => {
const hanZen = /[A-Za-z0-9](?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[ぁ-んァ-ヶ])/;
const zenHan = /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[ぁ-んァ-ヶ])[A-Za-z0-9]/;

const hanZenMatch = hanZen.exec(text);
const zenHanMatch = zenHan.exec(text);

if (hanZenMatch || zenHanMatch) {
const matched = hanZenMatch ? hanZenMatch[0] : zenHanMatch[0];
context.report(
node,
new context.RuleError(
`全角文字と半角英数字とが隣接しています("${matched}")。` +
`半角スペースを挿入してください。`,
),
);
}
};

const noLineEndSpace = (node, text, context) => {
// This detects a line-end space *only when* the line contains Japanese characters.
const reg = /(?:[\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF]|[\uD840-\uD87F][\uDC00-\uDFFF]|[ぁ-んァ-ヶ]).?(\s|\u3000)$/;

if (reg.exec(text)) {
context.report(
node,
new context.RuleError('行末にスペース文字を入れないでください。'),
);
}
};

const noConflictMarker = (node, text, context) => {
const reg = /<<<<<<< HEAD/;

if (reg.exec(text)) {
context.report(
node,
new context.RuleError(
'コンフリクトマーカーが残っています。コンフリクトを解消してください。',
),
);
}
};
Loading