remithomas / eslint-plugin-ban

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

Allow banning built-in code structures #26

Closed seanblonien closed 2 years ago

seanblonien commented 2 years ago

I was wondering if it would be possible to allow banning of built-in code structures, for example, the switch statement.

In my experience, most switch statements could be converted to an object mappings (where properties are either values of functions that produce values/perform some action), and I prefer this style over switch statements.

Can this plugin support a config like this?

'ban/ban': [
  'warn',
  {name: 'switch', message: 'Use object literal mapping instead'},
],

Other examples I think of are for-loops with a comment about saying you can use forEach/filter/map/reduce instead.

If this is out-of-scope of this project, totally fine, was just curious

seanblonien commented 2 years ago

Finally figured out you can just use the built-in eslint no-restricted-syntax command to ban any arbitrary javascript structure whatsoever, and that is how I'll be banning the switch statement

'no-restricted-syntax': [
  'error',
  {
    selector: 'SwitchStatement',
    message: 'Switch statements are banned. Use object literal mapping instead.',
  },
]