Skip to content

no-es6-methods rule should have an "exceptMethods" option #45

@cdavie-artium

Description

@cdavie-artium

I expected the no-es6-methods rule to accept an exceptMethods option, the same way that no-es6-static-methods does. However, it does not.

So I used patch-package to patch eslint-plugin-es5@1.5.0 to add that rule option:

diff --git a/node_modules/eslint-plugin-es5/src/rules/no-es6-methods.js b/node_modules/eslint-plugin-es5/src/rules/no-es6-methods.js
index b313f28..260cbd1 100644
--- a/node_modules/eslint-plugin-es5/src/rules/no-es6-methods.js
+++ b/node_modules/eslint-plugin-es5/src/rules/no-es6-methods.js
@@ -52,9 +52,22 @@ module.exports = {
     docs: {
       description: 'Forbid methods added in ES6'
     },
-    schema: []
+    schema: [{
+      type: 'object',
+      properties: {
+        exceptMethods: {
+          type: 'array',
+          items: {
+            type: 'string'
+          }
+        }
+      }
+    }]
   },
   create(context) {
+    const options = Object.assign({ exceptMethods: [] }, context.options[0]);
+    const exceptMethods = new Set(options.exceptMethods);
+
     return {
       CallExpression(node) {
         if(!node.callee || !node.callee.property) {
@@ -77,7 +90,7 @@ module.exports = {
         const es6Functions = [].concat(
           es6ArrayFunctions,
           es6StringFunctions
-        );
+        ).filter((name) => !exceptMethods.has(name));
         if (es6Functions.indexOf(functionName) > -1 && !isPermitted(node.callee)) {
           context.report({
             node: node.callee.property,

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions