wikilint 2.48.0 → 2.48.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 CHANGED
@@ -97,6 +97,6 @@ repos:
97
97
  # You can add any CLI options as needed
98
98
  entry: wikilint
99
99
  language: node
100
- additional_dependencies: ['wikilint@2.48.0']
100
+ additional_dependencies: ['wikilint@2.48.1']
101
101
  files: \.(mediawiki|wiki|wikitext)$
102
102
  ```
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/draft-07/schema#",
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "type": "object",
4
4
  "properties": {
5
5
  "ext": {
package/dist/base.d.mts CHANGED
@@ -2,7 +2,7 @@ import type { Range, Position, ColorInformation, ColorPresentation, CompletionIt
2
2
  export interface Config {
3
3
  ext: string[];
4
4
  readonly html: [string[], string[], string[]];
5
- readonly namespaces: Record<string, string>;
5
+ readonly namespaces: Record<number, string>;
6
6
  readonly nsid: Record<string, number>;
7
7
  readonly parserFunction: [Record<string, string>, Record<string, string>, string[], string[]];
8
8
  readonly doubleUnderscore: [string[], string[], Record<string, string>, Record<string, string>];
package/dist/base.d.ts CHANGED
@@ -2,7 +2,7 @@ import type { Range, Position, ColorInformation, ColorPresentation, CompletionIt
2
2
  export interface Config {
3
3
  ext: string[];
4
4
  readonly html: [string[], string[], string[]];
5
- readonly namespaces: Record<string, string>;
5
+ readonly namespaces: Record<number, string>;
6
6
  readonly nsid: Record<string, number>;
7
7
  readonly parserFunction: [Record<string, string>, Record<string, string>, string[], string[]];
8
8
  readonly doubleUnderscore: [string[], string[], Record<string, string>, Record<string, string>];
package/dist/bin/cli.js CHANGED
@@ -404,9 +404,9 @@ const { mtimeMs } = fs_1.default.statSync(config), obj = cache?.[include ? 'incl
404
404
  exiting ||= Boolean(nLocalErr || strict && nLocalWarn);
405
405
  }
406
406
  if (nErr || nWarn) {
407
- console.error(styleText(['red', 'bold'], '%s'), `\n✖ ${plural(nErr + nWarn, 'problem')} (${plural(nErr, 'error')}, ${plural(nWarn, 'warning')})`);
407
+ console.error(styleText(['red', 'bold'], '\n✖ %s (%s, %s)'), plural(nErr + nWarn, 'problem'), plural(nErr, 'error'), plural(nWarn, 'warning'));
408
408
  if (nFixableErr || nFixableWarn) {
409
- console.error(styleText(['red', 'bold'], '%s'), ` ${plural(nFixableErr, 'error')} and ${plural(nFixableWarn, 'warning')} potentially fixable with the \`--fix\` option.`);
409
+ console.error(styleText(['red', 'bold'], ' %s and %s potentially fixable with the `--fix` option.'), plural(nFixableErr, 'error'), plural(nFixableWarn, 'warning'));
410
410
  }
411
411
  console.error();
412
412
  }
@@ -41,7 +41,7 @@ const filterGadget = (id) => {
41
41
  const n = Number(id);
42
42
  return n < 2300 || n > 2303; // Gadget, Gadget talk, Gadget definition, Gadget definition talk
43
43
  };
