Run appropriate linters

This commit is contained in:
Slava Kim
2015-04-20 10:06:21 -07:00
committed by David Glasser
parent 7d7a64e921
commit 986b7a62ee
4 changed files with 46 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ JsHintLinter.prototype.processFilesForTarget = function (files) {
return;
}
// require configuration file to be called '.jshintrc'
if (path.extname(file.getBaseName()) !== 'js') {
if (path.extname(file.getBasename()) !== 'js') {
file.error("Unrecognized configuration file name. Configuration file should be called .jshintrc");
return;
}

View File

@@ -1,6 +1,7 @@
var archinfo = require('./archinfo.js');
var buildmessage = require('./buildmessage.js');
var files = require('./files.js');
var buildmessage = require('./buildmessage.js');
var _ = require('underscore');
exports.BuildPluginDefintion = function (options, factoryFunction) {

View File

@@ -11,6 +11,7 @@ var watch = require('./watch.js');
var Console = require('./console.js').Console;
var files = require('./files.js');
var colonConverter = require('./colon-converter.js');
var linterPluginModule = require('./linter-plugin.js');
var compiler = exports;
@@ -395,8 +396,43 @@ var compileUnibuild = function (options) {
};
});
// For each file choose the longest extension handled by linters.
var longestMatchingExt = {};
_.each(wrappedSourceItems, function (wrappedSource) {
var filename = files.pathBasename(wrappedSource.relPath);
var parts = filename.split('.');
for (var i = 1; i < parts.length; i++) {
var extension = parts.slice(i).join('.');
if (_.has(linterPluginsByExtension, extension)) {
longestMatchingExt[wrappedSource.relPath] = extension;
break;
}
}
});
// Run linters on files.
_.each(linterPluginsByExtension, function (linters, ext) {
// XXX would run linters here
var sourcesToLint = [];
_.each(wrappedSourceItems, function (wrappedSource) {
var relPath = wrappedSource.relPath;
var hash = wrappedSource.hash;
var fileWatchSet = wrappedSource.watchset;
var source = wrappedSource.source;
// only run linters matching the longest handled extension
if (longestMatchingExt[relPath] !== ext)
return;
sourcesToLint.push(new linterPluginModule.LintingFile(wrappedSource));
});
_.each(linters, function (linterDef) {
// skip linters not relevant to the arch we are compiling for
if (! linterDef.relevantForArch(inputSourceArch.arch))
return;
var linter = linterDef.instantiatePlugin();
linter.run(sourcesToLint);
});
});
_.each(wrappedSourceItems, function (wrappedSource) {

View File

@@ -8,10 +8,15 @@ exports.LinterPlugin = function (pluginDefinition, userPlugin) {
self.pluginDefinition = pluginDefinition;
};
_.extend(exports.LinterPlugin.prototype, {
run: function () {}
run: function (lintingFiles) {
var self = this;
self.userPlugin.processFilesForTarget(lintingFiles);
}
});
var LintingFile = function (source) {
var LintingFile = exports.LintingFile = function (source) {
buildPluginModule.InputFile.call(this);
var self = this;
self._source = source;
};