Build server prototype (integration with GitHub / NuGet / etc)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
micro-build-server/BuildServer/lib/tasks/dotnetcheckstyle.js

63 lines
1.8 KiB

"use strict";
const fs = require('fs');
const async = require('async');
const glob = require('glob');
const autoGeneratedMarker =
"//------------------------------------------------------------------------------" + "\n" +
"// <auto-generated>";
module.exports = (params, processor) => ({
process: () => {
if (processor.context.dotnetcheckerDone) {
return processor.done();
}
processor.context.dotnetcheckerDone = true;
glob("**/*.cs", {cwd: processor.context.exported}, (err, files) => {
if (err) {
processor.onError(err);
return processor.done();
}
processor.onInfo("Found " + files.length + " .cs files");
if (!files || !files.length) {
processor.onWarn("No .cs files found");
return processor.done();
}
return async.parallel(files.map((file) => (callback) => fs.readFile(processor.context.exported + "/" + file, { encoding: "utf8" }, (err, data) => {
if (err) {
processor.onError("Unable to check file " + file + ": " + err);
return callback(err);
}
if (data.indexOf("\r\n") >= 0) {
processor.onError("Windows-style EOL (0D0A) found in file " + file);
return callback();
}
if (params.ignoreCodeStyle) {
return callback();
}
if (data.substr(1, autoGeneratedMarker.length) === autoGeneratedMarker || data.substr(0, autoGeneratedMarker.length) === autoGeneratedMarker) {
processor.onInfo("Skipping auto-generated file " + file);
return callback();
}
if (data.indexOf("\t") >= 0 && data.indexOf(" ") >= 0) {
processor.onError("Both tabs and spaces found in file " + file);
}
if (data.indexOf("\t") >= 0) {
processor.onError("Tabs found in file " + file);
}
processor.onInfo("Checked file " + file);
callback();
})), processor.done.bind(processor));
});
}
});