44
- const pkg = 'wikilint', version = '2.48.0';
44
+ const pkg = 'wikilint', version = '2.48.1';
45
45
  /**
46
46
  * Get the parser configuration for a Wikimedia Foundation project.
47
47
  * @param site site nickname
@@ -1,8 +1,8 @@
1
1
  import type { Position } from 'vscode-languageserver-types';
2
2
  import type { TextDocument, Range } from 'vscode-languageserver-textdocument';
3
- import type { JSONDocument, LanguageService as JSONLanguageService } from 'vscode-json-languageservice';
4
- import type { Stylesheet, LanguageService as CSSLanguageService } from 'vscode-css-languageservice';
5
- import type { IHTMLDataProvider } from 'vscode-html-languageservice';
3
+ import type * as JsonLanguageService from 'vscode-json-languageservice';
4
+ import type * as CssLanguageService from 'vscode-css-languageservice';
5
+ import type * as HtmlLanguageService from 'vscode-html-languageservice';
6
6
  import type { PublicApi } from 'stylelint';
7
7
  import type { Token } from '../internal';
8
8
  export interface TexvcLocation {
@@ -32,9 +32,9 @@ declare interface Texvcjs {
32
32
  }): TexvcReport;
33
33
  }
34
34
  export declare const loadTexvcjs: () => Texvcjs | null;
35
- export declare const loadJsonLSP: () => JSONLanguageService | null;
36
- export declare const loadCssLSP: () => CSSLanguageService | null;
37
- export declare const loadHtmlData: () => IHTMLDataProvider | null;
35
+ export declare const loadJsonLSP: () => JsonLanguageService.LanguageService | null;
36
+ export declare const loadCssLSP: () => CssLanguageService.LanguageService | null;
37
+ export declare const loadHtmlData: () => HtmlLanguageService.IHTMLDataProvider | null;
38
38
  export declare const loadStylelint: () => PublicApi | null;
39
39
  /** embedded document */
