Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed 'codeFilename' parameter to hold a path that can be resolved by… #22

Merged
merged 1 commit into from
Nov 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}