eslint-plugin-userscripts
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -207,2 +207,51 @@ // Documentation: | ||
module.exports = compatMap; | ||
const gmPolyfillOverride = { | ||
GM_addStyle: 'ignore', | ||
GM_registerMenuCommand: 'ignore', | ||
GM_getResourceText: { | ||
deps: ['GM.getResourceUrl', 'GM.log'] | ||
}, | ||
'GM.log': 'ignore', | ||
'GM.info': { | ||
deps: ['GM_info'] | ||
}, | ||
'GM.addStyle': { | ||
deps: ['GM_addStyle'] | ||
}, | ||
'GM.deleteValue': { | ||
deps: ['GM_deleteValue'] | ||
}, | ||
'GM.getResourceUrl': { | ||
deps: ['GM_getResourceURL'] | ||
}, | ||
'GM.getValue': { | ||
deps: ['GM_getValue'] | ||
}, | ||
'GM.listValues': { | ||
deps: ['GM_listValues'] | ||
}, | ||
'GM.notification': { | ||
deps: ['GM_notification'] | ||
}, | ||
'GM.openInTab': { | ||
deps: ['GM_openInTab'] | ||
}, | ||
'GM.registerMenuCommand': { | ||
deps: ['GM_registerMenuCommand'] | ||
}, | ||
'GM.setClipboard': { | ||
deps: ['GM_setClipboard'] | ||
}, | ||
'GM.setValue': { | ||
deps: ['GM_setValue'] | ||
}, | ||
'GM.xmlHttpRequest': { | ||
deps: ['GM_xmlhttpRequest'] | ||
}, | ||
'GM.getResourceText': { | ||
deps: ['GM_getResourceText'] | ||
} | ||
}; | ||
module.exports.compatMap = compatMap; | ||
module.exports.gmPolyfillOverride = gmPolyfillOverride; |
const createValidator = require('../utils/createValidator'); | ||
const compatMap = require('../data/compat-grant'); | ||
const { compatMap, gmPolyfillOverride } = require('../data/compat-grant'); | ||
const { intersects } = require('semver'); | ||
@@ -17,11 +17,64 @@ const cleanupRange = require('../utils/cleanupRange'); | ||
context.options[0] && context.options[0].requireAllCompatible; | ||
const overrides = | ||
context.settings.userscriptGrantCompatabilityOverrides || {}; | ||
const gmPolyfill = context.options[0] && context.options[0].gmPolyfill; | ||
const gmPolyfillFallback = | ||
gmPolyfill && gmPolyfillOverride[requestedGrant] | ||
? gmPolyfillOverride[requestedGrant] | ||
: compatMap[requestedGrant]; | ||
if (overrides[requestedGrant] === 'ignore') { | ||
return; | ||
} | ||
const supports = []; | ||
if (compatMap[requestedGrant]) { | ||
function doesSupport(givenGrant) { | ||
let compatValue = | ||
overrides[givenGrant] || | ||
(gmPolyfill && gmPolyfillOverride[givenGrant] | ||
? gmPolyfillOverride[givenGrant] | ||
: compatMap[givenGrant]); | ||
console.log( | ||
requestedGrant, | ||
givenGrant, | ||
gmPolyfill, | ||
gmPolyfillFallback, | ||
compatValue | ||
); | ||
if (compatValue === 'ignore') { | ||
return; | ||
} | ||
if (compatValue.deps) { | ||
for (const overrideDep of compatValue.deps) { | ||
doesSupport(overrideDep); | ||
} | ||
if (compatValue.versions) { | ||
compatValue = compatValue.versions; | ||
} else { | ||
return; | ||
} | ||
} | ||
if (!Array.isArray(compatValue)) { | ||
if (compatValue.versions) { | ||
compatValue = compatValue.versions; | ||
} else { | ||
return; | ||
} | ||
} | ||
for (const versionConstraint in context.settings.userscriptVersions) { | ||
const foundAssertion = compatMap[requestedGrant].find( | ||
const foundAssertion = compatValue.find( | ||
(constraint) => constraint.type === versionConstraint | ||
); | ||
const secondAssertionFound = | ||
compatMap[givenGrant] && | ||
compatMap[givenGrant].find( | ||
(constraint) => constraint.type === versionConstraint | ||
); | ||
supports.push( | ||
foundAssertion | ||
(foundAssertion | ||
? intersects( | ||
@@ -34,3 +87,14 @@ cleanupRange( | ||
) | ||
: false | ||
: false) || | ||
(gmPolyfill && | ||
gmPolyfillOverride[givenGrant] && | ||
secondAssertionFound | ||
? intersects( | ||
cleanupRange( | ||
context.settings.userscriptVersions[versionConstraint] | ||
), | ||
cleanupRange(secondAssertionFound.versionConstraint), | ||
true | ||
) | ||
: false) | ||
); | ||
@@ -40,2 +104,7 @@ } | ||
if (overrides[requestedGrant] || gmPolyfillFallback) { | ||
console.log(requestedGrant); | ||
doesSupport(requestedGrant); | ||
} | ||
if ( | ||
@@ -61,3 +130,3 @@ allRequired && | ||
)) || | ||
!compatMap[requestedGrant] | ||
(!gmPolyfillFallback && !overrides[requestedGrant]) | ||
) { | ||
@@ -90,2 +159,6 @@ context.report({ | ||
default: false | ||
}, | ||
gmPolyfill: { | ||
type: 'boolean', | ||
default: false | ||
} | ||
@@ -92,0 +165,0 @@ }, |
const createValidator = require('../utils/createValidator'); | ||
const compatMap = require('../data/compat-grant'); | ||
const { compatMap } = require('../data/compat-grant'); | ||
@@ -4,0 +4,0 @@ module.exports = createValidator({ |
{ | ||
"name": "eslint-plugin-userscripts", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Implements rules for userscripts metadata in eslint", | ||
@@ -27,11 +27,11 @@ "keywords": [ | ||
"eslint-plugin-eslint-comments": "^3.2.0", | ||
"eslint-plugin-eslint-plugin": "^4.0.0", | ||
"eslint-plugin-eslint-plugin": "^5.0.0", | ||
"eslint-plugin-import": "^2.24.2", | ||
"eslint-plugin-unicorn": "^43.0.0", | ||
"husky": "^8.0.1", | ||
"markdownlint-cli": "^0.31.0", | ||
"markdownlint-cli": "^0.32.0", | ||
"mocha": "^10.0.0", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.4.1", | ||
"prettier-plugin-jsdoc": "^0.3.24", | ||
"prettier-plugin-jsdoc": "^0.4.2", | ||
"should": "^13.2.3" | ||
@@ -38,0 +38,0 @@ }, |
62457
25
1757