solana-labs / eslint-plugin-require-extensions

Apache License 2.0
61 stars 9 forks source link

usage in eslint flat config #13

Open mesqueeb opened 7 months ago

mesqueeb commented 7 months ago

how to use it in the new eslint flat config

electrovir commented 6 months ago

It appears to not even be importable because it is built in CommonJS. I get No "exports" main defined errors when trying to import anything from this package into an ESLint v9 flat config.

guoh27 commented 5 months ago

+1

speelbarrow commented 5 months ago

https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config

electrovir commented 4 months ago

https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config

Specifically, do this:

import {fileURLToPath} from 'node:url';
import {FlatCompat} from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const compat = new FlatCompat({
    baseDirectory: __dirname,
});

// ESM config export
export default [
    ...compat.plugins('require-extensions'),
    ...compat.extends('plugin:require-extensions/recommended'),
    // rest of your config
]
SeanMcMillan commented 2 months ago

The new @eslint/compat tool that's supposed to help migrate your .eslintrc incorrectly migrates this plugin, because it can't be imported.

You can still use compat.plugins, but you'll need to remove the import and fixupPluginRules call that is generated.