Skip to content

Latest commit

 

History

History
239 lines (179 loc) · 4.53 KB

compat-grant.md

File metadata and controls

239 lines (179 loc) · 4.53 KB

compat-grant

The compat-grant rule verifies that your @grant declarations are compatible with your target userscript managers.

Why?

Ensures that you aren't using permissions that you don't support or don't want to support.

Settings

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.

Optionally, you may also include a userscriptGrantCompatabilityOverrides property that contains compatability data overrides. The property is a group of key-value pairs with the key being the grant and the value being an object with a versions property (for more info see lib/data/compat-grant.js) and a deps property (depending grants).

Options

This rule has an object option with the following properties:

  • "requireAllCompatible" (default: false) requires that all configured userscript managers support the grant permission used
  • "gmPolyfill" (default: false) use compatability overrides for the greasemonkey 4 polyfill.

Examples

requireAllCompatible: false

👍 Examples of correct code for this rule

/* eslint userscripts/compat-grant: ["error", { "requireAllCompatible": false }] */

// ==UserScript==
// @grant         GM.openInTab
// @grant         GM_openInTab
// @downloadURL   example.com
// ==/UserScript==

/* My code adapted for async and sync openInTab */
Show Settings
{
  "userscriptVersions": {
    "tampermonkey": ">3 <4",
    "greasemonkey": ">4"
  }
}
/* eslint userscripts/compat-grant: ["error", { "requireAllCompatible": false }] */

// ==UserScript==
// @grant      unsafeWindow
// @grant      GM.listValues
// ==/UserScript==
Show Settings
{
  "userscriptVersions": {
    "tampermonkey": ">3 <4",
    "greasemonkey": ">4"
  }
}

👎︎ Examples of incorrect code for this rule

/* eslint userscripts/compat-grant: ["error", { "requireAllCompatible": false }] */

// ==UserScript==
// @name   my script name
// @grant  example.com
// ==/UserScript==
Show Settings
{
  "userscriptVersions": {
    "tampermonkey": ">3 <4",
    "greasemonkey": ">4"
  }
}
/* eslint userscripts/compat-grant: ["error", { "requireAllCompatible": false }] */

// ==UserScript==
// @grant   GM.getValue
// ==/UserScript==
Show Settings
{
  "userscriptVersions": {
    "tampermonkey": "<4" // GM.* is only supported 4.5 and above for tampermonkey
  }
}

requireAllCompatible: true

👍 Examples of correct code for this rule

/* eslint userscripts/compat-grant: "error" */

// ==UserScript==
// @grant   GM.getValue
// @grant   GM.deleteValue
// ==/UserScript==
Show Settings
{
  "userscriptVersions": {
    "tampermonkey": ">4.5",
    "violentmonkey": "*",
    "greasemonkey": ">=4.1"
  }
}
/* eslint userscripts/compat-grant: "error" */

// ==UserScript==
// @grant GM.log
// @grant  GM_log
// ==/UserScript==
Show Settings
{
  "userscriptVersions": {
    "tampermonkey": ">4.5",
    "violentmonkey": "*",
    "greasemonkey": ">=4.1"
  }
}

👎︎ Examples of incorrect code for this rule

/* eslint userscripts/compat-grant: "error" */

// ==UserScript==
// @grant      GM.log
// ==/UserScript==
Show Settings
{
  "userscriptVersions": {
    "tampermonkey": ">4.5",
    "violentmonkey": "<=2.13.0", // As of 2.13.0, GM.log is not supported
    "greasemonkey": ">=4.1"
  }
}
/* eslint userscripts/compat-grant: "error" */

// ==UserScript==
// @grant   GM_webRequest
// ==/UserScript==
Show Settings
{
  "userscriptVersions": {
    "tampermonkey": ">4.5", // GM_webRequest is TamperMonkey specific
    "violentmonkey": "<=2.13.0",
    "greasemonkey": ">=4.1"
  }
}

When Not to Use It

When you are aware of your compatability and/or support a limited number of userscript managers.