The compat-headers
rule verifies that your header declarations are compatible
with your target userscript managers.
Ensures that you aren't using declarations that you don't support or don't want to support.
This rule looks for your settings provided in the eslintrc.
The settings must contain a userscriptVersions
property with the keys of tampermonkey
,
greasemonkey
, violentmonkey
(you can exclude some of them if you don't
support them) with their values being semver version constraints.
This rule has an object option with the following properties:
"requireAllCompatible"
(default:false
) requires that all configured userscript managers support the header used
👍 Examples of correct code for this rule
/* eslint userscripts/compat-headers: ["error", { "requireAllCompatible": false }] */
// ==UserScript==
// @downloadURL example.com
// ==/UserScript==
/* My code adapted for async and sync openInTab */
Show Settings
{
"userscriptVersions": {
"tampermonkey": ">3 <4",
"greasemonkey": ">4"
}
}
/* eslint userscripts/compat-headers: ["error", { "requireAllCompatible": false }] */
// ==UserScript==
// @grant unsafeWindow
// @grant GM.listValues
// ==/UserScript==
Show Settings
{
"userscriptVersions": {
"tampermonkey": ">3.1 <4",
"greasemonkey": ">4"
}
}
👎︎ Examples of incorrect code for this rule
/* eslint userscripts/compat-headers: ["error", { "requireAllCompatible": false }] */
// ==UserScript==
// @name my script name
// @grant example.com
// ==/UserScript==
Show Settings
{
"userscriptVersions": {
"greasemonkey": ">=4 <4.2" // Greasemonkey removed support for localized names/descriptions in GM4 and readded it in GM4.11
}
}
/* eslint userscripts/compat-headers: ["error", { "requireAllCompatible": false }] */
// ==UserScript==
// @exclude-match ...
// ==/UserScript==
Show Settings
{
"userscriptVersions": {
"tampermonkey": "<4" // `exclude-match` is violentmonkey only
}
}
👍 Examples of correct code for this rule
/* eslint userscripts/compat-headers: "error" */
// ==UserScript==
// @version 0.0.1
// ==/UserScript==
Show Settings
{
"userscriptVersions": {
"tampermonkey": ">4.5",
"violentmonkey": "*",
"greasemonkey": ">4"
}
}
/* eslint userscripts/compat-headers: "error" */
// ==UserScript==
// @run-at context-menu
// ==/UserScript==
Show Settings
{
"userscriptVersions": {
"tampermonkey": ">4.5",
"greasemonkey": ">=4.1"
}
}
👎︎ Examples of incorrect code for this rule
/* eslint userscripts/compat-headers: "error" */
// ==UserScript==
// @version 0.0.1
// ==/UserScript==
Show Settings
{
"userscriptVersions": {
"tampermonkey": ">4.5",
"violentmonkey": "*",
"greasemonkey": "<0.9.0" // GM supports `version` as of 0.9.0
}
}
/* eslint userscripts/compat-headers: "error" */
// ==UserScript==
// @exclude-match *
// ==/UserScript==
Show Settings
{
"userscriptVersions": {
"tampermonkey": ">4.5",
"violentmonkey": "*"
}
}
When you are aware of your compatability and/or support a limited number of userscript managers.