remithomas / eslint-plugin-ban

Ban some methods and functions
ISC License
31 stars 4 forks source link

bug: allow multiple ban rules #2

Closed Hotell closed 5 years ago

Hotell commented 5 years ago

Hey! First of all thanks for this plugin! I'm migrating from tslint so this is very useful libary indeed.

It would be nice to add support for multiple rules, similarly to tslint ban.

Expected to work

module.exports = {
  plugins: ['ban'],
  rules: {
    'ban/ban': [
      'error',
      {
        name: 'parseInt',
        message: 'use #type-coercion -> Number(val)',
      },
      {
        name: 'parseFloat',
        message: 'use #type-coercion -> Number(val)',
      },
      {
        name: 'Array',
        message: 'use #array-constructor',
      },
      {
        name: ['describe', 'only'],
        message: "don't focus spec blocks",
      },
      {
        name: ['it', 'only'],
        message: "don't focus tests",
      },
    ],
  },
};

Also if I wrap those rules within an array, it wont work

 'ban/ban': [
      'error', [{...},{...},]
]

Error:

 Configuration for rule "ban/ban" is invalid:
        Value [{"name":"parseInt","message":"use #type-coercion -> Number(val)"},{"name":"parseFloat","message":"use #type-coercion -> Number(val)"},{"name":"Array","message":"use #array-constructor"},{"name":["describe","only"],"message":"don't focus spec blocks"},{"name":["it","only"],"message":"don't focus tests"}] should NOT have more than 1 items.

    at validateRuleOptions (/Users/hotell/Projects/devel/twisto/twisto-ui/node_modules/eslint/lib/config/config-validator.js:133:19)
remithomas commented 5 years ago

Hey! Thanks for this kind of word. Indeed this looks like useful, I will implement it soon. I will go back to you when it's fixed.

remithomas commented 5 years ago

@Hotell you can use this plugin as expected:

{
    "rules": {
        "ban/ban": [
            "error",
            {"name": "api", "message": "This function is deprecated, please use api.call()"},
            {"name": ["*", "push"], "message": "Prefer use es6 spread like [...items, newItem]"},
            {"name": "functionName", "message": "Prefer use functionName2"}
        ]
    }
}
Hotell commented 5 years ago

cheers !