Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cdavie-artium opened this issue Sep 20, 2023 · 0 comments
Open

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

cdavie-artium opened this issue Sep 20, 2023 · 0 comments

Comments

@cdavie-artium
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant