wikilint 2.1.6 → 2.3.0
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/dist/lib/text.js +3 -2
- package/dist/parser/links.js +1 -1
- package/dist/parser/table.js +1 -1
- package/dist/src/arg.js +3 -3
- package/dist/src/attribute.js +2 -2
- package/dist/src/converterFlags.js +1 -2
- package/dist/src/gallery.d.ts +5 -5
- package/dist/src/gallery.js +6 -8
- package/dist/src/parameter.js +1 -1
- package/dist/src/table/index.js +1 -2
- package/dist/src/tagPair/ext.js +1 -1
- package/dist/util/lint.js +4 -4
- package/package.json +2 -1
package/dist/lib/text.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AstText = void 0;
|
|
4
4
|
const Parser = require("../index");
|
|
5
5
|
const node_1 = require("./node");
|
|
6
|
-
const errorSyntax = /https
|
|
6
|
+
const errorSyntax = /https?[:/]\/+|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu, errorSyntaxUrl = /\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu, disallowedTags = [
|
|
7
7
|
'html',
|
|
8
8
|
'head',
|
|
9
9
|
'style',
|
|
@@ -54,6 +54,7 @@ class AstText extends node_1.AstNode {
|
|
|
54
54
|
lint(start = this.getAbsoluteIndex()) {
|
|
55
55
|
const { data, parentNode, nextSibling, previousSibling } = this;
|
|
56
56
|
const { type, name } = parentNode, nextType = nextSibling?.type, previousType = previousSibling?.type, errorRegex = type === 'free-ext-link' || type === 'ext-link-url' || type === 'image-parameter' && name === 'link'
|
|
57
|
+
|| type === 'attr-value'
|
|
57
58
|
? errorSyntaxUrl
|
|
58
59
|
: errorSyntax, errors = [...data.matchAll(errorRegex)], { ext, html } = this.getRootNode().getAttribute('config');
|
|
59
60
|
if (errors.length > 0) {
|
|
@@ -74,7 +75,7 @@ class AstText extends node_1.AstNode {
|
|
|
74
75
|
|| !data.slice(0, index).trim() && previousType === 'free-ext-link')
|
|
75
76
|
? 'error'
|
|
76
77
|
: 'warning';
|
|
77
|
-
return (char !== '
|
|
78
|
+
return (char !== '<' || tags.has(tag.toLowerCase())) && {
|
|
78
79
|
message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
|
|
79
80
|
severity,
|
|
80
81
|
startIndex,
|
package/dist/parser/links.js
CHANGED
|
@@ -13,7 +13,7 @@ const category_1 = require("../src/link/category");
|
|
|
13
13
|
*/
|
|
14
14
|
const parseLinks = (wikitext, config = Parser.getConfig(), accum = []) => {
|
|
15
15
|
const { parseQuotes } = require('./quotes');
|
|
16
|
-
const regex = /^((?:(?!\0\d+!\x7F)[^\n
|
|
16
|
+
const regex = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(?:(\||\0\d+!\x7F)(.*?[^\]]))?\]\](.*)$/su, regexImg = /^((?:(?!\0\d+!\x7F)[^\n[\]{}|])+)(\||\0\d+!\x7F)(.*)$/su, regexExt = new RegExp(`^\\s*(?:${config.protocol})`, 'iu'), bits = wikitext.split('[[');
|
|
17
17
|
let s = bits.shift();
|
|
18
18
|
for (let i = 0; i < bits.length; i++) {
|
|
19
19
|
let mightBeImg = false, link, delimiter, text, after;
|
package/dist/parser/table.js
CHANGED
|
@@ -61,7 +61,7 @@ const parseTable = ({ firstChild: { data }, type, name }, config = Parser.getCon
|
|
|
61
61
|
out += `\n${outLine}`;
|
|
62
62
|
continue;
|
|
63
63
|
}
|
|
64
|
-
// eslint-disable-next-line operator-linebreak
|
|
64
|
+
// eslint-disable-next-line @stylistic/operator-linebreak
|
|
65
65
|
const matches = /^(?:(\|\}|\0\d+!\x7F\}|\0\d+\}\x7F)|(\|-+|\0\d+!\x7F-+|\0\d+-\x7F-*)(?!-)|(!|(?:\||\0\d+!\x7F)\+?))(.*)$/u
|
|
66
66
|
.exec(line);
|
|
67
67
|
if (!matches) {
|
package/dist/src/arg.js
CHANGED
|
@@ -65,11 +65,11 @@ class ArgToken extends index_1.Token {
|
|
|
65
65
|
if (rest.length > 0) {
|
|
66
66
|
const rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
67
67
|
errors.push(...rest.map(child => {
|
|
68
|
-
const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces')
|
|
68
|
+
const error = (0, lint_1.generateForChild)(child, rect, 'invisible content inside triple braces');
|
|
69
69
|
return {
|
|
70
70
|
...error,
|
|
71
|
-
startIndex: startIndex - 1,
|
|
72
|
-
startCol: startCol - 1,
|
|
71
|
+
startIndex: error.startIndex - 1,
|
|
72
|
+
startCol: error.startCol - 1,
|
|
73
73
|
};
|
|
74
74
|
}));
|
|
75
75
|
}
|
package/dist/src/attribute.js
CHANGED
|
@@ -201,10 +201,10 @@ class AttributeToken extends index_1.Token {
|
|
|
201
201
|
if (!balanced) {
|
|
202
202
|
const root = this.getRootNode();
|
|
203
203
|
rect = { start, ...root.posFromIndex(start) };
|
|
204
|
-
const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed quotes', 'warning')
|
|
204
|
+
const e = (0, lint_1.generateForChild)(lastChild, rect, 'unclosed quotes', 'warning');
|
|
205
205
|
errors.push({
|
|
206
206
|
...e,
|
|
207
|
-
startIndex,
|
|
207
|
+
startIndex: e.startIndex - 1,
|
|
208
208
|
startCol: e.startCol - 1,
|
|
209
209
|
});
|
|
210
210
|
}
|
|
@@ -54,8 +54,7 @@ class ConverterFlagsToken extends index_1.Token {
|
|
|
54
54
|
const child = childNodes[i], flag = child.text().trim();
|
|
55
55
|
if (flag && !variantFlags.has(flag) && !unknownFlags.has(flag)
|
|
56
56
|
&& (variantFlags.size > 0 || !validFlags.has(flag))) {
|
|
57
|
-
|
|
58
|
-
errors.push(error);
|
|
57
|
+
errors.push((0, lint_1.generateForChild)(child, rect, 'invalid conversion flag'));
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
return errors;
|
package/dist/src/gallery.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import * as Parser from '../index';
|
|
2
2
|
import { Token } from './index';
|
|
3
3
|
import { GalleryImageToken } from './link/galleryImage';
|
|
4
|
-
import {
|
|
4
|
+
import { NoincludeToken } from './nowiki/noinclude';
|
|
5
5
|
import type { LintError } from '../base';
|
|
6
6
|
import type { AstText, AttributesToken, ExtToken } from '../internal';
|
|
7
7
|
/**
|
|
8
8
|
* gallery标签
|
|
9
|
-
* @classdesc `{childNodes: ...(GalleryImageToken|
|
|
9
|
+
* @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
|
|
10
10
|
*/
|
|
11
11
|
export declare class GalleryToken extends Token {
|
|
12
12
|
#private;
|
|
13
13
|
readonly type = "ext-inner";
|
|
14
14
|
readonly name: 'gallery';
|
|
15
|
-
readonly childNodes: (GalleryImageToken |
|
|
16
|
-
abstract get firstChild(): GalleryImageToken |
|
|
17
|
-
abstract get lastChild(): GalleryImageToken |
|
|
15
|
+
readonly childNodes: (GalleryImageToken | NoincludeToken | AstText)[];
|
|
16
|
+
abstract get firstChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
|
|
17
|
+
abstract get lastChild(): GalleryImageToken | NoincludeToken | AstText | undefined;
|
|
18
18
|
abstract get nextSibling(): undefined;
|
|
19
19
|
abstract get previousSibling(): AttributesToken;
|
|
20
20
|
abstract get parentNode(): ExtToken | undefined;
|
package/dist/src/gallery.js
CHANGED
|
@@ -4,10 +4,10 @@ exports.GalleryToken = void 0;
|
|
|
4
4
|
const Parser = require("../index");
|
|
5
5
|
const index_1 = require("./index");
|
|
6
6
|
const galleryImage_1 = require("./link/galleryImage");
|
|
7
|
-
const
|
|
7
|
+
const noinclude_1 = require("./nowiki/noinclude");
|
|
8
8
|
/**
|
|
9
9
|
* gallery标签
|
|
10
|
-
* @classdesc `{childNodes: ...(GalleryImageToken|
|
|
10
|
+
* @classdesc `{childNodes: ...(GalleryImageToken|NoincludeToken|AstText)}`
|
|
11
11
|
*/
|
|
12
12
|
class GalleryToken extends index_1.Token {
|
|
13
13
|
type = 'ext-inner';
|
|
@@ -17,9 +17,7 @@ class GalleryToken extends index_1.Token {
|
|
|
17
17
|
for (const line of inner?.split('\n') ?? []) {
|
|
18
18
|
const matches = /^([^|]+)(?:\|(.*))?/u.exec(line);
|
|
19
19
|
if (!matches) {
|
|
20
|
-
super.insertAt((line.trim()
|
|
21
|
-
? new hidden_1.HiddenToken(line, config, [], {})
|
|
22
|
-
: line));
|
|
20
|
+
super.insertAt((line.trim() ? new noinclude_1.NoincludeToken(line, config) : line));
|
|
23
21
|
continue;
|
|
24
22
|
}
|
|
25
23
|
const [, file, alt] = matches;
|
|
@@ -27,7 +25,7 @@ class GalleryToken extends index_1.Token {
|
|
|
27
25
|
super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
|
|
28
26
|
}
|
|
29
27
|
else {
|
|
30
|
-
super.insertAt(new
|
|
28
|
+
super.insertAt(new noinclude_1.NoincludeToken(line, config));
|
|
31
29
|
}
|
|
32
30
|
}
|
|
33
31
|
}
|
|
@@ -55,7 +53,7 @@ class GalleryToken extends index_1.Token {
|
|
|
55
53
|
const { top, left } = this.getRootNode().posFromIndex(start), errors = [];
|
|
56
54
|
for (let i = 0; i < this.length; i++) {
|
|
57
55
|
const child = this.childNodes[i], str = String(child), { length } = str, trimmed = str.trim(), startLine = top + i, startCol = i ? 0 : left;
|
|
58
|
-
if (child.type === '
|
|
56
|
+
if (child.type === 'noinclude' && trimmed && !/^<!--.*-->$/u.test(trimmed)) {
|
|
59
57
|
errors.push({
|
|
60
58
|
message: Parser.msg('invalid content in <$1>', 'gallery'),
|
|
61
59
|
severity: 'error',
|
|
@@ -67,7 +65,7 @@ class GalleryToken extends index_1.Token {
|
|
|
67
65
|
endCol: startCol + length,
|
|
68
66
|
});
|
|
69
67
|
}
|
|
70
|
-
else if (child.type !== '
|
|
68
|
+
else if (child.type !== 'noinclude' && child.type !== 'text') {
|
|
71
69
|
errors.push(...child.lint(start));
|
|
72
70
|
}
|
|
73
71
|
start += length + 1;
|
package/dist/src/parameter.js
CHANGED
|
@@ -59,7 +59,7 @@ class ParameterToken extends index_1.Token {
|
|
|
59
59
|
}
|
|
60
60
|
/** @override */
|
|
61
61
|
lint(start = this.getAbsoluteIndex()) {
|
|
62
|
-
const errors = super.lint(start), { firstChild
|
|
62
|
+
const errors = super.lint(start), { firstChild } = this, link = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu')
|
|
63
63
|
.exec(firstChild.toString(new Set(['comment', 'noinclude', 'include'])))?.[0];
|
|
64
64
|
if (link && new URL(link).search) {
|
|
65
65
|
const e = (0, lint_1.generateForChild)(firstChild, { start }, 'unescaped query string in an anonymous parameter');
|
package/dist/src/table/index.js
CHANGED
|
@@ -29,8 +29,7 @@ class TableToken extends trBase_1.TrBaseToken {
|
|
|
29
29
|
lint(start = this.getAbsoluteIndex()) {
|
|
30
30
|
const errors = super.lint(start);
|
|
31
31
|
if (!this.closed) {
|
|
32
|
-
|
|
33
|
-
errors.push(error);
|
|
32
|
+
errors.push((0, lint_1.generateForChild)(this.firstChild, { start }, 'unclosed table'));
|
|
34
33
|
}
|
|
35
34
|
return errors;
|
|
36
35
|
}
|
package/dist/src/tagPair/ext.js
CHANGED
|
@@ -112,7 +112,7 @@ class ExtToken extends index_2.TagPairToken {
|
|
|
112
112
|
lint(start = this.getAbsoluteIndex()) {
|
|
113
113
|
const errors = super.lint(start);
|
|
114
114
|
if (this.name !== 'nowiki' && this.closest('html-attrs, table-attrs')) {
|
|
115
|
-
const
|
|
115
|
+
const rect = { start, ...this.getRootNode().posFromIndex(start) };
|
|
116
116
|
errors.push((0, lint_1.generateForSelf)(this, rect, 'extension tag in HTML tag attributes'));
|
|
117
117
|
}
|
|
118
118
|
return errors;
|
package/dist/util/lint.js
CHANGED
|
@@ -10,12 +10,12 @@ const Parser = require("../index");
|
|
|
10
10
|
* @param severity 严重程度
|
|
11
11
|
*/
|
|
12
12
|
const generateForChild = (child, boundingRect, msg, severity = 'error') => {
|
|
13
|
-
const index = child.getRelativeIndex(), { offsetHeight, offsetWidth, parentNode } = child, { top: offsetTop, left: offsetLeft } = parentNode.posFromIndex(index), { start } = boundingRect, { top, left } = 'top' in boundingRect ? boundingRect : child.getRootNode().posFromIndex(start),
|
|
13
|
+
const index = child.getRelativeIndex(), { offsetHeight, offsetWidth, parentNode } = child, { top: offsetTop, left: offsetLeft } = parentNode.posFromIndex(index), { start } = boundingRect, { top, left } = 'top' in boundingRect ? boundingRect : child.getRootNode().posFromIndex(start), startIndex = start + index, startLine = top + offsetTop, startCol = offsetTop ? offsetLeft : left + offsetLeft;
|
|
14
14
|
return {
|
|
15
15
|
message: Parser.msg(msg),
|
|
16
16
|
severity,
|
|
17
17
|
startIndex,
|
|
18
|
-
endIndex: startIndex +
|
|
18
|
+
endIndex: startIndex + String(child).length,
|
|
19
19
|
startLine,
|
|
20
20
|
endLine: startLine + offsetHeight - 1,
|
|
21
21
|
startCol,
|
|
@@ -31,12 +31,12 @@ exports.generateForChild = generateForChild;
|
|
|
31
31
|
* @param severity 严重程度
|
|
32
32
|
*/
|
|
33
33
|
const generateForSelf = (token, boundingRect, msg, severity = 'error') => {
|
|
34
|
-
const { start } = boundingRect, { offsetHeight, offsetWidth } = token,
|
|
34
|
+
const { start } = boundingRect, { offsetHeight, offsetWidth } = token, { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start);
|
|
35
35
|
return {
|
|
36
36
|
message: Parser.msg(msg),
|
|
37
37
|
severity,
|
|
38
38
|
startIndex: start,
|
|
39
|
-
endIndex: start +
|
|
39
|
+
endIndex: start + String(token).length,
|
|
40
40
|
startLine: top,
|
|
41
41
|
endLine: top + offsetHeight - 1,
|
|
42
42
|
startCol: left,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikilint",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "A Node.js linter for MediaWiki markup",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mediawiki",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@cypress/request": "^3.0.1",
|
|
45
|
+
"@stylistic/eslint-plugin": "^1.5.3",
|
|
45
46
|
"@types/node": "^20.9.0",
|
|
46
47
|
"@types/request": "^2.48.12",
|
|
47
48
|
"@typescript-eslint/eslint-plugin": "^6.12.0",
|