Skip to content
Closed
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
85 changes: 54 additions & 31 deletions src/cli/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,8 @@ function cli(api) {
* @param {Object} options for processing
* @return {Number} exit code
*/
function processFile(relativeFilePath, options) {
var input = api.readFile(relativeFilePath),
ruleset = filterRules(options),
function processFile(relativeFilePath, input, options) {
var ruleset = filterRules(options),
result = CSSLint.verify(input, gatherRules(options, ruleset)),
formatter = CSSLint.getFormatter(options.format || "text"),
messages = result.messages || [],
Expand All @@ -154,8 +153,6 @@ function cli(api) {
}
exitCode = 1;
} else {
//var relativeFilePath = getRelativePath(api.getWorkingDirectory(), fullFilePath);
options.fullPath = api.getFullPath(relativeFilePath);
output = formatter.formatResults(result, relativeFilePath, options);
if (output) {
api.print(output);
Expand Down Expand Up @@ -214,42 +211,66 @@ function cli(api) {
*/
function processFiles(fileArray, options) {
var exitCode = 0,
formatId = options.format || "text",
formatter,
files = filterFiles(fileArray, options),
output;
files = filterFiles(fileArray, options);

if (!files.length) {
api.print("csslint: No files specified.");
exitCode = 1;
} else {
if (!CSSLint.hasFormat(formatId)) {
api.print("csslint: Unknown format '" + formatId + "'. Cannot proceed.");
exitCode = 1;
} else {
formatter = CSSLint.getFormatter(formatId);
files.forEach(function(file){
var input = api.readFile(file),
newExitCode = 0;

options.fullPath = api.getFullPath(file);
newExitCode = processFile(file, input, options);

output = formatter.startFormat();
if (output) {
api.print(output);
if (exitCode === 0) {
exitCode = newExitCode;
}
});
}

return exitCode;
}

files.forEach(function(file) {
if (exitCode === 0) {
exitCode = processFile(file, options);
} else {
processFile(file, options);
}
});

output = formatter.endFormat();
if (output) {
api.print(output);
}
function processInput(argCount, options, cb){
var exitCode = 0,
formatId = options.format || "text",
formatter,
output;

function exit(newExitCode) {
output = formatter.endFormat();
if (output){
api.print(output);
}
cb(newExitCode);
}

if (!CSSLint.hasFormat(formatId)){
api.print("csslint: Unknown format '" + formatId + "'. Cannot proceed.");
exitCode = 1;
cb(exitCode);
} else {
formatter = CSSLint.getFormatter(formatId);

output = formatter.startFormat();
if (output){
api.print(output);
}

if (argCount !== 0) {
exitCode = processFiles(options.files, options);
exit(exitCode);
} else {
api.readStdin(function (input) {
var exitCode = processFile("<stdin>", input, options);
exit(exitCode);
});
}

}
return exitCode;
}


Expand Down Expand Up @@ -346,7 +367,7 @@ function cli(api) {
// Preprocess command line arguments
cliOptions = processArguments(args);

if (cliOptions.help || argCount === 0) {
if (cliOptions.help) {
outputHelp();
api.quit(0);
}
Expand Down Expand Up @@ -374,5 +395,7 @@ function cli(api) {
// Validate options
validateOptions(options);

api.quit(processFiles(options.files, options));
processInput(argCount, options, function (exitCode) {
api.quit(exitCode);
});
}
20 changes: 20 additions & 0 deletions src/cli/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ cli({
fs.writeSync(1, message + "\n");
},

readStdin: function(cb) {
var data = "";
process.stdin.setEncoding("utf-8");
process.stdin.on("readable", function () {
var closed = false,
chunk;
while (!closed) {
chunk = process.stdin.read();
if (chunk !== null) {
data += chunk;
} else {
closed = true;
}
}
});
process.stdin.on("end", function () {
cb(data);
});
},

quit: function(code) {
process.exit(code || 0);
},
Expand Down
23 changes: 21 additions & 2 deletions src/cli/rhino.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
*/

/* jshint rhino:true */
/* global cli, File */
/* global cli, File, System, BufferedReader, InputStreamReader */

importPackage(java.lang);
importPackage(java.io);

cli({
Expand Down Expand Up @@ -56,5 +57,23 @@ cli({
} catch (ex) {
return "";
}
},

readStdin: function(cb) {
"use strict";
var data = "",
closed = false,
chunk,
isr = new InputStreamReader(System["in"]),
br = new BufferedReader(isr);
while (!closed) {
chunk = br.readLine();
if (chunk !== null) {
data += chunk;
} else {
closed = true;
}
}
cb(data);
}
});
});
4 changes: 4 additions & 0 deletions src/cli/wsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ var wshapi = (function() {
return "";
}
return allText;
},

readStdin: function(cb) {
cb(WScript.StdIn.ReadAll());
}
};

Expand Down