wikilint 2.35.2 → 2.36.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.
@@ -77,7 +77,7 @@ const mw = {
77
77
  },
78
78
  },
79
79
  };
80
- const pkg = "wikilint", version = "2.35.2";
80
+ const pkg = "wikilint", version = "2.36.0";
81
81
  let mwConfig;
82
82
  /**
83
83
  * Get the parser configuration for a Wikimedia Foundation project.
package/dist/index.js CHANGED
@@ -20,10 +20,17 @@ const re = new RegExp(String.raw `^https?:\/\/([^./]+)\.(${common_1.wmf})\.org`,
20
20
  * 从根路径require
21
21
  * @param file 文件名
22
22
  * @param dir 子路径
23
+ * @throws {RangeError} 仅支持JSON文件
23
24
  */
24
- const rootRequire = (file, dir) => require(path_1.default.isAbsolute(file)
25
- ? /* c8 ignore next */ file
26
- : path_1.default.join('..', file.includes('/') ? '' : dir, file));
25
+ const rootRequire = (file, dir) => {
26
+ const fullPath = require.resolve(path_1.default.isAbsolute(file)
27
+ ? /* c8 ignore next */ file
28
+ : path_1.default.join('..', file.includes('/') ? '' : dir, file));
29
+ if (!fullPath.endsWith('.json')) {
30
+ throw new RangeError('Only JSON files are supported!');
31
+ }
32
+ return require(fullPath);
33
+ };
27
34
  /* NOT FOR BROWSER ONLY END */
28
35
  let viewOnly = true;
