eslint-plugin-userscripts
Advanced tools
Comparing version 0.2.4 to 0.2.5
const parse = require('../utils/parse'); | ||
/** @type {import('eslint').Rule.RuleModule} */ | ||
module.exports = { | ||
@@ -10,3 +11,4 @@ meta: { | ||
category: 'Best Practices' | ||
} | ||
}, | ||
fixable: 'whitespace' | ||
}, | ||
@@ -17,14 +19,31 @@ create: (context) => { | ||
if ( | ||
result.enteredMetadata !== -1 && | ||
result.end && | ||
sourceCode.lines.length !== | ||
result.lines[result.lines.length - 1].lineLoc.end.line && | ||
sourceCode.lines[ | ||
result.lines[result.lines.length - 1].lineLoc.end.line | ||
].trim().length > 0 | ||
) { | ||
const hasMetadata = result.enteredMetadata !== -1 && result.end; | ||
if (!hasMetadata) { | ||
return {}; | ||
} | ||
const metadataLastLineLoc = result.lines[result.lines.length - 1].lineLoc; | ||
const hasCodeOtherThanMetadata = | ||
sourceCode.lines.length !== metadataLastLineLoc.end.line; | ||
if (!hasCodeOtherThanMetadata) { | ||
return {}; | ||
} | ||
const lineNextToMetadata = sourceCode.lines[metadataLastLineLoc.end.line]; | ||
if (lineNextToMetadata.trim().length > 0) { | ||
context.report({ | ||
message: 'There should be a newline between the metadata and the code', | ||
loc: result.lines[result.lines.length - 1].lineLoc | ||
loc: metadataLastLineLoc, | ||
fix: function (fixer) { | ||
const range = [ | ||
sourceCode.getIndexFromLoc(metadataLastLineLoc.start), | ||
sourceCode.getIndexFromLoc(metadataLastLineLoc.end) | ||
]; | ||
return fixer.insertTextAfterRange(range, '\n'); | ||
} | ||
}); | ||
@@ -31,0 +50,0 @@ } |
{ | ||
"name": "eslint-plugin-userscripts", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Implements rules for userscripts metadata in eslint", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"eslint-plugin-unicorn": "^42.0.0", | ||
"husky": "^7.0.2", | ||
"husky": "^8.0.1", | ||
"markdownlint-cli": "^0.31.0", | ||
@@ -33,0 +33,0 @@ "mocha": "^10.0.0", |
58117
1602