prh 5.4.4 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/LICENSE +21 -0
- package/README.md +16 -1
- package/lib/changeset/changeset.js +33 -34
- package/lib/changeset/changeset.js.map +1 -1
- package/lib/changeset/diff.d.ts +2 -2
- package/lib/changeset/diff.js +37 -48
- package/lib/changeset/diff.js.map +1 -1
- package/lib/changeset/index.js +10 -9
- package/lib/changeset/index.js.map +1 -1
- package/lib/cli.js +58 -58
- package/lib/cli.js.map +1 -1
- package/lib/engine.js +42 -44
- package/lib/engine.js.map +1 -1
- package/lib/index.js +46 -58
- package/lib/index.js.map +1 -1
- package/lib/options.js +4 -4
- package/lib/options.js.map +1 -1
- package/lib/paragraph.js +16 -17
- package/lib/paragraph.js.map +1 -1
- package/lib/raw.js.map +1 -1
- package/lib/rule.js +61 -62
- package/lib/rule.js.map +1 -1
- package/lib/ruleSpec.js +7 -7
- package/lib/ruleSpec.js.map +1 -1
- package/lib/target.js +19 -19
- package/lib/target.js.map +1 -1
- package/lib/targetPattern.js +18 -18
- package/lib/targetPattern.js.map +1 -1
- package/lib/utils/content.js +6 -6
- package/lib/utils/content.js.map +1 -1
- package/lib/utils/regexp.js +50 -42
- package/lib/utils/regexp.js.map +1 -1
- package/package.json +24 -24
- package/prh-rules/media/WEB+DB_PRESS.yml +141 -21
- package/prh-rules/media/techbooster.yml +3 -1
- package/prh-rules/package-lock.json +52 -128
- package/prh-rules/package.json +4 -4
- package/prh-rules/test.js +13 -13
- package/tsconfig.json +6 -6
- package/.gitmodules +0 -3
package/CHANGELOG.md
CHANGED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vvakame
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# proofreading-helper [](https://github.com/prh/prh/actions/workflows/ci.yml)
|
|
2
2
|
|
|
3
3
|
あなたの校正を手伝ってくれるライブラリ。
|
|
4
4
|
|
|
@@ -179,6 +179,21 @@ Markdownであれば `<!-- prh:disable -->` とすることができます。
|
|
|
179
179
|
このため、無視するルールの記述に半角スペースを利用することができなくなっています。
|
|
180
180
|
代わりに `\s` などを使ってください。
|
|
181
181
|
|
|
182
|
+
## リリース手順
|
|
183
|
+
|
|
184
|
+
npmへのpublishはGitHub Actionsで自動化されています。
|
|
185
|
+
GitHub Releaseを作成すると自動的にnpmにpublishされます。
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
# 1. バージョンを更新(package.json更新 + コミット + gitタグ作成)
|
|
189
|
+
$ npm version patch # patch: 5.4.4 → 5.4.5, minor: 5.4.4 → 5.5.0, major: 5.4.4 → 6.0.0
|
|
190
|
+
|
|
191
|
+
# 2. リモートに反映
|
|
192
|
+
$ git push && git push --tags
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
その後、GitHubで該当タグからReleaseを作成してください。
|
|
196
|
+
|
|
182
197
|
## 関連ツール
|
|
183
198
|
|
|
184
199
|
Atomのプラグインである[language-review](https://atom.io/packages/language-review)に組み込まれています。
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.ChangeSet = void 0;
|
|
4
|
+
class ChangeSet {
|
|
5
|
+
constructor(params) {
|
|
5
6
|
this.filePath = params.filePath;
|
|
6
7
|
this.content = params.content;
|
|
7
8
|
this.diffs = params.diffs;
|
|
8
9
|
this._prepare();
|
|
9
10
|
}
|
|
10
11
|
/* @internal */
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.diffs = this.diffs.sort(function (a, b) {
|
|
12
|
+
_prepare() {
|
|
13
|
+
this.diffs = this.diffs.sort((a, b) => {
|
|
14
14
|
if (a.index !== b.index) {
|
|
15
15
|
return a.index - b.index;
|
|
16
16
|
}
|
|
@@ -19,8 +19,8 @@ var ChangeSet = /** @class */ (function () {
|
|
|
19
19
|
// VSCodeのLSPでworkspace/applyEditを送った時に重複した範囲があるとエラーになる
|
|
20
20
|
// よって、重複する箇所のあるdiffを排除する必要がある
|
|
21
21
|
// 1. 同じindexからスタート→検出文字数が長い方を優先(より複雑なルール
|
|
22
|
-
this.diffs = this.diffs.filter(
|
|
23
|
-
|
|
22
|
+
this.diffs = this.diffs.filter((diff, idx) => {
|
|
23
|
+
const next = this.diffs[idx + 1];
|
|
24
24
|
if (!next) {
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
@@ -30,8 +30,8 @@ var ChangeSet = /** @class */ (function () {
|
|
|
30
30
|
return true;
|
|
31
31
|
});
|
|
32
32
|
// 2. 異なるindexからスタート→indexが先の方を優先(先勝ち
|
|
33
|
-
this.diffs = this.diffs.filter(
|
|
34
|
-
|
|
33
|
+
this.diffs = this.diffs.filter((diff, idx) => {
|
|
34
|
+
const prev = this.diffs[idx - 1];
|
|
35
35
|
if (!prev) {
|
|
36
36
|
return true;
|
|
37
37
|
}
|
|
@@ -40,17 +40,17 @@ var ChangeSet = /** @class */ (function () {
|
|
|
40
40
|
}
|
|
41
41
|
return true;
|
|
42
42
|
});
|
|
43
|
-
}
|
|
44
|
-
|
|
43
|
+
}
|
|
44
|
+
concat(other) {
|
|
45
45
|
this.diffs = this.diffs.concat(other.diffs);
|
|
46
46
|
this._prepare();
|
|
47
47
|
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
48
|
+
}
|
|
49
|
+
applyChangeSets(str) {
|
|
50
50
|
this._prepare();
|
|
51
|
-
|
|
52
|
-
this.diffs.forEach(
|
|
53
|
-
|
|
51
|
+
let delta = 0;
|
|
52
|
+
this.diffs.forEach((diff) => {
|
|
53
|
+
const applied = diff.apply(str, delta);
|
|
54
54
|
if (applied == null) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
@@ -58,20 +58,20 @@ var ChangeSet = /** @class */ (function () {
|
|
|
58
58
|
delta = applied.newDelta;
|
|
59
59
|
});
|
|
60
60
|
return str;
|
|
61
|
-
}
|
|
62
|
-
|
|
61
|
+
}
|
|
62
|
+
subtract(subtrahend) {
|
|
63
63
|
this._prepare();
|
|
64
64
|
subtrahend._prepare();
|
|
65
|
-
|
|
65
|
+
const result = new ChangeSet({
|
|
66
66
|
filePath: this.filePath,
|
|
67
67
|
content: this.content,
|
|
68
|
-
diffs: this.diffs.map(
|
|
68
|
+
diffs: this.diffs.map((v) => v),
|
|
69
69
|
});
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
let m = 0;
|
|
71
|
+
let s = 0;
|
|
72
72
|
while (true) {
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
const minuendDiff = result.diffs[m];
|
|
74
|
+
const subtrahendDiff = subtrahend.diffs[s];
|
|
75
75
|
if (!minuendDiff || !subtrahendDiff) {
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
@@ -87,20 +87,20 @@ var ChangeSet = /** @class */ (function () {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
return result;
|
|
90
|
-
}
|
|
91
|
-
|
|
90
|
+
}
|
|
91
|
+
intersect(audit) {
|
|
92
92
|
this._prepare();
|
|
93
93
|
audit._prepare();
|
|
94
|
-
|
|
94
|
+
const result = new ChangeSet({
|
|
95
95
|
filePath: this.filePath,
|
|
96
96
|
content: this.content,
|
|
97
97
|
diffs: [],
|
|
98
98
|
});
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
let a = 0;
|
|
100
|
+
let b = 0;
|
|
101
101
|
while (true) {
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
const baseDiff = this.diffs[a];
|
|
103
|
+
const auditDiff = audit.diffs[b];
|
|
104
104
|
if (!baseDiff || !auditDiff) {
|
|
105
105
|
break;
|
|
106
106
|
}
|
|
@@ -115,8 +115,7 @@ var ChangeSet = /** @class */ (function () {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
return result;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
}());
|
|
118
|
+
}
|
|
119
|
+
}
|
|
121
120
|
exports.ChangeSet = ChangeSet;
|
|
122
121
|
//# sourceMappingURL=changeset.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"changeset.js","sourceRoot":"","sources":["changeset.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"changeset.js","sourceRoot":"","sources":["changeset.ts"],"names":[],"mappings":";;;AAQA,MAAa,SAAS;IAKlB,YAAY,MAAuB;QAC/B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAA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AAQ,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBACzE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAChC,CAAC;YACD,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC/B,CAAC,EAAE,CAAC;YACR,CAAC;iBAAM,CAAC;gBACJ,CAAC,EAAE,CAAC;YACR,CAAC;QACL,CAAC;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AArID,8BAqIC","sourcesContent":["import { Diff } from \"./diff\";\n\nexport interface ChangeSetParams {\n filePath?: string;\n content: string;\n diffs: Diff[];\n}\n\nexport class ChangeSet {\n filePath?: string;\n content: string;\n diffs: Diff[];\n\n constructor(params: ChangeSetParams) {\n this.filePath = params.filePath;\n this.content = params.content;\n this.diffs = params.diffs;\n\n this._prepare();\n }\n\n /* @internal */\n _prepare() {\n this.diffs = this.diffs.sort((a, b) => {\n if (a.index !== b.index) {\n return a.index - b.index;\n }\n return a.tailIndex - b.tailIndex;\n });\n\n // VSCodeのLSPでworkspace/applyEditを送った時に重複した範囲があるとエラーになる\n // よって、重複する箇所のあるdiffを排除する必要がある\n // 1. 同じindexからスタート→検出文字数が長い方を優先(より複雑なルール\n this.diffs = this.diffs.filter((diff, idx) => {\n const next = this.diffs[idx + 1];\n if (!next) {\n return true;\n }\n if (diff.index === next.index && diff.tailIndex < next.tailIndex) {\n return false;\n }\n return true;\n });\n // 2. 異なるindexからスタート→indexが先の方を優先(先勝ち\n this.diffs = this.diffs.filter((diff, idx) => {\n const prev = this.diffs[idx - 1];\n if (!prev) {\n return true;\n }\n if (diff.index < prev.tailIndex) {\n return false;\n }\n return true;\n });\n }\n\n concat(other: ChangeSet): this {\n this.diffs = this.diffs.concat(other.diffs);\n this._prepare();\n return this;\n }\n\n applyChangeSets(str: string): string {\n this._prepare();\n\n let delta = 0;\n this.diffs.forEach((diff) => {\n const applied = diff.apply(str, delta);\n if (applied == null) {\n return;\n }\n str = applied.replaced;\n delta = applied.newDelta;\n });\n\n return str;\n }\n\n subtract(subtrahend: ChangeSet): ChangeSet {\n this._prepare();\n subtrahend._prepare();\n\n const result: ChangeSet = new ChangeSet({\n filePath: this.filePath,\n content: this.content,\n diffs: this.diffs.map((v) => v),\n });\n let m = 0;\n let s = 0;\n\n while (true) {\n const minuendDiff = result.diffs[m];\n const subtrahendDiff = subtrahend.diffs[s];\n\n if (!minuendDiff || !subtrahendDiff) {\n break;\n }\n if (!minuendDiff.isEncloser(subtrahendDiff) && minuendDiff.isCollide(subtrahendDiff)) {\n result.diffs.splice(m, 1);\n continue;\n }\n if (minuendDiff.isBefore(subtrahendDiff)) {\n m++;\n } else {\n s++;\n }\n }\n\n return result;\n }\n\n intersect(audit: ChangeSet): ChangeSet {\n this._prepare();\n audit._prepare();\n\n const result: ChangeSet = new ChangeSet({\n filePath: this.filePath,\n content: this.content,\n diffs: [],\n });\n let a = 0;\n let b = 0;\n\n while (true) {\n const baseDiff = this.diffs[a];\n const auditDiff = audit.diffs[b];\n if (!baseDiff || !auditDiff) {\n break;\n }\n if (baseDiff.isCollide(auditDiff) && result.diffs.indexOf(baseDiff) === -1) {\n result.diffs.push(baseDiff);\n }\n if (baseDiff.isBefore(auditDiff)) {\n a++;\n } else {\n b++;\n }\n }\n\n return result;\n }\n}\n"]}
|
package/lib/changeset/diff.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export declare class Diff {
|
|
|
13
13
|
matches: string[];
|
|
14
14
|
rule?: Rule;
|
|
15
15
|
constructor(params: DiffParams);
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
get tailIndex(): number;
|
|
17
|
+
get newText(): string | null;
|
|
18
18
|
/**
|
|
19
19
|
* Diffの結果を元の文章に反映する
|
|
20
20
|
* @param content 置き換えたいコンテンツ
|
package/lib/changeset/diff.js
CHANGED
|
@@ -1,49 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.Diff = void 0;
|
|
4
|
+
class Diff {
|
|
5
|
+
constructor(params) {
|
|
5
6
|
this.pattern = params.pattern;
|
|
6
7
|
this.expected = params.expected;
|
|
7
8
|
this.index = params.index;
|
|
8
9
|
this.matches = params.matches;
|
|
9
10
|
this.rule = params.rule;
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
configurable: true
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(Diff.prototype, "newText", {
|
|
19
|
-
get: function () {
|
|
20
|
-
var _this = this;
|
|
21
|
-
if (this._newText != null) {
|
|
22
|
-
return this._newText;
|
|
23
|
-
}
|
|
24
|
-
if (this.expected == null) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
var result = this.expected.replace(/\$([0-9]{1,2})/g, function (match, g1) {
|
|
28
|
-
var index = parseInt(g1, 10);
|
|
29
|
-
if (index === 0 || (_this.matches.length - 1) < index) {
|
|
30
|
-
return match;
|
|
31
|
-
}
|
|
32
|
-
return _this.matches[index] || "";
|
|
33
|
-
});
|
|
34
|
-
this._newText = result;
|
|
12
|
+
get tailIndex() {
|
|
13
|
+
return this.index + this.matches[0].length;
|
|
14
|
+
}
|
|
15
|
+
get newText() {
|
|
16
|
+
if (this._newText != null) {
|
|
35
17
|
return this._newText;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
18
|
+
}
|
|
19
|
+
if (this.expected == null) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const result = this.expected.replace(/\$([0-9]{1,2})/g, (match, g1) => {
|
|
23
|
+
const index = parseInt(g1, 10);
|
|
24
|
+
if (index === 0 || this.matches.length - 1 < index) {
|
|
25
|
+
return match;
|
|
26
|
+
}
|
|
27
|
+
return this.matches[index] || "";
|
|
28
|
+
});
|
|
29
|
+
this._newText = result;
|
|
30
|
+
return this._newText;
|
|
31
|
+
}
|
|
40
32
|
/**
|
|
41
33
|
* Diffの結果を元の文章に反映する
|
|
42
34
|
* @param content 置き換えたいコンテンツ
|
|
43
35
|
* @param delta diffの処理対象の地点がいくつズレているか 複数diffを順次適用する場合に必要
|
|
44
36
|
*/
|
|
45
|
-
|
|
46
|
-
if (delta === void 0) { delta = 0; }
|
|
37
|
+
apply(content, delta = 0) {
|
|
47
38
|
if (this.newText == null) {
|
|
48
39
|
return null;
|
|
49
40
|
}
|
|
@@ -53,11 +44,11 @@ var Diff = /** @class */ (function () {
|
|
|
53
44
|
replaced: content,
|
|
54
45
|
newDelta: delta,
|
|
55
46
|
};
|
|
56
|
-
}
|
|
57
|
-
|
|
47
|
+
}
|
|
48
|
+
isEncloser(other) {
|
|
58
49
|
return this.index < other.index && other.tailIndex < this.tailIndex;
|
|
59
|
-
}
|
|
60
|
-
|
|
50
|
+
}
|
|
51
|
+
isCollide(other) {
|
|
61
52
|
if (other.index < this.index && this.index < other.tailIndex) {
|
|
62
53
|
return true;
|
|
63
54
|
}
|
|
@@ -65,28 +56,26 @@ var Diff = /** @class */ (function () {
|
|
|
65
56
|
return true;
|
|
66
57
|
}
|
|
67
58
|
return false;
|
|
68
|
-
}
|
|
69
|
-
|
|
59
|
+
}
|
|
60
|
+
isBefore(other) {
|
|
70
61
|
return this.index < other.index;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Object.keys(this).forEach(function (key) {
|
|
62
|
+
}
|
|
63
|
+
toJSON() {
|
|
64
|
+
const result = {};
|
|
65
|
+
Object.keys(this).forEach((key) => {
|
|
76
66
|
if (key[0] === "_") {
|
|
77
67
|
return;
|
|
78
68
|
}
|
|
79
|
-
|
|
69
|
+
const value = this[key];
|
|
80
70
|
if (value instanceof RegExp) {
|
|
81
|
-
result[key] =
|
|
71
|
+
result[key] = `/${value.source}/${value.flags}`;
|
|
82
72
|
}
|
|
83
73
|
else {
|
|
84
74
|
result[key] = value;
|
|
85
75
|
}
|
|
86
76
|
});
|
|
87
77
|
return result;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
91
80
|
exports.Diff = Diff;
|
|
92
81
|
//# sourceMappingURL=diff.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["diff.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["diff.ts"],"names":[],"mappings":";;;AAUA,MAAa,IAAI;IASb,YAAY,MAAkB;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED,IAAI,SAAS;QACT,OAAO,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO;QACP,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;YACxB,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,KAAa,EAAE,EAAU,EAAE,EAAE;YAClF,MAAM,KAAK,GAAG,QAAQ,CAAC,EA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IAAI,CAAC;QAChB,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YAC3D,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,QAAQ,CAAC,KAAwB;QAC7B,OAAO,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IACpC,CAAC;IAED,MAAM;QACF,MAAM,MAAM,GAAQ,EAAE,CAAC;QACvB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC9B,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACjB,OAAO;YACX,CAAC;YACD,MAAM,KAAK,GAAI,IAAY,CAAC,GAAG,CAAC,CAAC;YACjC,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;gBAC1B,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACpD,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACxB,CAAC;QACL,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA5FD,oBA4FC","sourcesContent":["import { Rule } from \"../rule\";\n\nexport interface DiffParams {\n pattern: RegExp;\n expected?: string; // replaceが必要ないパターンの時渡されない場合がある\n index: number;\n matches: string[];\n rule?: Rule;\n}\n\nexport class Diff {\n pattern: RegExp;\n expected?: string;\n index: number;\n matches: string[];\n /** @internal */\n _newText?: string;\n rule?: Rule;\n\n constructor(params: DiffParams) {\n this.pattern = params.pattern;\n this.expected = params.expected;\n this.index = params.index;\n this.matches = params.matches;\n this.rule = params.rule;\n }\n\n get tailIndex() {\n return this.index + this.matches[0].length;\n }\n\n get newText(): string | null {\n if (this._newText != null) {\n return this._newText;\n }\n\n if (this.expected == null) {\n return null;\n }\n\n const result = this.expected.replace(/\\$([0-9]{1,2})/g, (match: string, g1: string) => {\n const index = parseInt(g1, 10);\n if (index === 0 || this.matches.length - 1 < index) {\n return match;\n }\n return this.matches[index] || \"\";\n });\n this._newText = result;\n return this._newText;\n }\n\n /**\n * Diffの結果を元の文章に反映する\n * @param content 置き換えたいコンテンツ\n * @param delta diffの処理対象の地点がいくつズレているか 複数diffを順次適用する場合に必要\n */\n apply(content: string, delta = 0): { replaced: string; newDelta: number } | null {\n if (this.newText == null) {\n return null;\n }\n content = content.slice(0, this.index + delta) + this.newText + content.slice(this.index + delta + this.matches[0].length);\n delta += this.newText.length - this.matches[0].length;\n\n return {\n replaced: content,\n newDelta: delta,\n };\n }\n\n isEncloser(other: { index: number; tailIndex: number }) {\n return this.index < other.index && other.tailIndex < this.tailIndex;\n }\n\n isCollide(other: { index: number; tailIndex: number }) {\n if (other.index < this.index && this.index < other.tailIndex) {\n return true;\n }\n if (this.index < other.index && other.index < this.tailIndex) {\n return true;\n }\n return false;\n }\n\n isBefore(other: { index: number }) {\n return this.index < other.index;\n }\n\n toJSON() {\n const result: any = {};\n Object.keys(this).forEach((key) => {\n if (key[0] === \"_\") {\n return;\n }\n const value = (this as any)[key];\n if (value instanceof RegExp) {\n result[key] = `/${value.source}/${value.flags}`;\n } else {\n result[key] = value;\n }\n });\n return result;\n }\n}\n"]}
|
package/lib/changeset/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports
|
|
3
|
+
exports.Diff = exports.ChangeSet = void 0;
|
|
4
|
+
exports.makeChangeSet = makeChangeSet;
|
|
5
|
+
const regexp_1 = require("../utils/regexp");
|
|
6
|
+
const diff_1 = require("./diff");
|
|
7
|
+
Object.defineProperty(exports, "Diff", { enumerable: true, get: function () { return diff_1.Diff; } });
|
|
8
|
+
const changeset_1 = require("./changeset");
|
|
9
|
+
Object.defineProperty(exports, "ChangeSet", { enumerable: true, get: function () { return changeset_1.ChangeSet; } });
|
|
8
10
|
function makeChangeSet(filePath, content, pattern, expected) {
|
|
9
11
|
pattern.lastIndex = 0;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return new changeset_1.ChangeSet({ filePath
|
|
12
|
+
const resultList = (0, regexp_1.collectAll)(pattern, content);
|
|
13
|
+
const diffs = resultList.map((matches) => new diff_1.Diff({ pattern, expected, index: matches.index, matches }));
|
|
14
|
+
return new changeset_1.ChangeSet({ filePath, content, diffs });
|
|
13
15
|
}
|
|
14
|
-
exports.makeChangeSet = makeChangeSet;
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAMA,sCAKC;AAXD,4CAA6C;AAC7C,iCAA8B;AAGV,qFAHX,WAAI,OAGW;AAFxB,2CAAwC;AAE/B,0FAFA,qBAAS,OAEA;AAElB,SAAgB,aAAa,CAAC,QAAgB,EAAE,OAAe,EAAE,OAAe,EAAE,QAAiB;IAC/F,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC;IACtB,MAAM,UAAU,GAAG,IAAA,mBAAU,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,WAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;IAC1G,OAAO,IAAI,qBAAS,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { collectAll } from \"../utils/regexp\";\nimport { Diff } from \"./diff\";\nimport { ChangeSet } from \"./changeset\";\n\nexport { ChangeSet, Diff };\n\nexport function makeChangeSet(filePath: string, content: string, pattern: RegExp, expected?: string): ChangeSet {\n pattern.lastIndex = 0;\n const resultList = collectAll(pattern, content);\n const diffs = resultList.map((matches) => new Diff({ pattern, expected, index: matches.index, matches }));\n return new ChangeSet({ filePath, content, diffs });\n}\n"]}
|
package/lib/cli.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const yaml = require("js-yaml");
|
|
6
|
+
const diff = require("diff");
|
|
7
|
+
const _1 = require("./");
|
|
8
|
+
const content_1 = require("./utils/content");
|
|
9
|
+
const commander_1 = require("commander");
|
|
10
|
+
const pkg = require("../package.json");
|
|
11
|
+
const program = new commander_1.Command();
|
|
12
|
+
program
|
|
13
|
+
.name("prh")
|
|
13
14
|
.version(pkg.version, "-v, --version")
|
|
15
|
+
.argument("[files...]")
|
|
14
16
|
.option("--rules-json", "emit rule set in json format")
|
|
15
17
|
.option("--rules-yaml", "emit rule set in yaml format")
|
|
16
|
-
.option("--rules <path>", "path to rule yaml file")
|
|
18
|
+
.option("--rules <path>", "path to rule yaml file", (value, previous) => previous.concat([value]), [])
|
|
17
19
|
.option("--verify", "checking file validity")
|
|
18
20
|
.option("--stdout", "print replaced content to stdout")
|
|
19
21
|
.option("--diff", "show unified diff")
|
|
20
22
|
.option("--verbose", "makes output more verbose")
|
|
21
23
|
.option("-r, --replace", "replace input files")
|
|
22
|
-
.action(
|
|
24
|
+
.action((files, opts) => {
|
|
23
25
|
if (opts.rulesJson || opts.rulesYaml) {
|
|
24
26
|
if (opts.verbose) {
|
|
25
|
-
console.warn(
|
|
27
|
+
console.warn(`processing ${process.cwd()} dir...`);
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
const engine = getEngineByTargetDir(process.cwd(), opts);
|
|
28
30
|
if (opts.rulesJson) {
|
|
29
31
|
console.log(JSON.stringify(engine, null, 2));
|
|
30
32
|
return;
|
|
@@ -34,82 +36,80 @@ var root = commandpost
|
|
|
34
36
|
return;
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
|
-
if (
|
|
39
|
+
if (files.length === 0) {
|
|
38
40
|
throw new Error("files is required more than 1 argument");
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
const invalidFiles = [];
|
|
43
|
+
files.forEach((filePath) => {
|
|
42
44
|
if (opts.verbose) {
|
|
43
|
-
console.warn(
|
|
45
|
+
console.warn(`processing ${filePath}...`);
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
const content = fs.readFileSync(filePath, { encoding: "utf8" });
|
|
48
|
+
const engine = getEngineByTargetDir(path.dirname(filePath), opts);
|
|
49
|
+
const changeSet = engine.makeChangeSet(filePath);
|
|
48
50
|
if (changeSet.diffs.length !== 0) {
|
|
49
51
|
invalidFiles.push(filePath);
|
|
50
52
|
}
|
|
51
53
|
if (opts.stdout) {
|
|
52
|
-
|
|
54
|
+
const result = changeSet.applyChangeSets(content);
|
|
53
55
|
process.stdout.write(result);
|
|
54
56
|
}
|
|
55
57
|
else if (opts.diff) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
const result = changeSet.applyChangeSets(content);
|
|
59
|
+
const patch = diff.createPatch(filePath, content, result, "before", "replaced");
|
|
58
60
|
console.log(patch);
|
|
59
61
|
}
|
|
60
62
|
else if (opts.replace) {
|
|
61
|
-
|
|
63
|
+
const result = changeSet.applyChangeSets(content);
|
|
62
64
|
if (content !== result) {
|
|
63
65
|
fs.writeFileSync(filePath, result);
|
|
64
|
-
console.warn(
|
|
66
|
+
console.warn(`replaced ${filePath}`);
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
else {
|
|
68
|
-
changeSet.diffs.forEach(
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
changeSet.diffs.forEach((d) => {
|
|
71
|
+
const before = changeSet.content.substr(d.index, d.tailIndex - d.index);
|
|
72
|
+
const after = d.newText;
|
|
71
73
|
if (after == null) {
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
|
-
|
|
75
|
-
console.log(changeSet.filePath
|
|
76
|
+
const lineColumn = (0, content_1.indexToLineColumn)(d.index, changeSet.content);
|
|
77
|
+
console.log(`${changeSet.filePath}(${lineColumn.line + 1},${lineColumn.column + 1}): ${before} → ${after}`);
|
|
76
78
|
});
|
|
77
79
|
}
|
|
78
80
|
});
|
|
79
81
|
if (opts.verify && invalidFiles.length !== 0) {
|
|
80
|
-
throw new Error(invalidFiles.join(" ,")
|
|
81
|
-
}
|
|
82
|
-
function getEngineByTargetDir(targetDir) {
|
|
83
|
-
var rulePaths;
|
|
84
|
-
if (opts.rules && opts.rules[0]) {
|
|
85
|
-
rulePaths = opts.rules.slice();
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
var foundPath = _1.getRuleFilePath(targetDir);
|
|
89
|
-
if (!foundPath) {
|
|
90
|
-
throw new Error("can't find rule file from " + targetDir);
|
|
91
|
-
}
|
|
92
|
-
rulePaths = [foundPath];
|
|
93
|
-
}
|
|
94
|
-
if (opts.verbose) {
|
|
95
|
-
rulePaths.forEach(function (path, i) {
|
|
96
|
-
console.warn(" apply " + (i + 1) + ": " + path);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return _1.fromYAMLFilePaths.apply(void 0, rulePaths);
|
|
82
|
+
throw new Error(`${invalidFiles.join(" ,")} failed proofreading`);
|
|
100
83
|
}
|
|
101
84
|
});
|
|
102
|
-
|
|
103
|
-
.
|
|
85
|
+
program
|
|
86
|
+
.command("init")
|
|
104
87
|
.description("generate prh.yml")
|
|
105
|
-
.action(
|
|
88
|
+
.action(() => {
|
|
106
89
|
fs.createReadStream(path.resolve(__dirname, "../misc/prh.yml")).pipe(fs.createWriteStream("prh.yml"));
|
|
107
90
|
console.log("create prh.yml");
|
|
108
91
|
console.log("see prh/rules collection https://github.com/prh/rules");
|
|
109
92
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.
|
|
93
|
+
function getEngineByTargetDir(targetDir, opts) {
|
|
94
|
+
let rulePaths;
|
|
95
|
+
if (opts.rules && opts.rules[0]) {
|
|
96
|
+
rulePaths = [...opts.rules];
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const foundPath = (0, _1.getRuleFilePath)(targetDir);
|
|
100
|
+
if (!foundPath) {
|
|
101
|
+
throw new Error(`can't find rule file from ${targetDir}`);
|
|
102
|
+
}
|
|
103
|
+
rulePaths = [foundPath];
|
|
104
|
+
}
|
|
105
|
+
if (opts.verbose) {
|
|
106
|
+
rulePaths.forEach((p, i) => {
|
|
107
|
+
console.warn(` apply ${i + 1}: ${p}`);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return (0, _1.fromYAMLFilePaths)(...rulePaths);
|
|
111
|
+
}
|
|
112
|
+
program.parseAsync(process.argv).catch(errorHandler);
|
|
113
113
|
function errorHandler(err) {
|
|
114
114
|
if (err instanceof Error) {
|
|
115
115
|
console.error(err.stack);
|
|
@@ -117,7 +117,7 @@ function errorHandler(err) {
|
|
|
117
117
|
else {
|
|
118
118
|
console.error(err);
|
|
119
119
|
}
|
|
120
|
-
return Promise.resolve(null).then(
|
|
120
|
+
return Promise.resolve(null).then(() => {
|
|
121
121
|
process.exit(1);
|
|
122
122
|
});
|
|
123
123
|
}
|