eslint-plugin-qml-js
Advanced tools
Comparing version 0.0.4 to 0.1.0
'use strict'; | ||
function makePathRelative(p) { | ||
var delimiter = p[0]; | ||
// Remove delimiters | ||
p = p.slice(1, -1); | ||
// Add ./ if necessary | ||
if (p[0] !== '.') { | ||
p = `./${p}`; | ||
} | ||
return `${delimiter}${p}${delimiter}`; | ||
} | ||
module.exports.processors = { | ||
".js": { | ||
preprocess: function(text, filename) { | ||
// Ignore QML head lines and transform JS import in CommonJS require | ||
text = text | ||
.replace(/^\.import (['"])([^'"]+\.js)(['"]) as (.+)$/mg, 'var $4 = require($1./$2$3);') | ||
.replace(/^\.(pragma|import).*$/mg, '\/* Ignored QML */'); | ||
preprocess: function(text) { | ||
text = text.replace(/^\.import .+$/gm, function (line) { | ||
var parts = line.split(' '); | ||
// Importing QML modules implies having 5 elements | ||
if (parts.length < 5) { | ||
return `var ${parts[3]} = require(${makePathRelative(parts[1])});`; | ||
} | ||
return `var ${parts[4]} = {};`; | ||
}) | ||
text = text.replace(/^\.pragma.*$/gm, '// Ignored QML'); | ||
return [text]; | ||
}, | ||
postprocess: function(messages, filename) { | ||
postprocess: function(messages) { | ||
// Do nothing | ||
@@ -16,0 +37,0 @@ return messages[0]; |
{ | ||
"name": "eslint-plugin-qml-js", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "Parse JS files in a QtQML project", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3364
31
5
1