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.ts

76 lines
2.4 KiB

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