wikilint 2.18.0 → 2.18.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/bin/config.js +4 -2
- package/config/.schema.json +1 -1
- package/data/signatures.json +141 -353
- package/dist/base.d.mts +9 -1
- package/dist/base.d.ts +9 -1
- package/dist/bin/config.js +62 -56
- package/dist/index.js +4 -4
- package/dist/lib/lsp.d.ts +20 -3
- package/dist/lib/lsp.js +211 -69
- package/dist/src/attribute.js +10 -4
- package/dist/src/index.js +3 -2
- package/dist/src/nowiki/doubleUnderscore.d.ts +1 -0
- package/dist/src/nowiki/doubleUnderscore.js +2 -0
- package/dist/util/diff.js +1 -1
- package/dist/util/lint.js +31 -1
- package/i18n/zh-hans.json +1 -0
- package/i18n/zh-hant.json +1 -0
- package/package.json +6 -2
package/dist/base.d.mts
CHANGED
|
@@ -239,6 +239,13 @@ export interface LanguageService {
|
|
|
239
239
|
* @param text source Wikitext / 源代码
|
|
240
240
|
*/
|
|
241
241
|
provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
|
|
242
|
+
/**
|
|
243
|
+
* Set the target Wikipedia
|
|
244
|
+
*
|
|
245
|
+
* 设置目标维基百科
|
|
246
|
+
* @param wiki Wikipedia URL / 维基百科网址
|
|
247
|
+
*/
|
|
248
|
+
setTargetWikipedia(wiki: string): Promise<void>;
|
|
242
249
|
}
|
|
243
250
|
export interface Parser {
|
|
244
251
|
config: Config | string;
|
|
@@ -247,8 +254,9 @@ export interface Parser {
|
|
|
247
254
|
* Get the current parser configuration
|
|
248
255
|
*
|
|
249
256
|
* 获取当前的解析设置
|
|
257
|
+
* @param config unprocessed parser configuration / 未处理的解析设置
|
|
250
258
|
*/
|
|
251
|
-
getConfig(): Config;
|
|
259
|
+
getConfig(config?: Config): Config;
|
|
252
260
|
/**
|
|
253
261
|
* Parse wikitext
|
|
254
262
|
*
|
package/dist/base.d.ts
CHANGED
|
@@ -239,6 +239,13 @@ export interface LanguageService {
|
|
|
239
239
|
* @param text source Wikitext / 源代码
|
|
240
240
|
*/
|
|
241
241
|
provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
|
|
242
|
+
/**
|
|
243
|
+
* Set the target Wikipedia
|
|
244
|
+
*
|
|
245
|
+
* 设置目标维基百科
|
|
246
|
+
* @param wiki Wikipedia URL / 维基百科网址
|
|
247
|
+
*/
|
|
248
|
+
setTargetWikipedia(wiki: string): Promise<void>;
|
|
242
249
|
}
|
|
243
250
|
export interface Parser {
|
|
244
251
|
config: Config | string;
|
|
@@ -247,8 +254,9 @@ export interface Parser {
|
|
|
247
254
|
* Get the current parser configuration
|
|
248
255
|
*
|
|
249
256
|
* 获取当前的解析设置
|
|
257
|
+
* @param config unprocessed parser configuration / 未处理的解析设置
|
|
250
258
|
*/
|
|
251
|
-
getConfig(): Config;
|
|
259
|
+
getConfig(config?: Config): Config;
|
|
252
260
|
/**
|
|
253
261
|
* Parse wikitext
|
|
254
262
|
*
|
package/dist/bin/config.js
CHANGED
|
@@ -8,64 +8,69 @@ const path_1 = __importDefault(require("path"));
|
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const assert_1 = __importDefault(require("assert"));
|
|
10
10
|
const cm_1 = require("@bhsd/common/dist/cm");
|
|
11
|
-
const { argv } = process, [, , site, , force, old] = argv;
|
|
12
|
-
let [, , , url] = argv;
|
|
13
|
-
if (!site || !url) {
|
|
14
|
-
console.error('Usage: npx getParserConfig <site> <script path> [force]');
|
|
15
|
-
process.exit(1);
|
|
16
|
-
}
|
|
17
|
-
else if (/(?:\.php|\/)$/u.test(url)) {
|
|
18
|
-
url = url.slice(0, url.lastIndexOf('/'));
|
|
19
|
-
}
|
|
20
|
-
let mwConfig;
|
|
21
|
-
const mw = {
|
|
22
|
-
loader: {
|
|
23
|
-
/** @ignore */
|
|
24
|
-
impl(callback) {
|
|
25
|
-
Object.entries(callback()[1].files).find(([k]) => k.endsWith('.data.js'))[1]();
|
|
26
|
-
},
|
|
27
|
-
/** @ignore */
|
|
28
|
-
implement(_, callback) {
|
|
29
|
-
callback();
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
config: {
|
|
33
|
-
/** @ignore */
|
|
34
|
-
set({ extCodeMirrorConfig }) {
|
|
35
|
-
mwConfig = extCodeMirrorConfig;
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
11
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
12
|
+
* Get the parser configuration for a Wikimedia Foundation project.
|
|
13
|
+
* @param site site nickname
|
|
14
|
+
* @param url script path
|
|
15
|
+
* @param force whether to overwrite the existing configuration
|
|
16
|
+
* @param old whether to target an older version of MediaWiki
|
|
43
17
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
18
|
+
exports.default = async (site, url, force, old) => {
|
|
19
|
+
if (!site || !url) {
|
|
20
|
+
console.error('Usage: npx getParserConfig <site> <script path> [force]');
|
|
21
|
+
process.exit(1);
|
|
49
22
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
23
|
+
else if (/(?:\.php|\/)$/u.test(url)) {
|
|
24
|
+
url = url.slice(0, url.lastIndexOf('/'));
|
|
25
|
+
}
|
|
26
|
+
let mwConfig;
|
|
27
|
+
const mw = {
|
|
28
|
+
loader: {
|
|
29
|
+
/** @ignore */
|
|
30
|
+
impl(callback) {
|
|
31
|
+
Object.entries(callback()[1].files).find(([k]) => k.endsWith('.data.js'))[1]();
|
|
32
|
+
},
|
|
33
|
+
/** @ignore */
|
|
34
|
+
implement(_, callback) {
|
|
35
|
+
callback();
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
config: {
|
|
39
|
+
/** @ignore */
|
|
40
|
+
set({ extCodeMirrorConfig }) {
|
|
41
|
+
mwConfig = extCodeMirrorConfig;
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Converts an array to an object.
|
|
47
|
+
* @param config parser configuration
|
|
48
|
+
* @param config.articlePath article path
|
|
49
|
+
*/
|
|
50
|
+
const arrToObj = ({ articlePath, ...obj }) => {
|
|
51
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
52
|
+
if (Array.isArray(v) && v.every(x => typeof x === 'string')) {
|
|
53
|
+
Object.assign(obj, { [k]: Object.fromEntries(v.map(x => [x, true])) });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return obj;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Gets the aliases of magic words.
|
|
60
|
+
* @param magicwords magic words
|
|
61
|
+
* @param targets magic word names
|
|
62
|
+
*/
|
|
63
|
+
const getAliases = (magicwords, targets) => magicwords
|
|
64
|
+
.filter(({ name }) => targets.has(name))
|
|
65
|
+
.flatMap(({ aliases }) => aliases.map(s => s.replace(/:$/u, '').toLowerCase()));
|
|
66
|
+
/**
|
|
67
|
+
* Filters out gadget-related namespaces.
|
|
68
|
+
* @param id namespace ID
|
|
69
|
+
*/
|
|
70
|
+
const filterGadget = (id) => {
|
|
71
|
+
const n = Number(id);
|
|
72
|
+
return n < 2300 || n > 2303; // Gadget, Gadget talk, Gadget definition, Gadget definition talk
|
|
73
|
+
};
|
|
69
74
|
const m = await (await fetch(`${url}/load.php?modules=ext.CodeMirror${old ? '.data' : ''}`)).text(), params = {
|
|
70
75
|
action: 'query',
|
|
71
76
|
meta: 'siteinfo',
|
|
@@ -109,4 +114,5 @@ const filterGadget = (id) => {
|
|
|
109
114
|
if (force || !exists) {
|
|
110
115
|
fs_1.default.writeFileSync(file, `${JSON.stringify(config, null, '\t')}\n`);
|
|
111
116
|
}
|
|
112
|
-
|
|
117
|
+
return config;
|
|
118
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -26,9 +26,9 @@ const Parser = {
|
|
|
26
26
|
i18n: undefined,
|
|
27
27
|
rules: base_1.rules,
|
|
28
28
|
/** @implements */
|
|
29
|
-
getConfig() {
|
|
29
|
+
getConfig(config) {
|
|
30
30
|
/* NOT FOR BROWSER ONLY */
|
|
31
|
-
if (typeof this.config === 'string') {
|
|
31
|
+
if (!config && typeof this.config === 'string') {
|
|
32
32
|
this.config = rootRequire(this.config, 'config');
|
|
33
33
|
/* istanbul ignore if */
|
|
34
34
|
if (this.config.doubleUnderscore.length < 3 || Array.isArray(this.config.parserFunction[1])) {
|
|
@@ -37,14 +37,14 @@ const Parser = {
|
|
|
37
37
|
return this.getConfig();
|
|
38
38
|
}
|
|
39
39
|
/* NOT FOR BROWSER ONLY END */
|
|
40
|
-
const { doubleUnderscore } =
|
|
40
|
+
const parserConfig = config ?? this.config, { doubleUnderscore } = parserConfig;
|
|
41
41
|
for (let i = 0; i < 2; i++) {
|
|
42
42
|
if (doubleUnderscore.length > i + 2 && doubleUnderscore[i].length === 0) {
|
|
43
43
|
doubleUnderscore[i] = Object.keys(doubleUnderscore[i + 2]);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
return {
|
|
47
|
-
...
|
|
47
|
+
...parserConfig,
|
|
48
48
|
excludes: [],
|
|
49
49
|
};
|
|
50
50
|
},
|
package/dist/lib/lsp.d.ts
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import Parser from '../index';
|
|
2
2
|
import type { Range, Position, ColorInformation, ColorPresentation, FoldingRange, DocumentLink, Location, WorkspaceEdit, Diagnostic as DiagnosticBase, TextEdit, Hover, SignatureHelp, InlayHint, CodeAction, DocumentSymbol } from 'vscode-languageserver-types';
|
|
3
|
-
import type { LanguageService as LanguageServiceBase, CompletionItem, SignatureData } from '../base';
|
|
4
|
-
import type { AttributeToken } from '../internal';
|
|
3
|
+
import type { Config, LanguageService as LanguageServiceBase, CompletionItem, SignatureData } from '../base';
|
|
4
|
+
import type { Token, AttributeToken } from '../internal';
|
|
5
5
|
export interface QuickFixData extends TextEdit {
|
|
6
6
|
title: string;
|
|
7
7
|
fix: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare const tasks: WeakMap<object, Parser.LanguageService>;
|
|
10
|
+
/**
|
|
11
|
+
* Check if a token is a plain attribute.
|
|
12
|
+
* @param token
|
|
13
|
+
* @param token.type
|
|
14
|
+
* @param token.parentNode
|
|
15
|
+
* @param token.length
|
|
16
|
+
* @param token.firstChild
|
|
17
|
+
* @param style whether it is a style attribute
|
|
18
|
+
*/
|
|
19
|
+
export declare const isAttr: ({ type, parentNode, length, firstChild }: Token, style?: boolean) => boolean | undefined;
|
|
10
20
|
/** VSCode-style language service */
|
|
11
21
|
export declare class LanguageService implements LanguageServiceBase {
|
|
12
22
|
#private;
|
|
13
23
|
include: boolean;
|
|
14
24
|
lilypond: string;
|
|
15
|
-
lilypondData: string[];
|
|
16
25
|
/** @param uri 任务标识 */
|
|
17
26
|
constructor(uri: object);
|
|
18
27
|
/** @implements */
|
|
@@ -133,4 +142,12 @@ export declare class LanguageService implements LanguageServiceBase {
|
|
|
133
142
|
* @param text source Wikitext / 源代码
|
|
134
143
|
*/
|
|
135
144
|
provideDocumentSymbols(text: string): Promise<DocumentSymbol[]>;
|
|
145
|
+
/**
|
|
146
|
+
* Set the target Wikipedia
|
|
147
|
+
*
|
|
148
|
+
* 设置目标维基百科
|
|
149
|
+
* @param wiki Wikipedia URL / 维基百科网址
|
|
150
|
+
* @throws `RangeError` 不是有效的维基百科网址
|
|
151
|
+
*/
|
|
152
|
+
setTargetWikipedia(wiki: string): Promise<void>;
|
|
136
153
|
}
|