Fix bugs with running linters and passing imports

This commit is contained in:
Slava Kim
2015-04-20 17:04:51 -07:00
committed by David Glasser
parent bf04ffa169
commit aaa9e606d4
2 changed files with 46 additions and 27 deletions

View File

@@ -38,10 +38,19 @@ JsHintLinter.prototype.processFilesForTarget = function (files, globals) {
}
});
// JSHint has a particular format for defining globals. `false` means that the
// global is not allowed to be redefined. `true` means it is allowed to be
// redefined. Since the passed imports are probably not great for definition,
// mark them as false.
var predefinedGlobals = {};
globals.forEach(function (symbol) {
predefinedGlobals[symbol] = false;
});
files.forEach(function (file) {
if (file.getBasename() === '.jshintrc')
return;
if (! jshint(file.getContentsAsString(), conf, globals)) {
if (! jshint(file.getContentsAsString(), conf, predefinedGlobals)) {
jshint.errors.forEach(function (error) {
file.error({
message: error.reason,

View File

@@ -232,7 +232,7 @@ var compileUnibuild = function (options) {
// XXX BBP redoc
var allHandlersWithPkgs = {};
var compilerPluginsByExtension = {};
var linterPluginsByExtension = {};
var allLinters = [];
var sourceExtensions = {}; // maps source extensions to isTemplate
sourceExtensions['js'] = false;
@@ -310,12 +310,8 @@ var compileUnibuild = function (options) {
});
});
// Iterate over the linters
_.each(otherPkg.sourceProcessors.linter, function (linterPlugin, id) {
_.each(linterPlugin.extensions, function (ext) {
linterPluginsByExtension[ext] = linterPluginsByExtension[ext] || [];
linterPluginsByExtension[ext].push(linterPlugin);
});
allLinters.push(linterPlugin);
});
});
@@ -396,7 +392,7 @@ var compileUnibuild = function (options) {
};
});
runLinters(inputSourceArch, isopackCache, wrappedSourceItems, linterPluginsByExtension);
runLinters(inputSourceArch, isopackCache, wrappedSourceItems, allLinters);
_.each(wrappedSourceItems, function (wrappedSource) {
var source = wrappedSource.source;
@@ -952,10 +948,15 @@ var runLinters = function (
inputSourceArch,
isopackCache,
wrappedSourceItems,
linterPluginsByExtension) {
linters) {
// For linters, figure out what are the global imports from other packages
// that we use directly, or are implied.
var globalImports = ['Package', 'Assets', 'Npm'];
var globalImports = ['Package'];
if (archinfo.matches(inputSourceArch.arch, "os")) {
globalImports = globalImports.concat(['Npm', 'Assets']);
}
compiler.eachUsedUnibuild({
dependencies: inputSourceArch.uses,
arch: inputSourceArch.arch,
@@ -971,6 +972,14 @@ var runLinters = function (
});
});
var linterPluginsByExtension = {};
_.each(linters, function (linterPlugin) {
_.each(linterPlugin.extensions, function (ext) {
linterPluginsByExtension[ext] = linterPluginsByExtension[ext] || [];
linterPluginsByExtension[ext].push(linterPlugin);
});
});
// For each file choose the longest extension handled by linters.
var longestMatchingExt = {};
_.each(wrappedSourceItems, function (wrappedSource) {
@@ -986,7 +995,11 @@ var runLinters = function (
});
// Run linters on files.
_.each(linterPluginsByExtension, function (linters, ext) {
_.each(linters, function (linterDef) {
// skip linters not relevant to the arch we are compiling for
if (! linterDef.relevantForArch(inputSourceArch.arch))
return;
var sourcesToLint = [];
_.each(wrappedSourceItems, function (wrappedSource) {
var relPath = wrappedSource.relPath;
@@ -995,28 +1008,25 @@ var runLinters = function (
var source = wrappedSource.source;
// only run linters matching the longest handled extension
if (longestMatchingExt[relPath] !== ext)
if (! _.contains(linterDef.extensions, longestMatchingExt[relPath]))
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;
if (! sourcesToLint.length)
return;
var linter = linterDef.instantiatePlugin();
buildmessage.enterJob({
title: "linting files with " + linterDef.isopack.name
}, function () {
try {
var markedLinter = buildmessage.markBoundary(linter.run.bind(linter));
markedLinter(sourcesToLint, globalImports);
} catch (e) {
buildmessage.exception(e);
}
});
var linter = linterDef.instantiatePlugin();
buildmessage.enterJob({
title: "linting files with " + linterDef.isopack.name
}, function () {
try {
var markedLinter = buildmessage.markBoundary(linter.run.bind(linter));
markedLinter(sourcesToLint, globalImports);
} catch (e) {
buildmessage.exception(e);
}
});
});
};