@nitpicker/analyze-textlint 0.4.1
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 +8 -0
- package/LICENSE +191 -0
- package/README.md +13 -0
- package/lib/index.d.ts +55 -0
- package/lib/index.js +256 -0
- package/lib/list-up.d.ts +1 -0
- package/lib/list-up.js +57 -0
- package/package.json +65 -0
- package/src/index.ts +317 -0
- package/src/list-up.ts +93 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## [0.4.1](https://github.com/d-zero-dev/nitpicker/compare/v0.4.0...v0.4.1) (2026-02-27)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @nitpicker/analyze-textlint
|
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2025 D-ZERO Co., Ltd.
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @nitpicker/analyze-textlint
|
|
2
|
+
|
|
3
|
+
textlint を使用した日本語テキスト校正プラグイン。
|
|
4
|
+
|
|
5
|
+
## 概要
|
|
6
|
+
|
|
7
|
+
各ページのテキストコンテンツに対して [textlint](https://textlint.github.io/) による日本語校正を実行し、表記ゆれ・文法上の問題を検出します。
|
|
8
|
+
|
|
9
|
+
このパッケージは [Nitpicker](../../README.md) モノレポの内部パッケージです。単体での利用は想定していません。
|
|
10
|
+
|
|
11
|
+
## ライセンス
|
|
12
|
+
|
|
13
|
+
Apache-2.0
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A textlint rule configuration map.
|
|
3
|
+
* Keys are rule identifiers; values are `true` (enable with defaults),
|
|
4
|
+
* `false` (disable), or a rule-specific options object.
|
|
5
|
+
*/
|
|
6
|
+
type Rule = Record<string, unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* Plugin options for the textlint text-proofreading analysis.
|
|
9
|
+
*/
|
|
10
|
+
type Options = {
|
|
11
|
+
/**
|
|
12
|
+
* Custom rule overrides merged on top of the default Japanese-oriented rule set.
|
|
13
|
+
* Set a rule to `false` to disable it; set to `true` or an options object to enable.
|
|
14
|
+
*/
|
|
15
|
+
rules?: Rule;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Analyze plugin that runs textlint Japanese text-proofreading rules
|
|
19
|
+
* against each page's HTML.
|
|
20
|
+
*
|
|
21
|
+
* The default rule set is heavily Japanese-oriented (mixed script detection,
|
|
22
|
+
* doubled particles, honorific misuse, etc.) because the primary use case
|
|
23
|
+
* is auditing Japanese corporate websites. Users can override or extend
|
|
24
|
+
* rules via the `rules` option.
|
|
25
|
+
*
|
|
26
|
+
* ## Lazy linter initialization
|
|
27
|
+
*
|
|
28
|
+
* Building the linter is expensive because it dynamically imports 20+
|
|
29
|
+
* rule packages (many of which are CJS and require interop resolution).
|
|
30
|
+
* The linter is therefore created lazily on the first `eachPage` call
|
|
31
|
+
* and the resulting promise is cached for all subsequent pages.
|
|
32
|
+
*
|
|
33
|
+
* This "lazy singleton" pattern (`linterPromise` variable) ensures:
|
|
34
|
+
* 1. Zero startup cost if textlint is configured but no pages match.
|
|
35
|
+
* 2. No duplicate initialization even under concurrent `eachPage` calls,
|
|
36
|
+
* because the same promise is shared (Promise deduplication).
|
|
37
|
+
* @example
|
|
38
|
+
* ```jsonc
|
|
39
|
+
* // nitpicker.config.json
|
|
40
|
+
* {
|
|
41
|
+
* "plugins": {
|
|
42
|
+
* "analyze": {
|
|
43
|
+
* "@nitpicker/analyze-textlint": {
|
|
44
|
+
* "rules": {
|
|
45
|
+
* "max-ten": { "max": 5 },
|
|
46
|
+
* "spellcheck-tech-word": false
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare const _default: import("@nitpicker/core").PluginFactory<Options, string>;
|
|
55
|
+
export default _default;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { definePlugin } from '@nitpicker/core';
|
|
2
|
+
import { createLinter } from 'textlint';
|
|
3
|
+
const defaultRules = {
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/textlint-ja/textlint-rule-no-nfd
|
|
6
|
+
*/
|
|
7
|
+
'no-nfd': true,
|
|
8
|
+
/**
|
|
9
|
+
* @see https://github.com/textlint-ja/textlint-rule-max-ten
|
|
10
|
+
*/
|
|
11
|
+
'max-ten': {
|
|
12
|
+
max: 3,
|
|
13
|
+
},
|
|
14
|
+
/**
|
|
15
|
+
* @see https://github.com/azu/textlint-rule-spellcheck-tech-word
|
|
16
|
+
*/
|
|
17
|
+
'spellcheck-tech-word': true,
|
|
18
|
+
/**
|
|
19
|
+
* @see https://github.com/azu/textlint-rule-web-plus-db
|
|
20
|
+
*/
|
|
21
|
+
'web-plus-db': true,
|
|
22
|
+
/**
|
|
23
|
+
* @see https://github.com/textlint-ja/textlint-rule-no-mix-dearu-desumasu
|
|
24
|
+
*/
|
|
25
|
+
// cspell:disable-next-line
|
|
26
|
+
'no-mix-dearu-desumasu': {
|
|
27
|
+
preferInHeader: '',
|
|
28
|
+
preferInBody: '',
|
|
29
|
+
preferInList: '',
|
|
30
|
+
strict: false,
|
|
31
|
+
},
|
|
32
|
+
/**
|
|
33
|
+
* @see https://github.com/textlint-ja/textlint-rule-no-doubled-joshi
|
|
34
|
+
*/
|
|
35
|
+
'no-doubled-joshi': true,
|
|
36
|
+
/**
|
|
37
|
+
* @see https://github.com/textlint-ja/textlint-rule-no-double-negative-ja
|
|
38
|
+
*/
|
|
39
|
+
'no-double-negative-ja': true,
|
|
40
|
+
/**
|
|
41
|
+
* @see https://github.com/textlint-ja/textlint-rule-no-hankaku-kana
|
|
42
|
+
*/
|
|
43
|
+
'no-hankaku-kana': true, // cspell:disable-line
|
|
44
|
+
/**
|
|
45
|
+
* @see https://github.com/textlint-ja/textlint-rule-ja-no-abusage
|
|
46
|
+
*/
|
|
47
|
+
'ja-no-abusage': true,
|
|
48
|
+
'no-mixed-zenkaku-and-hankaku-alphabet': true, // cspell:disable-line
|
|
49
|
+
'no-dropping-the-ra': true,
|
|
50
|
+
'no-doubled-conjunctive-particle-ga': true,
|
|
51
|
+
'no-doubled-conjunction': true,
|
|
52
|
+
'ja-no-mixed-period': true,
|
|
53
|
+
/**
|
|
54
|
+
* @see https://github.com/KeitaMoromizato/textlint-rule-max-appearence-count-of-words#readme
|
|
55
|
+
*/
|
|
56
|
+
'max-appearence-count-of-words': true, // cspell:disable-line
|
|
57
|
+
'ja-hiragana-keishikimeishi': true, // cspell:disable-line
|
|
58
|
+
'ja-hiragana-fukushi': true, // cspell:disable-line
|
|
59
|
+
'ja-hiragana-hojodoushi': true, // cspell:disable-line
|
|
60
|
+
'ja-unnatural-alphabet': true,
|
|
61
|
+
'@textlint-ja/textlint-rule-no-insert-dropping-sa': true,
|
|
62
|
+
'prefer-tari-tari': true, // cspell:disable-line
|
|
63
|
+
/**
|
|
64
|
+
* @see https://github.com/textlint-ja/textlint-rule-no-synonyms
|
|
65
|
+
*/
|
|
66
|
+
'@textlint-ja/no-synonyms': true,
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Mapping from short rule identifiers to their npm package names.
|
|
70
|
+
*
|
|
71
|
+
* Most textlint rules follow the convention `textlint-rule-{id}`, but some
|
|
72
|
+
* (especially scoped packages like `@textlint-ja/*`) deviate.
|
|
73
|
+
* This map provides explicit overrides so that `loadModule()` can
|
|
74
|
+
* dynamically import the correct package for each rule.
|
|
75
|
+
*/
|
|
76
|
+
const ruleImportMap = {
|
|
77
|
+
'no-nfd': 'textlint-rule-no-nfd',
|
|
78
|
+
'max-ten': 'textlint-rule-max-ten',
|
|
79
|
+
'spellcheck-tech-word': 'textlint-rule-spellcheck-tech-word',
|
|
80
|
+
'web-plus-db': 'textlint-rule-web-plus-db',
|
|
81
|
+
'no-mix-dearu-desumasu': 'textlint-rule-no-mix-dearu-desumasu',
|
|
82
|
+
'no-doubled-joshi': 'textlint-rule-no-doubled-joshi',
|
|
83
|
+
'no-double-negative-ja': 'textlint-rule-no-double-negative-ja',
|
|
84
|
+
'no-hankaku-kana': 'textlint-rule-no-hankaku-kana',
|
|
85
|
+
'ja-no-abusage': 'textlint-rule-ja-no-abusage',
|
|
86
|
+
'no-mixed-zenkaku-and-hankaku-alphabet': 'textlint-rule-no-mixed-zenkaku-and-hankaku-alphabet',
|
|
87
|
+
'no-dropping-the-ra': 'textlint-rule-no-dropping-the-ra',
|
|
88
|
+
'no-doubled-conjunctive-particle-ga': 'textlint-rule-no-doubled-conjunctive-particle-ga',
|
|
89
|
+
'no-doubled-conjunction': 'textlint-rule-no-doubled-conjunction',
|
|
90
|
+
'ja-no-mixed-period': 'textlint-rule-ja-no-mixed-period',
|
|
91
|
+
'max-appearence-count-of-words': 'textlint-rule-max-appearence-count-of-words',
|
|
92
|
+
'ja-hiragana-keishikimeishi': 'textlint-rule-ja-hiragana-keishikimeishi',
|
|
93
|
+
'ja-hiragana-fukushi': 'textlint-rule-ja-hiragana-fukushi',
|
|
94
|
+
'ja-hiragana-hojodoushi': 'textlint-rule-ja-hiragana-hojodoushi',
|
|
95
|
+
'ja-unnatural-alphabet': 'textlint-rule-ja-unnatural-alphabet',
|
|
96
|
+
'@textlint-ja/textlint-rule-no-insert-dropping-sa': '@textlint-ja/textlint-rule-no-insert-dropping-sa',
|
|
97
|
+
'prefer-tari-tari': 'textlint-rule-prefer-tari-tari',
|
|
98
|
+
'@textlint-ja/no-synonyms': '@textlint-ja/textlint-rule-no-synonyms',
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Dynamically imports a module and resolves CJS/ESM default-export interop.
|
|
102
|
+
*
|
|
103
|
+
* Many textlint rules are published as CommonJS modules. When imported
|
|
104
|
+
* via dynamic `import()` in an ESM context, Node wraps the CJS export
|
|
105
|
+
* in `{ default: ... }`. Some bundlers double-wrap this, producing
|
|
106
|
+
* `{ default: { default: actualExport } }`. The fallback chain
|
|
107
|
+
* `mod.default?.default ?? mod.default ?? mod` handles all three cases:
|
|
108
|
+
*
|
|
109
|
+
* 1. Double-wrapped CJS: `mod.default.default`
|
|
110
|
+
* 2. Single-wrapped CJS: `mod.default`
|
|
111
|
+
* 3. Native ESM: `mod` (no `.default` property)
|
|
112
|
+
* @param moduleName - The npm package name to import.
|
|
113
|
+
* @returns The resolved module export (typically a rule constructor).
|
|
114
|
+
*/
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
+
async function loadModule(moduleName) {
|
|
117
|
+
const mod = await import(moduleName);
|
|
118
|
+
// moduleInterop equivalent: handle default export for CJS/ESM interop
|
|
119
|
+
return mod.default?.default ?? mod.default ?? mod;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Constructs a textlint `Linter` instance with the given rule set.
|
|
123
|
+
*
|
|
124
|
+
* Rules are loaded dynamically via `loadModule()` to support the mix of
|
|
125
|
+
* CJS and ESM packages in the textlint ecosystem. The HTML plugin is
|
|
126
|
+
* always registered so that raw HTML can be linted directly without
|
|
127
|
+
* first converting to Markdown.
|
|
128
|
+
* @param rules - Merged rule configuration (defaults + user overrides).
|
|
129
|
+
* @returns A configured textlint `Linter` ready for `lintText()` calls.
|
|
130
|
+
*/
|
|
131
|
+
async function buildLinter(rules) {
|
|
132
|
+
const { TextlintKernelDescriptor } = await import('@textlint/kernel');
|
|
133
|
+
const ruleDescriptors = await Promise.all(Object.entries(rules)
|
|
134
|
+
.filter(([, value]) => value !== false)
|
|
135
|
+
.map(async ([ruleId, options]) => {
|
|
136
|
+
const moduleName = ruleImportMap[ruleId] ?? `textlint-rule-${ruleId}`;
|
|
137
|
+
const rule = await loadModule(moduleName);
|
|
138
|
+
return {
|
|
139
|
+
ruleId,
|
|
140
|
+
rule,
|
|
141
|
+
options: options === true ? {} : options,
|
|
142
|
+
};
|
|
143
|
+
}));
|
|
144
|
+
const htmlPlugin = await loadModule('textlint-plugin-html');
|
|
145
|
+
const descriptor = new TextlintKernelDescriptor({
|
|
146
|
+
rules: ruleDescriptors,
|
|
147
|
+
plugins: [
|
|
148
|
+
{
|
|
149
|
+
pluginId: 'html',
|
|
150
|
+
plugin: htmlPlugin,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
filterRules: [],
|
|
154
|
+
});
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
|
+
return createLinter({ descriptor: descriptor });
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Analyze plugin that runs textlint Japanese text-proofreading rules
|
|
160
|
+
* against each page's HTML.
|
|
161
|
+
*
|
|
162
|
+
* The default rule set is heavily Japanese-oriented (mixed script detection,
|
|
163
|
+
* doubled particles, honorific misuse, etc.) because the primary use case
|
|
164
|
+
* is auditing Japanese corporate websites. Users can override or extend
|
|
165
|
+
* rules via the `rules` option.
|
|
166
|
+
*
|
|
167
|
+
* ## Lazy linter initialization
|
|
168
|
+
*
|
|
169
|
+
* Building the linter is expensive because it dynamically imports 20+
|
|
170
|
+
* rule packages (many of which are CJS and require interop resolution).
|
|
171
|
+
* The linter is therefore created lazily on the first `eachPage` call
|
|
172
|
+
* and the resulting promise is cached for all subsequent pages.
|
|
173
|
+
*
|
|
174
|
+
* This "lazy singleton" pattern (`linterPromise` variable) ensures:
|
|
175
|
+
* 1. Zero startup cost if textlint is configured but no pages match.
|
|
176
|
+
* 2. No duplicate initialization even under concurrent `eachPage` calls,
|
|
177
|
+
* because the same promise is shared (Promise deduplication).
|
|
178
|
+
* @example
|
|
179
|
+
* ```jsonc
|
|
180
|
+
* // nitpicker.config.json
|
|
181
|
+
* {
|
|
182
|
+
* "plugins": {
|
|
183
|
+
* "analyze": {
|
|
184
|
+
* "@nitpicker/analyze-textlint": {
|
|
185
|
+
* "rules": {
|
|
186
|
+
* "max-ten": { "max": 5 },
|
|
187
|
+
* "spellcheck-tech-word": false
|
|
188
|
+
* }
|
|
189
|
+
* }
|
|
190
|
+
* }
|
|
191
|
+
* }
|
|
192
|
+
* }
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export default definePlugin((options) => {
|
|
196
|
+
const rules = { ...defaultRules, ...options.rules };
|
|
197
|
+
let linterPromise;
|
|
198
|
+
/**
|
|
199
|
+
* Returns a shared linter promise, creating it on first call.
|
|
200
|
+
* Subsequent calls return the same promise (lazy singleton pattern).
|
|
201
|
+
*/
|
|
202
|
+
function getLinter() {
|
|
203
|
+
if (!linterPromise) {
|
|
204
|
+
linterPromise = buildLinter(rules);
|
|
205
|
+
}
|
|
206
|
+
return linterPromise;
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
label: 'textlint: テキスト校正',
|
|
210
|
+
async eachPage({ html, url }) {
|
|
211
|
+
const linter = await getLinter();
|
|
212
|
+
const reports = [];
|
|
213
|
+
const result = await linter.lintText(html, url.pathname + '.html');
|
|
214
|
+
reports.push({
|
|
215
|
+
url: url.href,
|
|
216
|
+
results: result.messages,
|
|
217
|
+
});
|
|
218
|
+
const violations = reports.flatMap((report) => {
|
|
219
|
+
return report.results.map((r) => {
|
|
220
|
+
return {
|
|
221
|
+
validator: 'textlint',
|
|
222
|
+
severity: convertSeverity(r.severity),
|
|
223
|
+
rule: r.ruleId,
|
|
224
|
+
code: '-',
|
|
225
|
+
message: `${r.message}`,
|
|
226
|
+
url: `${report.url} (${r.line}:${r.column})`,
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
return {
|
|
231
|
+
violations,
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
/**
|
|
237
|
+
* Maps textlint's numeric severity levels to Nitpicker's string-based severity.
|
|
238
|
+
*
|
|
239
|
+
* textlint uses `1` for warning and `2` for error, following ESLint convention.
|
|
240
|
+
* Any unexpected value defaults to `"error"` for safety.
|
|
241
|
+
* @param severity - The textlint severity level (1 = warning, 2 = error).
|
|
242
|
+
* @returns The corresponding Nitpicker severity string.
|
|
243
|
+
*/
|
|
244
|
+
function convertSeverity(severity) {
|
|
245
|
+
switch (severity) {
|
|
246
|
+
case 1: {
|
|
247
|
+
return 'warning';
|
|
248
|
+
}
|
|
249
|
+
case 2: {
|
|
250
|
+
return 'error';
|
|
251
|
+
}
|
|
252
|
+
default: {
|
|
253
|
+
return 'error';
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
package/lib/list-up.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/list-up.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { glob } from 'glob';
|
|
4
|
+
import { JSDOM } from 'jsdom';
|
|
5
|
+
import { createLinter } from 'textlint';
|
|
6
|
+
import TurndownService from 'turndown';
|
|
7
|
+
const turndownService = new TurndownService();
|
|
8
|
+
const globPath = path.resolve(process.cwd(), '**', '*.html');
|
|
9
|
+
const files = await glob(globPath);
|
|
10
|
+
const pages = await Promise.all(files.map(async (filePath) => {
|
|
11
|
+
let html = await fs.readFile(filePath, { encoding: 'utf8' });
|
|
12
|
+
html = html.replaceAll(/\s+/g, ' ');
|
|
13
|
+
const md = turndownService.turndown(html);
|
|
14
|
+
const dom = new JSDOM(html);
|
|
15
|
+
const title = dom.window.document.title;
|
|
16
|
+
return `# ${title}\n\n${md}`;
|
|
17
|
+
}));
|
|
18
|
+
const rulesConfig = {
|
|
19
|
+
/**
|
|
20
|
+
* @see https://github.com/textlint-ja/textlint-rule-no-synonyms
|
|
21
|
+
*/
|
|
22
|
+
// '@textlint-ja/no-synonyms': true,
|
|
23
|
+
'ja-no-orthographic-variants': true,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Dynamically imports a module with CJS/ESM default-export interop.
|
|
27
|
+
* See `index.ts#loadModule` for the detailed interop explanation.
|
|
28
|
+
* @param moduleName - npm package name to import.
|
|
29
|
+
* @returns The resolved module export.
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
async function loadModule(moduleName) {
|
|
33
|
+
const mod = await import(moduleName);
|
|
34
|
+
return mod.default?.default ?? mod.default ?? mod;
|
|
35
|
+
}
|
|
36
|
+
const { TextlintKernelDescriptor } = await import('@textlint/kernel');
|
|
37
|
+
const ruleDescriptors = await Promise.all(Object.entries(rulesConfig)
|
|
38
|
+
.filter(([, value]) => value !== false)
|
|
39
|
+
.map(async ([ruleId, options]) => {
|
|
40
|
+
const rule = await loadModule(`textlint-rule-${ruleId}`);
|
|
41
|
+
return {
|
|
42
|
+
ruleId,
|
|
43
|
+
rule,
|
|
44
|
+
options: options === true ? {} : options,
|
|
45
|
+
};
|
|
46
|
+
}));
|
|
47
|
+
const descriptor = new TextlintKernelDescriptor({
|
|
48
|
+
rules: ruleDescriptors,
|
|
49
|
+
plugins: [],
|
|
50
|
+
filterRules: [],
|
|
51
|
+
});
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
const linter = createLinter({ descriptor: descriptor });
|
|
54
|
+
const result = await linter.lintText(pages.join('\n\n'), '.md');
|
|
55
|
+
const messages = result.messages.map((m) => m.message);
|
|
56
|
+
const resultSet = new Set(messages);
|
|
57
|
+
await fs.writeFile('result.txt', [...resultSet].join('\n'), { encoding: 'utf8' });
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nitpicker/analyze-textlint",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "Nitpicker plugin for Japanese text proofreading using textlint",
|
|
5
|
+
"author": "D-ZERO",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/d-zero-dev/nitpicker.git",
|
|
10
|
+
"directory": "packages/@nitpicker/analyze-textlint"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./lib/index.js",
|
|
19
|
+
"types": "./lib/index.d.ts"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"clean": "tsc --build --clean"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@nitpicker/core": "0.4.1",
|
|
28
|
+
"@nitpicker/types": "0.4.1",
|
|
29
|
+
"@textlint-ja/textlint-rule-no-insert-dropping-sa": "2.0.1",
|
|
30
|
+
"@textlint-ja/textlint-rule-no-synonyms": "1.3.0",
|
|
31
|
+
"@textlint/kernel": "15.5.2",
|
|
32
|
+
"jsdom": "28.1.0",
|
|
33
|
+
"sudachi-synonyms-dictionary": "17.0.0",
|
|
34
|
+
"textlint": "15.5.2",
|
|
35
|
+
"textlint-plugin-html": "1.0.1",
|
|
36
|
+
"textlint-rule-ja-hiragana-fukushi": "1.3.0",
|
|
37
|
+
"textlint-rule-ja-hiragana-hojodoushi": "1.1.0",
|
|
38
|
+
"textlint-rule-ja-hiragana-keishikimeishi": "1.1.0",
|
|
39
|
+
"textlint-rule-ja-no-abusage": "3.0.0",
|
|
40
|
+
"textlint-rule-ja-no-mixed-period": "3.0.2",
|
|
41
|
+
"textlint-rule-ja-unnatural-alphabet": "2.0.1",
|
|
42
|
+
"textlint-rule-max-appearence-count-of-words": "1.0.1",
|
|
43
|
+
"textlint-rule-max-ten": "5.0.0",
|
|
44
|
+
"textlint-rule-no-double-negative-ja": "2.0.1",
|
|
45
|
+
"textlint-rule-no-doubled-conjunction": "3.0.0",
|
|
46
|
+
"textlint-rule-no-doubled-conjunctive-particle-ga": "3.0.0",
|
|
47
|
+
"textlint-rule-no-doubled-joshi": "5.1.1",
|
|
48
|
+
"textlint-rule-no-dropping-the-ra": "3.0.0",
|
|
49
|
+
"textlint-rule-no-hankaku-kana": "2.0.1",
|
|
50
|
+
"textlint-rule-no-mix-dearu-desumasu": "6.0.4",
|
|
51
|
+
"textlint-rule-no-mixed-zenkaku-and-hankaku-alphabet": "1.0.1",
|
|
52
|
+
"textlint-rule-no-nfd": "2.0.2",
|
|
53
|
+
"textlint-rule-prefer-tari-tari": "1.0.3",
|
|
54
|
+
"textlint-rule-prh": "6.1.0",
|
|
55
|
+
"textlint-rule-spellcheck-tech-word": "5.0.0",
|
|
56
|
+
"textlint-rule-web-plus-db": "1.1.5",
|
|
57
|
+
"turndown": "7.2.2"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/jsdom": "28.0.0",
|
|
61
|
+
"@types/turndown": "5.0.6",
|
|
62
|
+
"glob": "13.0.6"
|
|
63
|
+
},
|
|
64
|
+
"gitHead": "32b83ee38eba7dfd237adb1b41f69e049e8d4ceb"
|
|
65
|
+
}
|