Files
openlayers/rules/requires-first.js
2016-08-08 09:58:12 -06:00

31 lines
690 B
JavaScript

'use strict';
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;
}
});
}
};
}
};