Skip to content

Commit

Permalink
Can define exceptions for missing requires
Browse files Browse the repository at this point in the history
  • Loading branch information
ger-benjamin committed Dec 5, 2017
1 parent 85d36da commit b05a5b5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ In a dedicated eslintrc file .eslintrc-googshift.yaml:
'googshift/no-duplicate-requires': 'error',

'googshift/no-missing-requires': ['error', {
prefixes: ['app', 'ol', 'ngeo']
prefixes: ['app', 'ol', 'ngeo'],
exceptions: ['ngeo.module.requires.push']
}],

'googshift/no-unused-requires': 'error',
Expand Down
3 changes: 2 additions & 1 deletion no-missing-requires.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exports.rule = {
create: function(context) {
const defined = {};
const prefixes = context.options[0].prefixes || ['ol'];
const exceptions = context.options[0].exceptions || [];
const joined = prefixes.join('|');
const CONST_RE = new RegExp(`^((?:${joined})(\\.[a-z]\\w*)*)\\.[A-Z]+_([_A-Z])+$`);
const CLASS_RE = new RegExp(`^((?:${joined})(\\.[a-z]\\w*)*\\.[A-Z]\\w*)(\\.\\w+)*$`);
Expand Down Expand Up @@ -70,7 +71,7 @@ exports.rule = {

if (parent.type !== 'MemberExpression') {
const name = util.getName(expression);
if (name && STARTS_WITH.test(name) && !defined[name]) {
if (name && STARTS_WITH.test(name) && !defined[name] && exceptions.indexOf(name) < 0) {
// check if the name looks like a const
let match = name.match(CONST_RE);
if (match) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-googshift",
"version": "0.9.2",
"version": "0.9.3",
"description": "Custom ESLint rules for checking Google Compiler projects",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit b05a5b5

Please sign in to comment.