dolsem / eslint-plugin-filename-rules

MIT License
36 stars 8 forks source link

unable to specify regexp inside json-config #8

Closed cherepanov closed 1 year ago

cherepanov commented 3 years ago

Where should be check for predefined values, not for value type. Currently where is no way to specify regexp inside json-config.

if (value instanceof RegExp) return [value, value.toString()];
  if (typeof value === 'string') {
dolsem commented 3 years ago

Right, I made an assumption all values of type string refer to predefined values, for the sake of simplicity. So currently there is no support for defining regexes as strings. Is there any specific reason you can't switch to a js based config? I am not opposed to adding this functionality though.

cherepanov commented 3 years ago

Well, we simply use json configs in monorepo, so we need to change coding standards and this change will effect too many files.

Why we can't do like this?

  if (typeof value === 'string') {
    let predefinedRegex = aliases[value];

    if (predefinedRegex) {
      return [predefinedRegex, value];
    }

    try {
      return [new RegExp(value), value];
    } catch (e) {}

    throw new Error(`Unrecognized option "${value}"`);
  }