Skip to content

bhsd-harry/eslint-plugin-wikitext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm version

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.js configuration file:

module.exports = {
	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 a preset configuration file:

{
	parserOptions: {
		// e.g., configuration for Chinese Wikipedia https://zh.wikipedia.org
		config: "zhwiki",
		// Check https://github.com/bhsd-harry/wikiparser-node/tree/main/config for other
		// preset configurations
	},
}

Or you can create your own configuration based on the schema:

{
	parserOptions: {
		config: require(PATH_TO_MY_CONFIG),
	},
}

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:

module.exports = {
	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.
🌐 Set in the inherited configuration.
✅ Set in the recommended configuration.

Name Description 💼
error errors reported by the parser
lonely-http http or https unused as a link protocol 🌐 ✅
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 Sublime​Linter-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"
		}
	}
}