29
36
  let lintConfig = (() => {
@@ -236,14 +236,12 @@ const defaultLintRuleConfig = {
236
236
  ],
237
237
  'invalid-math': 2,
238
238
  };
239
- Object.freeze(defaultLintRuleConfig);
240
239
  const defaultLintConfig = {
241
240
  configurationComment: 'lint',
242
241
  ignoreDisables: false,
243
242
  fix: true,
244
243
  computeEditInfo: true,
245
244
  };
246
- Object.freeze(defaultLintConfig);
247
245
  /**
248
246
  * 验证错误级别是否符合规范
249
247
  * @param severity 错误级别
@@ -1,4 +1,4 @@
1
- import type { LintError, AstNode as AstNodeBase, TokenTypes } from '../base';
1
+ import type { AstNode as AstNodeBase, TokenTypes, LintError } from '../base';
2
2
  import type { NodeLike } from '../mixin/nodeLike';
3
3
  import type { AstText, Token } from '../internal';
4
4
  export type AstNodes = AstText | Token;
@@ -1,7 +1,7 @@
1
1
  import Parser from '../index';
2
2
  import { AstElement } from '../lib/element';
3
3
  import { AstText } from '../lib/text';
4
- import type { LintError, TokenTypes } from '../base';
4
+ import type { TokenTypes, LintError } from '../base';
5
5
  import type { Title, TitleOptions } from '../lib/title';
6
6
  import type { AstNodes } from '../internal';
7
7
  declare type ExtendedLintError = LintError[] & {
@@ -1,5 +1,5 @@
1
1
  import { NowikiBaseToken } from './base';
2
- import type { LintError, Config } from '../../base';
2
+ import type { Config, LintError } from '../../base';
3
3
  import type { Token } from '../../internal';
4
4
  /**
5
5
  * invisible HTML comment
@@ -1,6 +1,6 @@
1
1
  import { Token } from './index';
2
2
  import type { Config, LintError } from '../base';
3
- import type { AtomToken, SyntaxToken, TranscludeToken } from '../internal';
3
+ import type { AtomToken, TranscludeToken, SyntaxToken } from '../internal';
4
4
  /**
5
5
  * template or magic word parameter
6
6
  *
@@ -1,5 +1,5 @@
1
1
  import { TagPairToken } from './index';
2
- import type { LintError, Config } from '../../base';
2
+ import type { Config, LintError } from '../../base';
3
3
  import type { AstText, Token } from '../../internal';
4
4
  /**
5
5
  * `<includeonly>`, `<noinclude>` or `<onlyinclude>`
@@ -56,25 +56,13 @@ export declare abstract class TranscludeToken extends Token {
56
56
  * @param i position to be inserted at / 插入位置
57
57
  */
58
58
  insertAt<T extends ParameterToken>(token: T, i?: number): T;
59
- /**
60
- * Get all parameters
61
- *
62
- * 获取所有参数
63
- */
64
- getAllArgs(): ParameterToken[];
65
- /**
66
- * Get all anonymous parameters
67
- *
68
- * 获取所有匿名参数
69
- */
70
- getAnonArgs(): ParameterToken[];
71
59
  /**
72
60
  * Get parameters with the specified name
73
61
  *
74
62
  * 获取指定参数
75
63
  * @param key parameter name / 参数名
76
64
  */
77
- getArgs(key: string | number, exact?: boolean, copy?: boolean): Set<ParameterToken>;
65
+ getArgs(key: string | number, exact?: boolean, copy?: boolean, init?: boolean): Set<ParameterToken>;
78
66
  /**
79
67
  * Get duplicated parameters
80
68
  *
@@ -76,6 +76,7 @@ let TranscludeToken = (() => {
76
76
  #colon = ':';
77
77
  #raw = false;
78
78
  #args = new Map();
79
+ #anonCount = 0;
79
80
  #title;
80
81
  get type() {
81
82
  return this.#type;
@@ -317,19 +318,17 @@ let TranscludeToken = (() => {
317
318
  return errors;
318
319
  }
319
320
  }
320
- /**
321
- * 处理匿名参数更改
322
- * @param addedToken 新增的参数
323
- */
324
- #handleAnonArgChange(addedToken) {
325
- const args = this.getAnonArgs(), added = typeof addedToken !== 'number';
326
- for (let i = added ? args.indexOf(addedToken) : addedToken - 1; i < args.length; i++) {
327
- const token = args[i], { name } = token, newName = String(i + 1);
328
- if (name !== newName || token === addedToken) {
329
- token.setAttribute('name', newName);
330
- this.getArgs(newName, false, false).add(token);
331
- }
332
- }
321
+ #handleAnonArgChange(addedToken, append) {
322
+ /* eslint-disable @stylistic/operator-linebreak */
323
+ this.#anonCount +=
324
+ 1;
325
+ /* eslint-enable @stylistic/operator-linebreak */
326
+ let i;
327
+ // eslint-disable-next-line prefer-const
328
+ i = this.#anonCount - 1;
329
+ const token = addedToken, newName = String(i + 1);
330
+ token.setAttribute('name', newName);
331
+ this.getArgs(newName, false, false).add(token);
333
332
  }
334
333
  /**
335
334
  * @override
@@ -346,22 +345,6 @@ let TranscludeToken = (() => {
346
345
  }
347
346
  return token;
348
347
  }
349
- /**
350
- * Get all parameters
351
- *
352
- * 获取所有参数
353
- */
354
- getAllArgs() {
355
- return this.childNodes.filter((0, debug_1.isToken)('parameter'));
356
- }
357
- /**
358
- * Get all anonymous parameters
359
- *
360
- * 获取所有匿名参数
361
- */
362
- getAnonArgs() {
363
- return this.getAllArgs().filter(({ anon }) => anon);
364
- }
365
348
  // eslint-disable-next-line jsdoc/require-param
366
349
  /**
367
350
  * Get parameters with the specified name
@@ -369,7 +352,7 @@ let TranscludeToken = (() => {
369
352
  * 获取指定参数
370
353
  * @param key parameter name / 参数名
371
354
  */
