eslint-plugin-wikitext v0.1.0
eslint-plugin-wikitext
ESLint plugin for Wikitext built upon a Node.js parser
Installation
You'll first need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-wikitext
:
npm i eslint-plugin-wikitext --save-dev
Usage
Specify the wiki file patterns, and add plugin:wikitext/base
to the extends section of your .eslintrc
configuration file:
{
"overrides": [
{
"files": "**/*.wiki", // assume wiki file extension to be ".wiki"
"extends": [
"plugin:wikitext/base"
// alternatives: "plugin:wikitext/recommended" or "plugin:wikitext/inherited"
]
}
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"wikitext/rule-name": 2
}
}
Parser Options
config
Specify the path to the parser's configuration file:
{
"parserOptions": {
// Paths are relative to the wikiparser-node module, not the working directory
// e.g., configuration for Chinese Wikipedia https://zh.wikipedia.org
"config": "./config/zhwiki"
// Check https://github.com/bhsd-harry/wikiparser-node/tree/main/config for other
// preset configurations
}
}
include
By default, the parser will ignore any code for inclusion only (i.e., <includeonly></includeonly>
). You can decide to ignore any code not for inclusion (i.e., <noinclude></noinclude>
) instead:
{
"parserOptions": {
"include": true
}
}
One recommended solution is to determine this option based on the page name:
{
"overrides": [
{
"files": "**/*.wiki", // assume wiki file extension to be ".wiki"
"extends": [
"plugin:wikitext/base"
// alternatives: "plugin:wikitext/recommended" or "plugin:wikitext/inherited"
]
},
{
// Templates conventionally have a "Template:" prefix
"files": "**/Template:*.wiki",
"parserOptions": {
"include": true
}
}
]
}
Rules
💼 Configurations enabled in.\
⚠️ Configurations set to warn in.\
🌐 Set in the inherited
configuration.\
✅ Set in the recommended
configuration.
Name | Description | 💼 | ⚠️ |
---|---|---|---|
error | errors reported by the parser | 🌐 ✅ | |
warn | warnings reported by the parser | 🌐 |
Advanced Usage
Visual Studio Code
This plugin can be used together with the ESLint extension and the Wikitext extension.
First, install and configure this plugin and the abovementioned two VS Code extensions respectively. Then add the settings below to .vscode/settings.json
:
{
"eslint.runtime": "node",
"eslint.probe": [
"wikitext"
],
"eslint.validate": [
"wikitext"
]
}
Sublime Text
This plugin can be used together with SublimeLinter-eslint and Mediawiker.
First, install and configure this plugin and the abovementioned two Sublime Text packages respectively. Then add the settings below to the package setting of SublimeLinter, which is the required dependency for SublimeLinter-eslint:
{
"linters": {
"eslint": {
// You may include other selectors for source.ts, text.html.vue, etc.
"selector": "text.html.mediawiki, source.js - meta.attribute-with-value"
}
}
}