not-an-aardvark / eslint-plugin-self

Allows ESLint plugins to lint themselves
MIT License
18 stars 4 forks source link

Support redefining plugins, overrides and rules with a "/" in them #2

Closed BPScott closed 5 years ago

BPScott commented 5 years ago

Handle case where a rule name contains a /

Previously rule names like myplugin/folder/rule would get converted to self/rule - cutting off any folder structure. Slicing at the first / rather than the last one shall preserve the full path.


Handle cases where a config defined in a plugin enables the plugin. Previously the logic didn't switch plugin names out for 'self'

Consider a plugin named 'myplugin' that is defined like so:

module.exports = {
    rules: {
        'myrule': {/* Imagine a rule here */}
    },
    configs: {
        myconfig: {
            plugins: ['myplugin'],
            rules: {'myplugin/myrule': 'error'}
        }
    }
}

Consumers of the plugin can do extends: ['plugin:myplugin/myconfig] to enable the plugin and configure its rules.

Prior to this PR trying to use eslint-plugin-self resulted in a "myplugin could not be found" error as references to it were not replaced.


Handle cases where rules are defined in an override (e.g. because I only want to enable a rule for typescript files)

Consider a plugin that looks like:

module.exports = {
  rules: {
    'myrule': {}
  },
  configs: {
    myconfig: {
      plugins: ['myplugin'],
      rules: {'myplugin/myrule': 'off'},
      overrides: [
        {
          files: ['*.ts'],
          rules: {'myplugin/myrule': 'error'}
        }
      ]
    }
  }
};

Prior to this PR the "myplugin/myrule" rule within the overrides would not be transformed into "self/myrule"

BPScott commented 5 years ago

Heya @not-an-aardvark, I fixed it to not mutate the rules. Is there anything else you'd like me to look at?