372
- getArgs(key, exact, copy = true) {
355
+ getArgs(key, exact, copy = true, init = true) {
373
356
  const keyStr = String(key)
374
357
  .replace(/^[ \t\n\0\v]+|([^ \t\n\0\v])[ \t\n\0\v]+$/gu, '$1');
375
358
  let args;
@@ -377,7 +360,9 @@ let TranscludeToken = (() => {
377
360
  args = this.#args.get(keyStr);
378
361
  }
379
362
  else {
380
- args = new Set(this.getAllArgs().filter(({ name }) => keyStr === name));
363
+ /* eslint-disable @stylistic/function-paren-newline */
364
+ args = new Set();
365
+ /* eslint-enable @stylistic/function-paren-newline */
381
366
  this.#args.set(keyStr, args);
382
367
  }
383
368
  return args;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikilint",
3
- "version": "2.35.2",
3
+ "version": "2.36.0",
4
4
  "description": "A Node.js linter for MediaWiki markup",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -53,6 +53,7 @@
53
53
  "coverage": "tsc --declaration false --target es2024 && npm run build:define && c8 npm run test:ci && node dist/script/coverage.js && open coverage/index.html",
54
54
  "test:unit": "mocha dist/test/test.js",
55
55
  "test:parser": "LC_ALL=en.UTF-8 mocha dist/test/parserTests.js",
56
+ "test:perf": "mocha --reporter spec dist/test/perf.js",
56
57
  "test": "npm run test:unit && npm run test:parser",
57
58
  "test:parseronly": "LSP=0 npm run test:parser",
58
59
  "test:ci": "LSP=0 npm test",
@@ -82,39 +83,39 @@
82
83
  "color-name": "^2.0.0",
83
84
  "entities": "^7.0.1",
84
85
  "mathoid-texvcjs": "^0.6.0",
85
- "minimatch": "^10.2.2",
86
- "stylelint": "^17.3.0",
87
- "vscode-css-languageservice": "^6.3.9",
88
- "vscode-html-languageservice": "^5.6.1",
89
- "vscode-json-languageservice": "^5.7.1"
86
+ "minimatch": "^10.2.4",
87
+ "stylelint": "^17.4.0",
88
+ "vscode-css-languageservice": "^6.3.10",
89
+ "vscode-html-languageservice": "^5.6.2",
90
+ "vscode-json-languageservice": "^5.7.2"
90
91
  },
91
92
  "devDependencies": {
92
- "@bhsd/code-standard": "^2.0.1",
93
- "@bhsd/nodejs": "^0.1.0",
93
+ "@bhsd/code-standard": "^2.1.0",
94
+ "@bhsd/nodejs": "^0.1.1",
94
95
  "@bhsd/test-util": "^0.3.0",
95
- "@stylistic/eslint-plugin": "^5.8.0",
96
+ "@stylistic/eslint-plugin": "^5.9.0",
96
97
  "@types/color-name": "^2.0.0",
97
98
  "@types/color-rgba": "^2.1.3",
98
99
  "@types/mocha": "^10.0.10",
99
- "@types/node": "^24.10.13",
100
+ "@types/node": "^24.11.0",
100
101
  "@typescript-eslint/eslint-plugin": "^8.54.0",
101
102
  "@typescript-eslint/parser": "^8.54.0",
102
- "c8": "^10.1.3",
103
+ "c8": "^11.0.0",
103
104
  "color-rgba": "^3.0.0",
104
105
  "diff2html-cli": "^5.2.15",
105
106
  "esbuild": "^0.27.3",
106
107
  "eslint": "^9.39.3",
107
108
  "eslint-plugin-eslint-comments": "^3.2.0",
108
- "eslint-plugin-jsdoc": "^62.7.0",
109
- "eslint-plugin-jsonc": "^2.21.1",
110
- "eslint-plugin-n": "^17.23.2",
109
+ "eslint-plugin-jsdoc": "^62.7.1",
110
+ "eslint-plugin-jsonc": "^3.1.1",
111
+ "eslint-plugin-n": "^17.24.0",
111
112
  "eslint-plugin-promise": "^7.2.1",
112
113
  "eslint-plugin-regexp": "^3.0.0",
113
114
  "eslint-plugin-unicorn": "^63.0.0",
114
115
  "markdownlint-cli2": "^0.21.0",
115
116
  "mocha": "^11.7.5",
116
117
  "typescript": "^5.9.3",
117
- "v8r": "^5.1.0",
118
+ "v8r": "^6.0.0",
118
119
  "vscode-languageserver-textdocument": "^1.0.12"
119
120
  },
120
121
  "engines": {