Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
add firecloud/no-for, deprecate better/no-fors fp/no-loops
Browse files Browse the repository at this point in the history
  • Loading branch information
andreineculau committed Dec 8, 2018
1 parent b10579a commit 0b7b5c5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion configs/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = {
'generator-star-spacing': 'error',
'getter-return': 'error',
'global-require': 'error',
'guard-for-in': 'error',
'guard-for-in': 'off',
'handle-callback-err': 'error',
'id-blacklist': 'off',
'id-length': 'off',
Expand Down
2 changes: 1 addition & 1 deletion configs/better.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
'better/no-deletes': 'off',
'better/no-exceptions': 'off',
'better/no-exports': 'off',
'better/no-fors': 'error',
'better/no-fors': 'off',
'better/no-function-expressions': 'off',
'better/no-ifs': 'off',
'better/no-imports': 'off',
Expand Down
1 change: 1 addition & 0 deletions configs/firecloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'firecloud/import-specifier-newline': ['error', {
allowMultiplePerLine: false
}],
'firecloud/no-for': 'error',
'firecloud/no-underscore-prefix-exported': 'error',
'firecloud/order-imports': 'error',
'firecloud/padding-line-import-multiple': 'error',
Expand Down
2 changes: 1 addition & 1 deletion configs/fp.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
'fp/no-events': 'error',
'fp/no-get-set': 'error',
'fp/no-let': 'off',
'fp/no-loops': 'error',
'fp/no-loops': 'off',
'fp/no-mutating-assign': 'error',
'fp/no-mutating-methods': 'off',
'fp/no-mutation': 'off',
Expand Down
4 changes: 1 addition & 3 deletions rules/import-specifier-newline.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ module.exports = {
}
}

/* eslint-disable better/no-fors, fp/no-loops, no-plusplus */
for (let i = 1; i < specifiers.length; i++) {
for (let i of _.range(1, specifiers.length)) {
const lastTokenOfPreviousSpecifier = sourceCode.getLastToken(specifiers[i - 1]);
const firstTokenOfCurrentSpecifier = sourceCode.getFirstToken(specifiers[i]);

Expand All @@ -81,7 +80,6 @@ module.exports = {
});
}
}
/* eslint-enable better/no-fors, fp/no-loops, no-plusplus */
}
};
}
Expand Down
1 change: 1 addition & 0 deletions rules/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports.rules = {
'import-specifier-newline': require('./import-specifier-newline'),
'no-underscore-prefix-exported': require('./no-underscore-prefix-exported'),
'no-for': require('./no-for'),
'order-imports': require('./order-imports'),
'padding-line-import-multiple': require('./padding-line-import-multiple'),
'underscore-prefix-non-exported': require('./underscore-prefix-non-exported')
Expand Down
41 changes: 41 additions & 0 deletions rules/no-for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// NOTE modification of https://github.com/jfmengels/eslint-plugin-fp/blob/8757d3c/rules/no-loops.js
// to allow for for...in, for...of, while and do...while

/* eslint eslint-comments/no-unlimited-disable: off */
/* eslint-disable */

const create = function (context) {
function reportForLoop(node) {
context.report({
node,
message: 'Unallowed use of `for` loop'
});
}

function reportWhileLoop(node) {
context.report({
node,
message: 'Unallowed use of `while` loop. Use recursion instead'
});
}

return {
ForStatement: reportForLoop
// ForInStatement: reportForLoop,
// ForOfStatement: reportForLoop,

// WhileStatement: reportWhileLoop,
// DoWhileStatement: reportWhileLoop
};
};

module.exports = {
create,
meta: {
docs: {
// description: 'Forbid the use of loops.',
description: 'Forbid the use of for loops.',
recommended: 'error'
}
}
};

0 comments on commit 0b7b5c5

Please sign in to comment.