wikilint 1.1.0 → 2.0.0-beta.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/README.md +2 -1
- package/config/.schema.json +33 -0
- package/config/default.json +1 -0
- package/config/llwiki.json +1 -0
- package/config/minimum.json +136 -0
- package/config/moegirl.json +1 -0
- package/config/zhwiki.json +1 -0
- package/dist/bin/cli.js +133 -0
- package/dist/index.d.ts +50 -109
- package/dist/index.js +80 -0
- package/dist/internal.d.ts +44 -0
- package/dist/lib/element.d.ts +55 -20
- package/dist/lib/element.js +162 -0
- package/dist/lib/node.d.ts +54 -76
- package/dist/lib/node.js +160 -0
- package/dist/lib/text.d.ts +30 -22
- package/dist/lib/text.js +118 -0
- package/dist/lib/title.d.ts +15 -10
- package/dist/lib/title.js +60 -0
- package/dist/mixin/hidden.js +21 -0
- package/dist/parser/braces.js +119 -0
- package/dist/parser/commentAndExt.js +63 -0
- package/dist/parser/converter.js +38 -0
- package/dist/parser/externalLinks.js +26 -0
- package/dist/parser/hrAndDoubleUnderscore.js +36 -0
- package/dist/parser/html.js +34 -0
- package/dist/parser/links.js +92 -0
- package/dist/parser/list.js +57 -0
- package/dist/parser/magicLinks.js +38 -0
- package/dist/parser/quotes.js +65 -0
- package/dist/parser/table.js +107 -0
- package/dist/src/arg.d.ts +24 -14
- package/dist/src/arg.js +91 -0
- package/dist/src/atom.d.ts +10 -0
- package/dist/src/atom.js +14 -0
- package/dist/src/attribute.d.ts +49 -30
- package/dist/src/attribute.js +273 -0
- package/dist/src/attributes.d.ts +31 -22
- package/dist/src/attributes.js +126 -0
- package/dist/src/converter.d.ts +18 -16
- package/dist/src/converter.js +57 -0
- package/dist/src/converterFlags.d.ts +33 -15
- package/dist/src/converterFlags.js +84 -0
- package/dist/src/converterRule.d.ts +22 -17
- package/dist/src/converterRule.js +67 -0
- package/dist/src/extLink.d.ts +22 -12
- package/dist/src/extLink.js +58 -0
- package/dist/src/gallery.d.ts +28 -11
- package/dist/src/gallery.js +84 -0
- package/dist/src/heading.d.ts +27 -13
- package/dist/src/heading.js +89 -0
- package/dist/src/hidden.d.ts +15 -0
- package/dist/src/hidden.js +11 -0
- package/dist/src/html.d.ts +33 -18
- package/dist/src/html.js +141 -0
- package/dist/src/imageParameter.d.ts +31 -22
- package/dist/src/imageParameter.js +130 -0
- package/dist/src/imagemap.d.ts +32 -15
- package/dist/src/imagemap.js +115 -0
- package/dist/src/imagemapLink.d.ts +18 -9
- package/dist/src/imagemapLink.js +29 -0
- package/dist/src/index.d.ts +31 -40
- package/dist/src/index.js +370 -0
- package/dist/src/link/base.d.ts +37 -0
- package/dist/src/link/base.js +104 -0
- package/dist/src/link/category.d.ts +5 -7
- package/dist/src/link/category.js +11 -0
- package/dist/src/link/file.d.ts +38 -11
- package/dist/src/link/file.js +144 -0
- package/dist/src/link/galleryImage.d.ts +18 -12
- package/dist/src/link/galleryImage.js +53 -0
- package/dist/src/link/index.d.ts +6 -29
- package/dist/src/link/index.js +14 -0
- package/dist/src/magicLink.d.ts +12 -10
- package/dist/src/magicLink.js +51 -0
- package/dist/src/nested.d.ts +33 -0
- package/dist/src/nested.js +62 -0
- package/dist/src/nowiki/base.d.ts +14 -0
- package/dist/src/nowiki/base.js +11 -0
- package/dist/src/nowiki/comment.d.ts +28 -13
- package/dist/src/nowiki/comment.js +41 -0
- package/dist/src/nowiki/dd.d.ts +5 -7
- package/dist/src/nowiki/dd.js +11 -0
- package/dist/src/nowiki/doubleUnderscore.d.ts +16 -8
- package/dist/src/nowiki/doubleUnderscore.js +23 -0
- package/dist/src/nowiki/hr.d.ts +5 -12
- package/dist/src/nowiki/hr.js +11 -0
- package/dist/src/nowiki/index.d.ts +13 -14
- package/dist/src/nowiki/index.js +23 -0
- package/dist/src/nowiki/list.d.ts +5 -7
- package/dist/src/nowiki/list.js +11 -0
- package/dist/src/nowiki/noinclude.d.ts +14 -7
- package/dist/src/nowiki/noinclude.js +12 -0
- package/dist/src/nowiki/quote.d.ts +8 -16
- package/dist/src/nowiki/quote.js +46 -0
- package/dist/src/onlyinclude.d.ts +14 -7
- package/dist/src/onlyinclude.js +34 -0
- package/dist/src/paramTag/index.d.ts +25 -12
- package/dist/src/paramTag/index.js +56 -0
- package/dist/src/paramTag/inputbox.d.ts +7 -7
- package/dist/src/paramTag/inputbox.js +19 -0
- package/dist/src/parameter.d.ts +28 -16
- package/dist/src/parameter.js +86 -0
- package/dist/src/pre.d.ts +21 -0
- package/dist/src/pre.js +37 -0
- package/dist/src/syntax.d.ts +11 -12
- package/dist/src/syntax.js +20 -0
- package/dist/src/table/base.d.ts +21 -0
- package/dist/src/table/base.js +24 -0
- package/dist/src/table/index.d.ts +29 -6
- package/dist/src/table/index.js +59 -0
- package/dist/src/table/td.d.ts +36 -22
- package/dist/src/table/td.js +100 -0
- package/dist/src/table/tr.d.ts +15 -15
- package/dist/src/table/tr.js +23 -0
- package/dist/src/table/trBase.d.ts +23 -0
- package/dist/src/table/trBase.js +48 -0
- package/dist/src/tagPair/ext.d.ts +19 -13
- package/dist/src/tagPair/ext.js +122 -0
- package/dist/src/tagPair/include.d.ts +28 -10
- package/dist/src/tagPair/include.js +25 -0
- package/dist/src/tagPair/index.d.ts +25 -18
- package/dist/src/tagPair/index.js +67 -0
- package/dist/src/transclude.d.ts +49 -39
- package/dist/src/transclude.js +304 -0
- package/dist/util/diff.js +71 -0
- package/dist/util/lint.js +46 -0
- package/dist/util/string.js +41 -0
- package/errors/README +1 -0
- package/i18n/zh-hans.json +46 -0
- package/i18n/zh-hant.json +46 -0
- package/package.json +29 -27
- package/bin/cli.js +0 -143
- package/dist/mixin/hidden.d.ts +0 -8
- package/dist/parser/brackets.d.ts +0 -12
- package/dist/parser/commentAndExt.d.ts +0 -8
- package/dist/parser/converter.d.ts +0 -7
- package/dist/parser/externalLinks.d.ts +0 -7
- package/dist/parser/hrAndDoubleUnderscore.d.ts +0 -11
- package/dist/parser/html.d.ts +0 -7
- package/dist/parser/links.d.ts +0 -7
- package/dist/parser/list.d.ts +0 -7
- package/dist/parser/magicLinks.d.ts +0 -7
- package/dist/parser/quotes.d.ts +0 -7
- package/dist/parser/table.d.ts +0 -11
- package/dist/src/atom/hidden.d.ts +0 -5
- package/dist/src/atom/index.d.ts +0 -14
- package/dist/src/hasNowiki/index.d.ts +0 -14
- package/dist/src/hasNowiki/pre.d.ts +0 -13
- package/dist/src/nested/choose.d.ts +0 -13
- package/dist/src/nested/combobox.d.ts +0 -13
- package/dist/src/nested/index.d.ts +0 -20
- package/dist/src/nested/references.d.ts +0 -13
- package/dist/util/lint.d.ts +0 -28
- package/dist/util/string.d.ts +0 -31
- package/index.js +0 -76
- package/lib/element.js +0 -115
- package/lib/node.js +0 -231
- package/lib/text.js +0 -168
- package/lib/title.js +0 -56
- package/mixin/hidden.js +0 -18
- package/parser/brackets.js +0 -127
- package/parser/commentAndExt.js +0 -61
- package/parser/converter.js +0 -45
- package/parser/externalLinks.js +0 -32
- package/parser/hrAndDoubleUnderscore.js +0 -48
- package/parser/html.js +0 -41
- package/parser/links.js +0 -98
- package/parser/list.js +0 -58
- package/parser/magicLinks.js +0 -40
- package/parser/quotes.js +0 -63
- package/parser/table.js +0 -113
- package/src/arg.js +0 -93
- package/src/atom/hidden.js +0 -11
- package/src/atom/index.js +0 -26
- package/src/attribute.js +0 -286
- package/src/attributes.js +0 -147
- package/src/converter.js +0 -70
- package/src/converterFlags.js +0 -97
- package/src/converterRule.js +0 -74
- package/src/extLink.js +0 -60
- package/src/gallery.js +0 -94
- package/src/hasNowiki/index.js +0 -32
- package/src/hasNowiki/pre.js +0 -28
- package/src/heading.js +0 -83
- package/src/html.js +0 -130
- package/src/imageParameter.js +0 -141
- package/src/imagemap.js +0 -140
- package/src/imagemapLink.js +0 -29
- package/src/index.js +0 -413
- package/src/link/category.js +0 -13
- package/src/link/file.js +0 -132
- package/src/link/galleryImage.js +0 -62
- package/src/link/index.js +0 -119
- package/src/magicLink.js +0 -67
- package/src/nested/choose.js +0 -23
- package/src/nested/combobox.js +0 -22
- package/src/nested/index.js +0 -69
- package/src/nested/references.js +0 -22
- package/src/nowiki/comment.js +0 -47
- package/src/nowiki/dd.js +0 -13
- package/src/nowiki/doubleUnderscore.js +0 -26
- package/src/nowiki/hr.js +0 -22
- package/src/nowiki/index.js +0 -34
- package/src/nowiki/list.js +0 -13
- package/src/nowiki/noinclude.js +0 -14
- package/src/nowiki/quote.js +0 -51
- package/src/onlyinclude.js +0 -39
- package/src/paramTag/index.js +0 -66
- package/src/paramTag/inputbox.js +0 -32
- package/src/parameter.js +0 -96
- package/src/syntax.js +0 -23
- package/src/table/index.js +0 -45
- package/src/table/td.js +0 -118
- package/src/table/tr.js +0 -73
- package/src/tagPair/ext.js +0 -126
- package/src/tagPair/include.js +0 -26
- package/src/tagPair/index.js +0 -77
- package/src/transclude.js +0 -336
- package/typings/api.d.ts +0 -9
- package/typings/index.d.ts +0 -50
- package/typings/node.d.ts +0 -16
- package/typings/parser.d.ts +0 -5
- package/typings/token.d.ts +0 -28
- package/util/base.js +0 -17
- package/util/diff.js +0 -76
- package/util/lint.js +0 -55
- package/util/string.js +0 -75
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ npx wikilint --config zhwiki --include *.wiki
|
|
|
17
17
|
| `-c`, `--config` \<path or preset config\> | Choose parser's configuration | `default` |
|
|
18
18
|
| `-h`, `--help` | Print available options | |
|
|
19
19
|
| `-i`, `--include` | Parse for inclusion | no inclusion |
|
|
20
|
+
| `-l`, `--lang` | Choose i18n language | English
|
|
20
21
|
| `-q`, `--quiet` | Report errors only | errors and warnings |
|
|
21
|
-
| `-s`, `--strict` | Exit
|
|
22
|
+
| `-s`, `--strict` | Exit when there is an error or warning<br>Override `-q` or `--quiet` | Exit `1` only where there is an error |
|
|
22
23
|
| `-v`, `--version` | Print package version | |
|
package/config/.schema.json
CHANGED
|
@@ -95,6 +95,12 @@
|
|
|
95
95
|
"type": "string",
|
|
96
96
|
"pattern": "^[a-z:/]+(?:\\|[a-z:/]+)*$"
|
|
97
97
|
},
|
|
98
|
+
"interwiki": {
|
|
99
|
+
"type": "array",
|
|
100
|
+
"items": {
|
|
101
|
+
"type": "string"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
98
104
|
"img": {
|
|
99
105
|
"description": "image-related magic words",
|
|
100
106
|
"type": "object",
|
|
@@ -110,6 +116,32 @@
|
|
|
110
116
|
"type": "string",
|
|
111
117
|
"pattern": "^[-a-z]+$"
|
|
112
118
|
}
|
|
119
|
+
},
|
|
120
|
+
"conversionTable": {
|
|
121
|
+
"description": "table of unidirectional conversions",
|
|
122
|
+
"type": "array",
|
|
123
|
+
"items": {
|
|
124
|
+
"type": "array",
|
|
125
|
+
"items": {
|
|
126
|
+
"type": "string",
|
|
127
|
+
"pattern": "^[^ <>[\\]{}|]+$"
|
|
128
|
+
},
|
|
129
|
+
"minItems": 2,
|
|
130
|
+
"maxItems": 2
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
"redirects": {
|
|
134
|
+
"description": "table of redirects",
|
|
135
|
+
"type": "array",
|
|
136
|
+
"items": {
|
|
137
|
+
"type": "array",
|
|
138
|
+
"items": {
|
|
139
|
+
"type": "string",
|
|
140
|
+
"pattern": "^[^ <>[\\]{}|]+$"
|
|
141
|
+
},
|
|
142
|
+
"minItems": 2,
|
|
143
|
+
"maxItems": 2
|
|
144
|
+
}
|
|
113
145
|
}
|
|
114
146
|
},
|
|
115
147
|
"required": [
|
|
@@ -120,6 +152,7 @@
|
|
|
120
152
|
"parserFunction",
|
|
121
153
|
"doubleUnderscore",
|
|
122
154
|
"protocol",
|
|
155
|
+
"interwiki",
|
|
123
156
|
"img",
|
|
124
157
|
"variants"
|
|
125
158
|
],
|
package/config/default.json
CHANGED
|
@@ -754,6 +754,7 @@
|
|
|
754
754
|
]
|
|
755
755
|
],
|
|
756
756
|
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
|
|
757
|
+
"interwiki": [],
|
|
757
758
|
"img": {
|
|
758
759
|
"thumbnail": "thumbnail",
|
|
759
760
|
"thumb": "thumbnail",
|
package/config/llwiki.json
CHANGED
|
@@ -518,6 +518,7 @@
|
|
|
518
518
|
]
|
|
519
519
|
],
|
|
520
520
|
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
|
|
521
|
+
"interwiki": [],
|
|
521
522
|
"img": {
|
|
522
523
|
"thumbnail": "thumbnail",
|
|
523
524
|
"thumb": "thumbnail",
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
{
|
|
2
|
+
"ext": [],
|
|
3
|
+
"html": [
|
|
4
|
+
[
|
|
5
|
+
"b",
|
|
6
|
+
"bdi",
|
|
7
|
+
"del",
|
|
8
|
+
"i",
|
|
9
|
+
"ins",
|
|
10
|
+
"u",
|
|
11
|
+
"font",
|
|
12
|
+
"big",
|
|
13
|
+
"small",
|
|
14
|
+
"sub",
|
|
15
|
+
"sup",
|
|
16
|
+
"h1",
|
|
17
|
+
"h2",
|
|
18
|
+
"h3",
|
|
19
|
+
"h4",
|
|
20
|
+
"h5",
|
|
21
|
+
"h6",
|
|
22
|
+
"cite",
|
|
23
|
+
"code",
|
|
24
|
+
"em",
|
|
25
|
+
"s",
|
|
26
|
+
"strike",
|
|
27
|
+
"strong",
|
|
28
|
+
"tt",
|
|
29
|
+
"var",
|
|
30
|
+
"div",
|
|
31
|
+
"center",
|
|
32
|
+
"blockquote",
|
|
33
|
+
"ol",
|
|
34
|
+
"ul",
|
|
35
|
+
"dl",
|
|
36
|
+
"table",
|
|
37
|
+
"caption",
|
|
38
|
+
"pre",
|
|
39
|
+
"ruby",
|
|
40
|
+
"rb",
|
|
41
|
+
"rp",
|
|
42
|
+
"rt",
|
|
43
|
+
"rtc",
|
|
44
|
+
"p",
|
|
45
|
+
"span",
|
|
46
|
+
"abbr",
|
|
47
|
+
"dfn",
|
|
48
|
+
"kbd",
|
|
49
|
+
"samp",
|
|
50
|
+
"data",
|
|
51
|
+
"time",
|
|
52
|
+
"mark",
|
|
53
|
+
"tr",
|
|
54
|
+
"td",
|
|
55
|
+
"th",
|
|
56
|
+
"q",
|
|
57
|
+
"bdo"
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
"li",
|
|
61
|
+
"dt",
|
|
62
|
+
"dd"
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"br",
|
|
66
|
+
"wbr",
|
|
67
|
+
"hr",
|
|
68
|
+
"meta",
|
|
69
|
+
"link",
|
|
70
|
+
"img"
|
|
71
|
+
]
|
|
72
|
+
],
|
|
73
|
+
"namespaces": {
|
|
74
|
+
"6": "File",
|
|
75
|
+
"10": "Template"
|
|
76
|
+
},
|
|
77
|
+
"nsid": {},
|
|
78
|
+
"parserFunction": [
|
|
79
|
+
{
|
|
80
|
+
"#language": "language",
|
|
81
|
+
"#special": "special",
|
|
82
|
+
"#speciale": "speciale",
|
|
83
|
+
"#tag": "tag",
|
|
84
|
+
"#formatdate": "formatdate",
|
|
85
|
+
"#invoke": "invoke",
|
|
86
|
+
"#while": "while",
|
|
87
|
+
"#dowhile": "dowhile",
|
|
88
|
+
"#loop": "loop",
|
|
89
|
+
"#forargs": "forargs",
|
|
90
|
+
"#fornumargs": "fornumargs",
|
|
91
|
+
"#if": "if",
|
|
92
|
+
"#ifeq": "ifeq",
|
|
93
|
+
"#switch": "switch",
|
|
94
|
+
"#ifexist": "ifexist",
|
|
95
|
+
"#ifexpr": "ifexpr",
|
|
96
|
+
"#iferror": "iferror",
|
|
97
|
+
"#time": "time",
|
|
98
|
+
"#timel": "timel",
|
|
99
|
+
"#expr": "expr",
|
|
100
|
+
"#rel2abs": "rel2abs",
|
|
101
|
+
"#titleparts": "titleparts",
|
|
102
|
+
"#categorytree": "categorytree",
|
|
103
|
+
"#urldecode": "urldecode",
|
|
104
|
+
"#choose": "choose",
|
|
105
|
+
"#var": "var",
|
|
106
|
+
"#varexists": "varexists",
|
|
107
|
+
"#var_final": "var_final",
|
|
108
|
+
"#vardefine": "vardefine",
|
|
109
|
+
"#vardefineecho": "vardefineecho",
|
|
110
|
+
"#widget": "widget",
|
|
111
|
+
"#regex": "regex",
|
|
112
|
+
"#related": "related",
|
|
113
|
+
"#cscore": "cscore"
|
|
114
|
+
},
|
|
115
|
+
[],
|
|
116
|
+
[
|
|
117
|
+
"msg",
|
|
118
|
+
"原始",
|
|
119
|
+
"raw"
|
|
120
|
+
],
|
|
121
|
+
[
|
|
122
|
+
"替代",
|
|
123
|
+
"subst",
|
|
124
|
+
"安全替代",
|
|
125
|
+
"safesubst"
|
|
126
|
+
]
|
|
127
|
+
],
|
|
128
|
+
"doubleUnderscore": [
|
|
129
|
+
[],
|
|
130
|
+
[]
|
|
131
|
+
],
|
|
132
|
+
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
|
|
133
|
+
"interwiki": [],
|
|
134
|
+
"img": {},
|
|
135
|
+
"variants": []
|
|
136
|
+
}
|
package/config/moegirl.json
CHANGED
|
@@ -611,6 +611,7 @@
|
|
|
611
611
|
]
|
|
612
612
|
],
|
|
613
613
|
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
|
|
614
|
+
"interwiki": [],
|
|
614
615
|
"img": {
|
|
615
616
|
"thumbnail": "thumbnail",
|
|
616
617
|
"thumb": "thumbnail",
|
package/config/zhwiki.json
CHANGED
|
@@ -708,6 +708,7 @@
|
|
|
708
708
|
]
|
|
709
709
|
],
|
|
710
710
|
"protocol": "bitcoin:|ftp://|ftps://|geo:|git://|gopher://|http://|https://|irc://|ircs://|magnet:|mailto:|mms://|news:|nntp://|redis://|sftp://|sip:|sips:|sms:|ssh://|svn://|tel:|telnet://|urn:|worldwind://|xmpp:",
|
|
711
|
+
"interwiki": [],
|
|
711
712
|
"img": {
|
|
712
713
|
"thumbnail": "thumbnail",
|
|
713
714
|
"thumb": "thumbnail",
|
package/dist/bin/cli.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable n/no-process-exit */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const Parser = require("../index");
|
|
7
|
+
const man = `
|
|
8
|
+
Available options:
|
|
9
|
+
-c, --config <path or preset config> Choose parser's configuration
|
|
10
|
+
-h, --help Print available options
|
|
11
|
+
-i, --include Parse for inclusion
|
|
12
|
+
-l, --lang Choose i18n language
|
|
13
|
+
-q, --quiet Report errors only
|
|
14
|
+
-s, --strict Exit when there is an error or warning
|
|
15
|
+
Override -q or --quiet
|
|
16
|
+
-v, --version Print package version
|
|
17
|
+
`, preset = new Set(['default', 'zhwiki', 'moegirl', 'llwiki']), { argv } = process, files = [];
|
|
18
|
+
let include = false, quiet = false, strict = false, exit = false, nErr = 0, nWarn = 0, option, config, lang;
|
|
19
|
+
/**
|
|
20
|
+
* throw if `-c` or `--config` option is incorrect
|
|
21
|
+
* @throws `Error` unrecognized config input
|
|
22
|
+
*/
|
|
23
|
+
const throwOnConfig = () => {
|
|
24
|
+
if (!config || config.startsWith('-')) {
|
|
25
|
+
throw new Error('The option -c/--config must be followed by a path or a preset config');
|
|
26
|
+
}
|
|
27
|
+
else if (!config.includes('/') && !preset.has(config)) {
|
|
28
|
+
throw new Error(`Unrecognized preset config: ${config}`);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* generate plural form if necessary
|
|
33
|
+
* @param n number of items
|
|
34
|
+
* @param word item name
|
|
35
|
+
*/
|
|
36
|
+
const plural = (n, word) => `${n} ${word}${n > 1 ? 's' : ''}`;
|
|
37
|
+
/**
|
|
38
|
+
* color the severity
|
|
39
|
+
* @param severity problem severity
|
|
40
|
+
*/
|
|
41
|
+
const coloredSeverity = (severity) => `\x1B[${severity === 'error' ? 31 : 33}m${severity}\x1B[0m`.padEnd(16);
|
|
42
|
+
for (let i = 2; i < argv.length; i++) {
|
|
43
|
+
option = argv[i];
|
|
44
|
+
switch (option) {
|
|
45
|
+
case '-c':
|
|
46
|
+
case '--config':
|
|
47
|
+
config = argv[++i];
|
|
48
|
+
throwOnConfig();
|
|
49
|
+
break;
|
|
50
|
+
case '-h':
|
|
51
|
+
case '--help':
|
|
52
|
+
console.log(man);
|
|
53
|
+
process.exit(0);
|
|
54
|
+
break;
|
|
55
|
+
case '-i':
|
|
56
|
+
case '--include':
|
|
57
|
+
include = true;
|
|
58
|
+
break;
|
|
59
|
+
case '-l':
|
|
60
|
+
case '--lang':
|
|
61
|
+
lang = argv[++i];
|
|
62
|
+
break;
|
|
63
|
+
case '-q':
|
|
64
|
+
case '--quiet':
|
|
65
|
+
quiet = true;
|
|
66
|
+
break;
|
|
67
|
+
case '-s':
|
|
68
|
+
case '--strict':
|
|
69
|
+
strict = true;
|
|
70
|
+
break;
|
|
71
|
+
case '-v':
|
|
72
|
+
case '--version': {
|
|
73
|
+
const { version } = require('../../package');
|
|
74
|
+
console.log(`wikilint v${version}`);
|
|
75
|
+
process.exit(0);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
if (option.startsWith('--config=')) {
|
|
80
|
+
config = option.slice(9);
|
|
81
|
+
throwOnConfig();
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
else if (option.startsWith('--lang=')) {
|
|
85
|
+
lang = option.slice(7);
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
else if (option.startsWith('-')) {
|
|
89
|
+
throw new Error(`Unknown wikilint option: ${option}\n${man}`);
|
|
90
|
+
}
|
|
91
|
+
files.push(option);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (files.length === 0) {
|
|
95
|
+
throw new Error('No target file is specified');
|
|
96
|
+
}
|
|
97
|
+
else if (config) {
|
|
98
|
+
Parser.config = config.includes('/') ? (0, path_1.resolve)(config) : `./config/${config}`;
|
|
99
|
+
}
|
|
100
|
+
if (lang) {
|
|
101
|
+
Parser.i18n = lang;
|
|
102
|
+
}
|
|
103
|
+
if (quiet && strict) {
|
|
104
|
+
quiet = false;
|
|
105
|
+
console.error('-s or --strict will override -q or --quiet\n');
|
|
106
|
+
}
|
|
107
|
+
for (const file of files) {
|
|
108
|
+
const wikitext = (0, fs_1.readFileSync)(file, 'utf8');
|
|
109
|
+
let problems = Parser.parse(wikitext, include).lint();
|
|
110
|
+
const errors = problems.filter(({ severity }) => severity === 'error'), { length: nLocalErr } = errors, nLocalWarn = problems.length - nLocalErr;
|
|
111
|
+
if (quiet) {
|
|
112
|
+
problems = errors;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
nWarn += nLocalWarn;
|
|
116
|
+
}
|
|
117
|
+
if (problems.length > 0) {
|
|
118
|
+
console.error('\x1B[4m%s\x1B[0m', (0, path_1.resolve)(file));
|
|
119
|
+
const { length: maxLineChars } = String(Math.max(...problems.map(({ startLine }) => startLine))), { length: maxColChars } = String(Math.max(...problems.map(({ startCol }) => startCol)));
|
|
120
|
+
for (const { message, severity, startLine, startCol } of problems) {
|
|
121
|
+
console.error(` ${String(startLine).padStart(maxLineChars)}:${String(startCol).padEnd(maxColChars)} ${coloredSeverity(severity)} ${message}`);
|
|
122
|
+
}
|
|
123
|
+
console.error();
|
|
124
|
+
}
|
|
125
|
+
nErr += nLocalErr;
|
|
126
|
+
exit ||= Boolean(nLocalErr || strict && nLocalWarn);
|
|
127
|
+
}
|
|
128
|
+
if (nErr || nWarn) {
|
|
129
|
+
console.error('\x1B[1;31m%s\x1B[0m\n', `✖ ${plural(nErr + nWarn, 'problem')} (${plural(nErr, 'error')}, ${plural(nWarn, 'warning')})`);
|
|
130
|
+
}
|
|
131
|
+
if (exit) {
|
|
132
|
+
process.exitCode = 1;
|
|
133
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,110 +1,51 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
import TagPairToken = require("./src/tagPair/index.js")
|
|
51
|
-
import TranscludeToken = require("./src/transclude.js")
|
|
52
|
-
|
|
1
|
+
import type { Title } from './lib/title';
|
|
2
|
+
import type { Token } from './internal';
|
|
3
|
+
export interface Config {
|
|
4
|
+
ext: string[];
|
|
5
|
+
html: [string[], string[], string[]];
|
|
6
|
+
namespaces: Record<string, string>;
|
|
7
|
+
nsid: Record<string, number>;
|
|
8
|
+
parserFunction: [Record<string, string>, string[], string[], string[]];
|
|
9
|
+
doubleUnderscore: [string[], string[]];
|
|
10
|
+
protocol: string;
|
|
11
|
+
img: Record<string, string>;
|
|
12
|
+
variants: string[];
|
|
13
|
+
excludes?: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface LintError {
|
|
16
|
+
message: string;
|
|
17
|
+
severity: 'error' | 'warning';
|
|
18
|
+
startIndex: number;
|
|
19
|
+
endIndex: number;
|
|
20
|
+
startLine: number;
|
|
21
|
+
startCol: number;
|
|
22
|
+
endLine: number;
|
|
23
|
+
endCol: number;
|
|
24
|
+
}
|
|
25
|
+
declare interface Parser {
|
|
26
|
+
/** @browser */
|
|
27
|
+
config: string | Config;
|
|
28
|
+
/** @browser */
|
|
29
|
+
i18n?: string | Record<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* 规范化页面标题
|
|
32
|
+
* @browser
|
|
33
|
+
* @param title 标题(含或不含命名空间前缀)
|
|
34
|
+
* @param defaultNs 命名空间
|
|
35
|
+
* @param include 是否嵌入
|
|
36
|
+
* @param halfParsed 是否是半解析状态
|
|
37
|
+
* @param decode 是否需要解码
|
|
38
|
+
* @param selfLink 是否允许selfLink
|
|
39
|
+
*/
|
|
40
|
+
normalizeTitle(title: string, defaultNs?: number, include?: boolean, config?: Config, halfParsed?: boolean, decode?: boolean, selfLink?: boolean): Title;
|
|
41
|
+
/**
|
|
42
|
+
* 解析wikitext
|
|
43
|
+
* @browser
|
|
44
|
+
* @param include 是否嵌入
|
|
45
|
+
* @param maxStage 最大解析层级
|
|
46
|
+
*/
|
|
47
|
+
parse(wikitext: string, include?: boolean, maxStage?: number, config?: Config): Token;
|
|
48
|
+
}
|
|
49
|
+
declare const Parser: Parser;
|
|
53
50
|
export = Parser;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
declare namespace Parser {
|
|
57
|
-
export {
|
|
58
|
-
AstElement,
|
|
59
|
-
AstNode,
|
|
60
|
-
AstText,
|
|
61
|
-
Title,
|
|
62
|
-
ArgToken,
|
|
63
|
-
HiddenToken,
|
|
64
|
-
AtomToken,
|
|
65
|
-
AttributeToken,
|
|
66
|
-
AttributesToken,
|
|
67
|
-
ConverterToken,
|
|
68
|
-
ConverterFlagsToken,
|
|
69
|
-
ConverterRuleToken,
|
|
70
|
-
ExtLinkToken,
|
|
71
|
-
GalleryToken,
|
|
72
|
-
HasNowikiToken,
|
|
73
|
-
PreToken,
|
|
74
|
-
HeadingToken,
|
|
75
|
-
HtmlToken,
|
|
76
|
-
ImageParameterToken,
|
|
77
|
-
ImagemapToken,
|
|
78
|
-
ImagemapLinkToken,
|
|
79
|
-
Token,
|
|
80
|
-
CategoryToken,
|
|
81
|
-
FileToken,
|
|
82
|
-
GalleryImageToken,
|
|
83
|
-
LinkToken,
|
|
84
|
-
MagicLinkToken,
|
|
85
|
-
ChooseToken,
|
|
86
|
-
ComboboxToken,
|
|
87
|
-
NestedToken,
|
|
88
|
-
ReferencesToken,
|
|
89
|
-
CommentToken,
|
|
90
|
-
DdToken,
|
|
91
|
-
DoubleUnderscoreToken,
|
|
92
|
-
HrToken,
|
|
93
|
-
NowikiToken,
|
|
94
|
-
ListToken,
|
|
95
|
-
NoincludeToken,
|
|
96
|
-
QuoteToken,
|
|
97
|
-
OnlyincludeToken,
|
|
98
|
-
ParamTagToken,
|
|
99
|
-
InputboxToken,
|
|
100
|
-
ParameterToken,
|
|
101
|
-
SyntaxToken,
|
|
102
|
-
TableToken,
|
|
103
|
-
TdToken,
|
|
104
|
-
TrToken,
|
|
105
|
-
ExtToken,
|
|
106
|
-
IncludeToken,
|
|
107
|
-
TagPairToken,
|
|
108
|
-
TranscludeToken,
|
|
109
|
-
}
|
|
110
|
-
}
|
|
51
|
+
export type * from './internal';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint n/exports-style: 0 */
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
/**
|
|
6
|
+
* 从根路径require
|
|
7
|
+
* @param file 文件名
|
|
8
|
+
* @param dir 子路径
|
|
9
|
+
*/
|
|
10
|
+
const rootRequire = (file, dir) => require(file.startsWith('/') ? file : `../${file.includes('/') ? '' : dir}${file}`);
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
12
|
+
const Parser = {
|
|
13
|
+
config: 'default',
|
|
14
|
+
MAX_STAGE: 11,
|
|
15
|
+
/** @implements */
|
|
16
|
+
getConfig() {
|
|
17
|
+
if (typeof this.config === 'string') {
|
|
18
|
+
this.config = rootRequire(this.config, 'config/');
|
|
19
|
+
return this.getConfig();
|
|
20
|
+
}
|
|
21
|
+
return { ...this.config, excludes: [] };
|
|
22
|
+
},
|
|
23
|
+
/** @implements */
|
|
24
|
+
msg(msg, arg = '') {
|
|
25
|
+
if (typeof this.i18n === 'string') {
|
|
26
|
+
this.i18n = rootRequire(this.i18n, 'i18n/');
|
|
27
|
+
return this.msg(msg, arg);
|
|
28
|
+
}
|
|
29
|
+
return (this.i18n?.[msg] ?? msg).replace('$1', arg);
|
|
30
|
+
},
|
|
31
|
+
/** @implements */
|
|
32
|
+
normalizeTitle(title, defaultNs = 0, include = false, config = Parser.getConfig(), halfParsed = false, decode = false, selfLink = false) {
|
|
33
|
+
const { Title } = require('./lib/title');
|
|
34
|
+
if (halfParsed) {
|
|
35
|
+
return new Title(title, defaultNs, config, decode, selfLink);
|
|
36
|
+
}
|
|
37
|
+
const { Token } = require('./src');
|
|
38
|
+
const token = this.run(() => new Token(title, config).parseOnce(0, include).parseOnce()), titleObj = new Title(String(token), defaultNs, config, decode, selfLink);
|
|
39
|
+
return titleObj;
|
|
40
|
+
},
|
|
41
|
+
/** @implements */
|
|
42
|
+
parse(wikitext, include, maxStage = Parser.MAX_STAGE, config = Parser.getConfig()) {
|
|
43
|
+
const { Token } = require('./src');
|
|
44
|
+
let token;
|
|
45
|
+
this.run(() => {
|
|
46
|
+
token = new Token(wikitext.replace(/[\0\x7F]/gu, ''), config);
|
|
47
|
+
try {
|
|
48
|
+
token.parse(maxStage, include);
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
if (e instanceof Error) {
|
|
52
|
+
const file = path.join(__dirname, '..', 'errors', new Date().toISOString()), stage = token.getAttribute('stage');
|
|
53
|
+
fs.writeFileSync(file, stage === this.MAX_STAGE ? wikitext : String(token));
|
|
54
|
+
fs.writeFileSync(`${file}.err`, e.stack);
|
|
55
|
+
fs.writeFileSync(`${file}.json`, JSON.stringify({
|
|
56
|
+
stage, include: token.getAttribute('include'), config: this.config,
|
|
57
|
+
}, null, '\t'));
|
|
58
|
+
}
|
|
59
|
+
throw e;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return token;
|
|
63
|
+
},
|
|
64
|
+
/** @implements */
|
|
65
|
+
run(callback) {
|
|
66
|
+
const result = callback();
|
|
67
|
+
return result;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
const def = {}, immutable = new Set(['MAX_STAGE']), enumerable = new Set(['config', 'normalizeTitle', 'parse']);
|
|
71
|
+
for (const key in Parser) {
|
|
72
|
+
if (immutable.has(key)) {
|
|
73
|
+
def[key] = { enumerable: false, writable: false };
|
|
74
|
+
}
|
|
75
|
+
else if (!enumerable.has(key)) {
|
|
76
|
+
def[key] = { enumerable: false };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
Object.defineProperties(Parser, def);
|
|
80
|
+
module.exports = Parser;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type { AstNodes, } from './lib/node';
|
|
2
|
+
export type * from './lib/text';
|
|
3
|
+
export type * from './src';
|
|
4
|
+
export type * from './src/onlyinclude';
|
|
5
|
+
export type * from './src/nowiki/noinclude';
|
|
6
|
+
export type * from './src/tagPair/include';
|
|
7
|
+
export type * from './src/nowiki/comment';
|
|
8
|
+
export type * from './src/atom';
|
|
9
|
+
export type { AttributeToken } from './src/attribute';
|
|
10
|
+
export type * from './src/attributes';
|
|
11
|
+
export type * from './src/tagPair/ext';
|
|
12
|
+
export type * from './src/hidden';
|
|
13
|
+
export type * from './src/arg';
|
|
14
|
+
export type * from './src/syntax';
|
|
15
|
+
export type * from './src/parameter';
|
|
16
|
+
export type * from './src/transclude';
|
|
17
|
+
export type * from './src/heading';
|
|
18
|
+
export type * from './src/html';
|
|
19
|
+
export type { TdToken } from './src/table/td';
|
|
20
|
+
export type * from './src/table/tr';
|
|
21
|
+
export type * from './src/table';
|
|
22
|
+
export type * from './src/nowiki/hr';
|
|
23
|
+
export type * from './src/nowiki/doubleUnderscore';
|
|
24
|
+
export type * from './src/link';
|
|
25
|
+
export type * from './src/link/category';
|
|
26
|
+
export type * from './src/imageParameter';
|
|
27
|
+
export type * from './src/link/file';
|
|
28
|
+
export type * from './src/link/galleryImage';
|
|
29
|
+
export type * from './src/nowiki/quote';
|
|
30
|
+
export type * from './src/magicLink';
|
|
31
|
+
export type * from './src/extLink';
|
|
32
|
+
export type * from './src/nowiki/dd';
|
|
33
|
+
export type * from './src/nowiki/list';
|
|
34
|
+
export type * from './src/converterFlags';
|
|
35
|
+
export type * from './src/converterRule';
|
|
36
|
+
export type * from './src/converter';
|
|
37
|
+
export type * from './src/nowiki';
|
|
38
|
+
export type * from './src/pre';
|
|
39
|
+
export type * from './src/paramTag';
|
|
40
|
+
export type * from './src/paramTag/inputbox';
|
|
41
|
+
export type * from './src/nested';
|
|
42
|
+
export type * from './src/gallery';
|
|
43
|
+
export type * from './src/imagemapLink';
|
|
44
|
+
export type * from './src/imagemap';
|