wikilint 2.2.0 → 2.3.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/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?:\/\/|\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu, errorSyntaxUrl = /\{+|\}+|\[{2,}|\[(?![^[]*\])|(?<=^|\])([^[]*?)\]+|\]{2,}|<\s*\/?([a-z]\w*)/giu, disallowedTags = [
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 !== 'h' || index > 0) && (char !== '<' || tags.has(tag.toLowerCase())) && {
78
+ return (char !== '<' || tags.has(tag.toLowerCase())) && {
78
79
  message: Parser.msg('lonely "$1"', char === 'h' ? error : char),
79
80
  severity,
80
81
  startIndex,
@@ -79,7 +79,6 @@ const parseBraces = (wikitext, config = Parser.getConfig(), accum = []) => {
79
79
  }
80
80
  catch (e) {
81
81
  if (e instanceof SyntaxError && e.message.startsWith('非法的模板名称:')) {
82
- lastIndex = index + open.length;
83
82
  skip = true;
84
83
  }
85
84
  else {
@@ -41,10 +41,10 @@ const parseCommentAndExt = (wikitext, config = Parser.getConfig(), accum = [], i
41
41
  return str;
42
42
  }
43
43
  }
44
- const ext = config.ext.join('|'), includeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', noincludeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)|' // comment
45
- + `<${includeRegex}(?:\\s[^>]*?)?>|</${includeRegex}\\s*>|` // <includeonly>
44
+ const ext = config.ext.join('|'), noincludeRegex = includeOnly ? 'includeonly' : '(?:no|only)include', includeRegex = includeOnly ? 'noinclude' : 'includeonly', regex = new RegExp('<!--.*?(?:-->|$)|' // comment
45
+ + `<${noincludeRegex}(?:\\s[^>]*?)?>|</${noincludeRegex}\\s*>|` // <noinclude>
46
46
  + `<(${ext})(\\s[^>]*?)?(?:/>|>(.*?)</(\\1\\s*)>)|` // 扩展标签
47
- + `<(${noincludeRegex})(\\s[^>]*?)?(?:/>|>(.*?)(?:</(\\5\\s*)>|$))`, // <noinclude>
47
+ + `<(${includeRegex})(\\s[^>]*?)?(?:/>|>(.*?)(?:</(${includeRegex}\\s*)>|$))`, // <includeonly>
48
48
  'gisu');
49
49
  return wikitext.replace(regex, (substr, name, attr, inner, closing, include, includeAttr, includeInner, includeClosing) => {
50
50
  const str = `\0${accum.length}${name ? 'e' : 'c'}\x7F`;
@@ -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'), { startIndex, startCol, } = error;
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
  }
@@ -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'), startIndex = e.startIndex - 1;
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
- const error = (0, lint_1.generateForChild)(child, rect, 'invalid conversion flag');
58
- errors.push(error);
57
+ errors.push((0, lint_1.generateForChild)(child, rect, 'invalid conversion flag'));
59
58
  }
60
59
  }
61
60
  return errors;
@@ -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, } = this, link = new RegExp(`https?://${string_1.extUrlCharFirst}${string_1.extUrlChar}$`, 'iu')
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');
@@ -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
- const { firstChild, } = this, error = (0, lint_1.generateForChild)(firstChild, { start }, 'unclosed table');
33
- errors.push(error);
32
+ errors.push((0, lint_1.generateForChild)(this.firstChild, { start }, 'unclosed table'));
34
33
  }
35
34
  return errors;
36
35
  }
@@ -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 root = this.getRootNode(), rect = { start, ...root.posFromIndex(start) };
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), str = String(child), startIndex = start + index, startLine = top + offsetTop, startCol = offsetTop ? offsetLeft : left + offsetLeft;
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 + str.length,
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, str = String(token), { top, left } = 'top' in boundingRect ? boundingRect : token.getRootNode().posFromIndex(start);
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 + str.length,
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.2.0",
3
+ "version": "2.3.1",
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",