From 0b7b5c547985166d4603a01f9a2056dbe5943e25 Mon Sep 17 00:00:00 2001 From: Andrei Neculau Date: Sat, 8 Dec 2018 21:54:05 +0100 Subject: [PATCH] add firecloud/no-for, deprecate better/no-fors fp/no-loops --- configs/basic.js | 2 +- configs/better.js | 2 +- configs/firecloud.js | 1 + configs/fp.js | 2 +- rules/import-specifier-newline.js | 4 +-- rules/index.js | 1 + rules/no-for.js | 41 +++++++++++++++++++++++++++++++ 7 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 rules/no-for.js diff --git a/configs/basic.js b/configs/basic.js index 79e7294..4f8759a 100644 --- a/configs/basic.js +++ b/configs/basic.js @@ -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', diff --git a/configs/better.js b/configs/better.js index 4709475..2163ef4 100644 --- a/configs/better.js +++ b/configs/better.js @@ -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', diff --git a/configs/firecloud.js b/configs/firecloud.js index 06b022a..ff5c8a6 100644 --- a/configs/firecloud.js +++ b/configs/firecloud.js @@ -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', diff --git a/configs/fp.js b/configs/fp.js index 4a69a39..215f172 100644 --- a/configs/fp.js +++ b/configs/fp.js @@ -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', diff --git a/rules/import-specifier-newline.js b/rules/import-specifier-newline.js index 025bafe..b3c12df 100644 --- a/rules/import-specifier-newline.js +++ b/rules/import-specifier-newline.js @@ -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]); @@ -81,7 +80,6 @@ module.exports = { }); } } - /* eslint-enable better/no-fors, fp/no-loops, no-plusplus */ } }; } diff --git a/rules/index.js b/rules/index.js index ad8da35..9de70ba 100644 --- a/rules/index.js +++ b/rules/index.js @@ -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') diff --git a/rules/no-for.js b/rules/no-for.js new file mode 100644 index 0000000..b5a0651 --- /dev/null +++ b/rules/no-for.js @@ -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' + } + } +};