Skip to content

Commit

Permalink
Fixed 'codeFilename' parameter to hold a path that can be resolved by…
Browse files Browse the repository at this point in the history
… stylelint 7.4+
  • Loading branch information
pfmmfp committed Nov 9, 2016
1 parent 8fc8cac commit 72544e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
30 changes: 25 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
var Filter = require('broccoli-persistent-filter');
var escapeString = require('js-string-escape');
var stylelint = require('stylelint');
var merge = require('merge');
var Filter = require('broccoli-persistent-filter');
var escapeString = require('js-string-escape');
var stylelint = require('stylelint');
var merge = require('merge');
var path = require('path');
var broccoliNodeInfo = require('broccoli-node-info');

function resolveInputDirectory(inputNodes) {
if (typeof inputNodes === 'string') {
return inputNodes;
}

const nodeInfo = broccoliNodeInfo.getNodeInfo(inputNodes);
if (nodeInfo.nodeType === 'source') {
return nodeInfo.sourceDirectory;
}

if (nodeInfo.inputNodes.length > 1) {
throw new Error('broccoli-stylelint can only handle one:* broccoli nodes, but part of the given input pipeline is a many:* node. (broccoli-merge-trees is an example of a many:* node) Please perform many:* operations after linting.');
}

return resolveInputDirectory(nodeInfo.inputNodes[0]);
};

/* Setup class */
StyleLinter.prototype = Object.create(Filter.prototype);
Expand Down Expand Up @@ -33,6 +52,7 @@ StyleLinter.prototype.availableOptions = [{name: 'onError'},
*/
function StyleLinter(inputNodes, options) {
this.options = options || {linterConfig:{}};
this.inputNodesDirectory = resolveInputDirectory(inputNodes);

for(var i = 0; i < this.availableOptions.length; i++){
var option = this.availableOptions[i];
Expand Down Expand Up @@ -111,7 +131,7 @@ StyleLinter.prototype.build = function() {
StyleLinter.prototype.processString = function(content, relativePath) {
var self = this;
this.linterConfig.code = content;
this.linterConfig.codeFilename = relativePath;
this.linterConfig.codeFilename = path.join(this.inputNodesDirectory, relativePath);
return stylelint.lint(this.linterConfig).then(function(results){
//sets the value to relative path otherwise it would be absolute path
results = self.processResults(results, relativePath);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
"walk-sync": "0.3.1"
},
"dependencies": {
"broccoli-node-info": "1.0.0",
"broccoli-persistent-filter": "1.2.11",
"js-string-escape": "1.0.1",
"merge": "1.2.0",
"stylelint": "7.3.0"
"stylelint": "7.5.0"
}
}

0 comments on commit 72544e3

Please sign in to comment.