coderaiser / putout

🐊 Pluggable and configurable JavaScript Linter, code transformer and formatter, drop-in ESLint superpower replacement 💪 with built-in support for js, jsx, typescript, flow, markdown, yaml and json. Write declarative codemods in a simplest possible way 😏
https://putout.cloudcmd.io/
MIT License
698 stars 40 forks source link

ESLint integration fail #212

Closed ivanbanov closed 2 months ago

ivanbanov commented 2 months ago

Im in the process of migrating a codemod from jscodeshift to putout so I can integrate it with ESLint and properly test it.

Unfortunately Im facing the following error in a minimal setup:

> eslint index.ts

Oops! Something went wrong! :(

ESLint: 8.57.0

Error: Key "rules": Key "no-debugger": create(context) {
            const {options} = context;
            const prepared = prepare(plugin, context, ...<omitted>... } could not be cloned.
    at /Users/ivanbanov/dev/ivanbanov/putout-poc/node_modules/.pnpm/@humanwhocodes+object-schema@2.0.3/node_modules/@humanwhocodes/object-schema/src/object-schema.js:250:27
    at Array.reduce (<anonymous>)
    at ObjectSchema.merge (/Users/ivanbanov/dev/ivanbanov/putout-poc/node_modules/.pnpm/@humanwhocodes+object-schema@2.0.3/node_modules/@humanwhocodes/object-schema/src/object-schema.js:237:24)
    at /Users/ivanbanov/dev/ivanbanov/putout-poc/node_modules/.pnpm/@humanwhocodes+config-array@0.11.14/node_modules/@humanwhocodes/config-array/api.js:935:42
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfig (/Users/ivanbanov/dev/ivanbanov/putout-poc/node_modules/.pnpm/@humanwhocodes+config-array@0.11.14/node_modules/@humanwhocodes/config-array/api.js:934:39)
    at FlatConfigArray.isFileIgnored (/Users/ivanbanov/dev/ivanbanov/putout-poc/node_modules/.pnpm/@humanwhocodes+config-array@0.11.14/node_modules/@humanwhocodes/config-array/api.js:962:15)
    at /Users/ivanbanov/dev/ivanbanov/putout-poc/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/eslint/eslint-helpers.js:504:38
    at Array.forEach (<anonymous>)
    at findFiles (/Users/ivanbanov/dev/ivanbanov/putout-poc/node_modules/.pnpm/eslint@8.57.0/node_modules/eslint/lib/eslint/eslint-helpers.js:493:11)
 ELIFECYCLE  Command failed with exit code 2.

the code for reproducing it can be found here https://github.com/ivanbanov/putout-poc

What am I doing wrong? Is it a bug?

coderaiser commented 2 months ago

I have no access to repository, show me ESLint config you are using.

ivanbanov commented 2 months ago

oh sorry, I made it private for no reason, it's public now

coderaiser commented 2 months ago

You need to update ESLint to v9, and fix config.

Try something like this:

module.exports = [
  {
    files: ['*.ts'],
    languageOptions: {
      parser,
      parserOptions: {
        project: true,
      },
    },
    plugins: {
      '@typescript-eslint': tseslintPlugin,
      'poc': {
        rules: {
            'no-debuger': createPlugin(require('./.putout/no-debugger.js')),
        },
    },
    rules: {
      'poc/no-debugger': 'error'
    }
  }
]

Declare poc in plugins section and use it in rules.

ivanbanov commented 2 months ago

nice! thanks for spotting the issue in the config. it worked, even with v8 :)