feat(plugin-eslint): add smart defaults to plugin
User story
As a developer I want to have as less setup and configuration cost as possible.
At the moment when I'm have the plugin imported i still need to understand how to configure it. Smart defaults could help here.
import eslintPlugin from '@code-pushup/eslint-plugin';
export default {
// ...
plugins: [
// ...
await eslintPlugin(
// 👇 required => 🧠 📖 🐞⏱️
{ eslintrc: '.eslintrc.js', patterns: ['src/**/*.js'] })
],
};
Acceptance criteria
-
[ ] calling
eslintPluginwithouteslintrcoptions -
(optional 🤓) provide a static value for
eslintrc. E.g..eslintrc.json -
(optional 🤓🤓) derive the value for
eslintrcby crawling the file system forprocess.cwd. Use a glob to target different formats and naming. E.g..eslintrc.(ts|js) -
[ ] throws if no file is set for options
eslintrc -
[ ] calling
eslintPluginwithoutpatternsoptions -
(optional 🤓) provide a static value for
patterns. E.g.**/src/**/index.js -
(optional 🤓🤓) derive the value for
patternsby crawling the file system use a combination of early exit like some and a glob patters. Start with a static value or a glob pattern to target different file and naming. E.g.**/src/**/index.js. -
[ ] throws if no pattern is set for options
patterns -
[ ] calling
eslintPluginwithout options- [ ] throws if no options are given.
e.g. throw the following error:
- [ ] throws if no options are given.
throw new Error(`${ESLINT_PLUGIN_SLUG} needs configuration to work properly. Please read up the configuration section. ${eslintConfigLink}`)
The optional criteria should go into a followup PR 📏.
Implementation details
It would be cool to use the plugin like this:
import eslintPlugin from '@code-pushup/eslint-plugin';
export default {
// ...
plugins: [
// ...
await eslintPlugin(), // 👈 optional => ❤️ 😍
],
};
The file patterns are probably needed, but we could enable configuring only patterns as string | string[]:
await eslintPlugin('src/**/*.js')
await eslintPlugin(['src/**/*.js', 'src/**/*.ts'])