cli icon indicating copy to clipboard operation
cli copied to clipboard

feat(plugin-eslint): add smart defaults to plugin

Open BioPhoton opened this issue 1 year ago • 1 comments

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 eslintPlugin without eslintrc options

  • (optional 🤓) provide a static value for eslintrc. E.g. .eslintrc.json

  • (optional 🤓🤓) derive the value for eslintrc by crawling the file system for process.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 eslintPlugin without patterns options

  • (optional 🤓) provide a static value for patterns. E.g. **/src/**/index.js

  • (optional 🤓🤓) derive the value for patterns by 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 eslintPlugin without options

    • [ ] throws if no options are given.
      e.g. throw the following error:
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 => ❤️ 😍
    ],
  };

BioPhoton avatar Apr 07 '24 02:04 BioPhoton

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'])

matejchalk avatar Apr 11 '24 12:04 matejchalk