eslint-plugin-userscripts
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -31,2 +31,3 @@ module.exports = { | ||
let end = {}; | ||
for (const comment of comments.filter( | ||
@@ -39,13 +40,23 @@ (comment) => comment.type === 'Line' | ||
const commentValue = comment.value.trim(); | ||
// istanbul ignore else | ||
if (inMetadata && comment.value.trim() === '==/UserScript==') { | ||
if (inMetadata && commentValue === '==/UserScript==') { | ||
end = comment.loc.end; | ||
done = true; | ||
} else if (!inMetadata && comment.value.trim() === '==UserScript==') { | ||
} else if (!inMetadata && commentValue === '==UserScript==') { | ||
start = comment.loc.start; | ||
inMetadata = true; | ||
} else if (inMetadata && comment.value.trim().startsWith('@')) { | ||
} else if (inMetadata && commentValue.startsWith('@')) { | ||
// Get space string between key and value | ||
const [, spaceString] = /^\S*(\s*)/.exec(commentValue.slice(1)); | ||
// Keys w/o value must not be validated | ||
if (spaceString.length === 0) { | ||
continue; | ||
} | ||
metadata.push({ | ||
key: comment.value.trim().slice(1).split(/\s/)[0], | ||
space: /^\S*(\s+)/.exec(comment.value.trim().slice(1))[1].length, | ||
key: commentValue.slice(1).split(/\s/)[0], | ||
space: spaceString.length, | ||
line: comment.loc.start.line, | ||
@@ -66,10 +77,11 @@ comment | ||
const totalSpacing = | ||
Math.max(...metadata.map((metadatapoint) => metadatapoint.key.length)) + | ||
spacing; | ||
Math.max(...metadata.map(({ key }) => key.length)) + spacing; | ||
const hasSpaceLessThenSpacing = | ||
metadata.map(({ space }) => space).sort()[0] < spacing; | ||
if ( | ||
metadata.map((metadatapoint) => metadatapoint.space).sort()[0] < | ||
spacing || | ||
hasSpaceLessThenSpacing || | ||
metadata | ||
.map((metadatapoint) => metadatapoint.key.length + metadatapoint.space) | ||
.map(({ key, space }) => key.length + space) | ||
.some((val) => val !== totalSpacing) | ||
@@ -76,0 +88,0 @@ ) { |
@@ -30,3 +30,4 @@ const createValidator = require('../utils/createValidator'); | ||
), | ||
cleanupRange(foundAssertion.versionConstraint) | ||
cleanupRange(foundAssertion.versionConstraint), | ||
true | ||
) | ||
@@ -33,0 +34,0 @@ : false |
@@ -49,3 +49,4 @@ const createValidator = require('../utils/createValidator'); | ||
), | ||
cleanupRange(foundAssertion.versionConstraint) | ||
cleanupRange(foundAssertion.versionConstraint), | ||
true | ||
) | ||
@@ -52,0 +53,0 @@ : false |
{ | ||
"name": "eslint-plugin-userscripts", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Implements rules for userscripts metadata in eslint", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"markdownlint-cli": "^0.31.0", | ||
"mocha": "^9.0.3", | ||
"mocha": "^10.0.0", | ||
"nyc": "^15.1.0", | ||
@@ -35,0 +35,0 @@ "prettier": "^2.4.1", |
57596
1590