Refactored rules

This commit is contained in:
Tim Schaub
2016-08-07 23:17:09 -06:00
parent c203f6a841
commit dd2e9c9ac9
10 changed files with 181 additions and 46 deletions

28
rules/requires-first.js Normal file
View File

@@ -0,0 +1,28 @@
const util = require('./util');
exports.rule = {
meta: {
docs: {
description: 'require that all goog.require() precede other statements (except goog.provide())'
}
},
create: function(context) {
return {
Program: function(program) {
let otherSeen = false;
program.body.forEach(statement => {
if (util.isRequireStatement(statement)) {
if (otherSeen) {
return context.report(statement, 'Expected goog.require() to precede other statements');
}
} else if (!util.isProvideStatement(statement)) {
otherSeen = true;
}
});
}
};
}
};