40
40
  declare abstract class EmbeddedDocument implements TextDocument {
@@ -65,7 +65,7 @@ declare abstract class EmbeddedDocument implements TextDocument {
65
65
  }
66
66
  /** embedded JSON document */
67
67
  export declare class EmbeddedJSONDocument extends EmbeddedDocument {
68
- jsonDoc: JSONDocument;
68
+ jsonDoc: JsonLanguageService.JSONDocument;
69
69
  abstract getLineRange(): Range;
70
70
  abstract getEOLCharacters(): string;
71
71
  /**
@@ -76,7 +76,7 @@ export declare class EmbeddedJSONDocument extends EmbeddedDocument {
76
76
  }
77
77
  /** embedded CSS document */
78
78
  export declare class EmbeddedCSSDocument extends EmbeddedDocument {
79
- styleSheet: Stylesheet;
79
+ styleSheet: CssLanguageService.Stylesheet;
80
80
  abstract getLineRange(): Range;
81
81
  abstract getEOLCharacters(): string;
82
82
  /**
@@ -27,8 +27,7 @@ let jsonLSP;
27
27
  const loadJsonLSP = () => {
28
28
  if (jsonLSP === undefined) {
29
29
  try {
30
- jsonLSP = require('vscode-json-languageservice')
31
- .getLanguageService({
30
+ jsonLSP = require('vscode-json-languageservice').getLanguageService({
32
31
  /* c8 ignore start */
33
32
  /** @implements */
34
33
  async schemaRequestService(uri) {
@@ -67,8 +66,7 @@ let cssLSP;
67
66
  const loadCssLSP = () => {
68
67
  if (cssLSP === undefined) {
69
68
  try {
70
- cssLSP = require('vscode-css-languageservice')
71
- .getCSSLanguageService();
69
+ cssLSP = require('vscode-css-languageservice').getCSSLanguageService();
72
70
  }
73
71
  catch /* c8 ignore start */ {
74
72
  cssLSP = null;
package/dist/lib/node.js CHANGED
@@ -90,7 +90,7 @@ let AstNode = (() => {
90
90
  /** @private */
91
91
  getChildNodes() {
92
92
  const { childNodes } = this;
93
- if (Object.isFrozen(childNodes)) { // NOT FOR TEMPLATE
93
+ if (Object.isFrozen(childNodes)) { // eslint-disable-line unicorn/prefer-ternary
94
94
  return [...childNodes];
95
95
  }
96
96
  return childNodes;
package/dist/lib/text.js CHANGED
@@ -70,7 +70,7 @@ class AstText extends node_1.AstNode {
70
70
  }
71
71
  /** @private */
72
72
  toString(skip) {
73
- if (skip && !this.parentNode?.getAttribute('built')) { // NOT FOR TEMPLATE
73
+ if (skip && !this.parentNode?.getAttribute('built')) { // eslint-disable-line unicorn/prefer-ternary
74
74
  return (0, string_1.removeComment)(this.data);
75
75
  }
76
76
  return this.data;
@@ -178,19 +178,19 @@ class AttributeToken extends index_2.Token {
178
178
  }
179
179
  }
180
180
  }
181
- else if ((/^xmlns:[\w:.-]+$/u.test(name) || urlAttrs.has(name)) && evil.test(value)
182
- || simple
183
- && (name === 'href' || type === 'ext-attr' && tag === 'img' && name === 'src')
184
- && !new RegExp(String.raw `^(?:${this.getAttribute('config').protocol}|//)\S+$`, 'iu')
185
- .test(value)) {
186
- LINT: {
187
- const s = lintConfig.getSeverity(rule, 'value');
188
- return s && (0, lint_1.generateForChild)(lastChild, rect, rule, 'illegal-attribute-value', s);
181
+ else {
182
+ let valueIssue = (/^xmlns:[\w:.-]+$/u.test(name) || urlAttrs.has(name)) && evil.test(value)
183
+ || simple
184
+ && (name === 'href' || type === 'ext-attr' && tag === 'img' && name === 'src')
185
+ && !new RegExp(String.raw `^(?:${this.getAttribute('config').protocol}|//)\S+$`, 'iu')
186
+ .test(value);
187
+ if (simple && !valueIssue && type !== 'ext-attr') {
188
+ const data = (0, lint_1.provideValues)(tag, name), v = value.toLowerCase();
189
+ if (data.length > 0 && data.every(n => n !== v)) {
190
+ valueIssue = true;
191
+ }
189
192
  }
190
- }
191
- else if (simple && type !== 'ext-attr') {
192
- const data = (0, lint_1.provideValues)(tag, name), v = value.toLowerCase();
193
- if (data.length > 0 && data.every(n => n !== v)) {
193
+ if (valueIssue) {
194
194
  LINT: {
195
195
  const s = lintConfig.getSeverity(rule, 'value');
196
196
  return s && (0, lint_1.generateForChild)(lastChild, rect, rule, 'illegal-attribute-value', s);
@@ -86,7 +86,7 @@ let ConverterRuleToken = (() => {
86
86
  */
87
87
  constructor(rule, hasColon = true, config = index_1.default.getConfig(), accum = []) {
88
88
  super(undefined, config, accum, {});
89
- const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = j === -1 ? rule.slice(0, i) : rule.slice(j + 2, i);
89
+ const i = rule.indexOf(':'), j = rule.slice(0, i).indexOf('=>'), v = rule.slice(j === -1 ? 0 : j + 2, i);
90
90
  if (hasColon && config.variants.includes(v.trim())) {
91
91
  super.insertAt(new atom_1.AtomToken(v, 'converter-rule-variant', config, accum));
92
92
  super.insertAt(getRuleFromTo(rule.slice(i + 1), 'to', config, accum));
package/dist/src/index.js CHANGED
@@ -113,6 +113,7 @@ class Token extends element_1.AstElement {
113
113
  return this;
114
114
  }
115
115
  /* c8 ignore start */
116
+ // eslint-disable-next-line unicorn/prefer-combined-guards
116
117
  if (this.#stage >= constants_1.MAX_STAGE) {
117
118
  return this;
118
119
  }
@@ -124,7 +124,7 @@ let LinkBaseToken = (() => {
124
124
  /** @private */
125
125
  toString(skip) {
126
126
  const str = super.toString(skip, this.#delimiter);
127
- if (this.#bracket) { // NOT FOR TEMPLATE
127
+ if (this.#bracket) { // eslint-disable-line unicorn/prefer-ternary
128
128
  return `[[${str}]]`;
129
129
  }
130
130
  return str;
@@ -137,7 +137,7 @@ let LinkBaseToken = (() => {
137
137
  'trim']()
138
138
  : `${target.trim()}|${(0, string_1.text)(childNodes.slice(1)
139
139
  .filter(({ type: t, name }) => t !== 'image-parameter' || name !== 'invalid'), '|')}`;
140
- if (this.#bracket) { // NOT FOR TEMPLATE
140
+ if (this.#bracket) { // eslint-disable-line unicorn/prefer-ternary
141
141
  return `[[${str}]]`;
142
142
  }
143
143
  return str;
@@ -28,7 +28,7 @@ class GalleryToken extends index_2.MultiLineToken {
28
28
  continue;
29
29
  }
30
30
  const [, file, alt] = matches;
31
- if (this.#checkFile(file)) {
31
+ if (this.#checkFile(file)) { // eslint-disable-line unicorn/prefer-ternary
32
32
  // @ts-expect-error abstract class
33
33
  super.insertAt(new galleryImage_1.GalleryImageToken('gallery', file, alt, config, accum));
34
34
  }
@@ -333,7 +333,7 @@ let TranscludeToken = (() => {
333
333
  this.#anonCount +=
334
334
  1;
335
335
  let i;
336
- // eslint-disable-next-line prefer-const
336
+ // eslint-disable-next-line prefer-const, unicorn/no-immediate-mutation
337
337
  i = this.#anonCount - 1;
338
338
  const token = addedToken, newName = String(i + 1);
339
339
  token.setAttribute('name', newName);
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const fs_1 = __importDefault(require("fs"));
7
+ /**
8
+ * 验证JSON数据并返回错误信息
9
+ * @param schemaPath JSON Schema文件路径
10
+ * @param dataVar 错误信息前缀
11
+ */
12
+ exports.default = (schemaPath, dataVar = '#') => {
13
+ const schema = JSON.parse(fs_1.default.readFileSync(schemaPath, 'utf8'));
14
+ const Ajv = require(schema.$schema?.includes('draft-07') ? 'ajv' : 'ajv/dist/2020'), ajvErrors = require('ajv-errors');
15
+ const ajv = new Ajv({ allErrors: true });
16
+ ajvErrors(ajv, { singleError: true });
17
+ ajv.addKeyword('markdownDescription');
18
+ const v = ajv.compile(schema);
19
+ return data => {
20
+ if (v(data)) {
21
+ return '';
22
+ }
23
+ const errors = v.errors, { instancePath } = errors[0], related = errors.filter(error => error.instancePath === instancePath);
24
+ return ajv.errorsText([related.find(({ keyword }) => keyword === 'errorMessage') || related[0]], { dataVar });
25
+ };
26
+ };
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.toLowerCase = exports.decodeNumber = exports.decodeHtml = exports.decodeHtmlBasic = exports.text = exports.removeCommentLine = exports.removeComment = exports.tidy = exports.trimLc = exports.extUrlChar = exports.extUrlCharFirst = exports.zs = void 0;
4
4
  exports.restore = restore;
5
+ /* NOT FOR BROWSER ONLY END */
5
6
  exports.zs = String.raw ` \xA0\u1680\u2000-\u200A\u202F\u205F\u3000`;
6
7
  const commonExtUrlChar = String.raw `[^[\]<>"\0-\x1F\x7F${exports.zs}\uFFFD]`;
7
8
  exports.extUrlCharFirst = String.raw `(?:\[[\da-f:.]+\]|${commonExtUrlChar})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikilint",
3
- "version": "2.48.0",
3
+ "version": "2.48.1",
4
4
  "description": "A Node.js linter for MediaWiki markup",
5
5
  "keywords": [
6
6
  "mediawiki",
@@ -39,7 +39,7 @@
39
39
  "url": "git+https://github.com/bhsd-harry/wikiparser-node.git"
40
40
  },
41
41
  "scripts": {
42
- "ls": "npm i --package-lock-only && npm ls --package-lock-only --all --include=peer --omit=dev",
42
+ "ls": "npm i --package-lock-only && npm ls --package-lock-only -a --include=peer --omit=dev",
43
43
  "prepublishOnly": "npm run build:core",
44
44
  "build:core": "bash build.sh",
45
45
  "build:define": "bash sed.sh -i \"s/pkg = \\$PKG/pkg = '$(npm pkg get name)'/; s/version = \\$VERSION/version = '$(npm pkg get version)'/\" dist/bin/config.js",
@@ -47,15 +47,15 @@
47
47
  "diff": "bash diff.sh",
48
48
  "diff:stat": "f() { git diff --stat -w --color=always $1 $2 -- . | grep '\\.ts'; }; f",
49
49
  "lint:ts": "[ ! -f dist/bin/config.js ] && npm run build:core; tsc --noEmit && eslint --cache .",
50
- "lint:json": "v8r -s config/.schema.json config/*.json && v8r -s data/.schema.json data/*.json && testUtil dist/test/json.js",
51
- "lint:md": "markdownlint-cli2 '*.md'",
52
- "lint": "npm run lint:ts && npm run lint:json && npm run lint:md",
50
+ "lint:md": "myMarkdownlint",
51
+ "lint": "npm run lint:ts && npm run lint:md",
53
52
  "prof": "node dist/test/prof.js",
54
- "coverage": "tsc --declaration false --target es2024 && npm run build:define && c8 npm run test:ci && node dist/script/coverage.js && open coverage/index.html",
53
+ "coverage": "tsc -d false -t es2024 && npm run build:define && c8 npm run test:ci && node dist/script/coverage.js && open coverage/index.html",
55
54
  "test:unit": "testUtil dist/test/test.js",
55
+ "test:json": "testUtil dist/test/json.js",
56
56
  "test:parser": "LC_ALL=en.UTF-8 testUtil dist/test/parserTests.js",
57
57
  "test:perf": "testUtil --test-reporter=spec dist/test/perf.js",
58
- "test": "npm run test:unit && npm run test:parser",
58
+ "test": "npm run test:unit && npm run test:parser && npm run test:json",
59
59
  "test:parseronly": "LSP=0 npm run test:parser",
60
60
  "test:ci": "LSP=0 npm test",
61
61
  "test:end": "pkill -x http-server",
@@ -98,26 +98,26 @@
98
98
  }
99
99
  },
100
100
  "dependencies": {
101
- "@bhsd/cm-util": "^2.4.1",
101
+ "@bhsd/cm-util": "^2.4.2",
102
102
  "@bhsd/common": "^4.1.0",
103
103
  "@bhsd/stylelint-util": "^1.1.0",
104
104
  "culori": "^4.0.2",
105
105
  "entities": "^8.1.0",
106
- "vscode-languageserver-types": "^3.18.3"
106
+ "vscode-languageserver-types": "^3.18.4"
107
107
  },
108
108
  "devDependencies": {
109
- "@bhsd/code-standard": "^4.3.0",
109
+ "@bhsd/code-standard": "^5.0.0",
110
110
  "@bhsd/nodejs": "^1.2.1",
111
- "@bhsd/test-util": "^3.2.1",
111
+ "@bhsd/test-util": "^3.3.0",
112
+ "ajv": "^8.20.0",
113
+ "ajv-errors": "^3.0.0",
112
114
  "c8": "^12.0.0",
113
115
  "diff2html-cli": "^5.2.15",
114
116
  "esbuild": "^0.28.2",
115
- "eslint": "^10.11.0",
116
- "markdownlint-cli2": "^0.23.3",
117
+ "eslint": "^10.13.0",
117
118
  "mathoid-texvcjs": "^0.6.0",
118
119
  "stylelint": "^17.16.0",
119
120
  "typescript": "^6.0.3",
120
- "v8r": "^6.1.0",
121
121
  "vscode-css-languageservice": "^6.3.10",
122
122
  "vscode-html-languageservice": "^5.6.2",
123
123
  "vscode-json-languageservice": "^5.7.2",