eslint-plugin-require-extensions icon indicating copy to clipboard operation
eslint-plugin-require-extensions copied to clipboard

usage in eslint flat config

Open mesqueeb opened this issue 1 year ago • 7 comments

how to use it in the new eslint flat config

mesqueeb avatar May 02 '24 14:05 mesqueeb

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.

electrovir avatar May 20 '24 15:05 electrovir

+1

guoh27 avatar Jun 19 '24 07:06 guoh27

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

speelbarrow avatar Jun 19 '24 13:06 speelbarrow

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
]

electrovir avatar Jul 21 '24 21:07 electrovir

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.

SeanMcMillan avatar Sep 17 '24 17:09 SeanMcMillan

@jordaaash could you please please please upgrade this plugin to modern eslint v9? it's the only plugin that adds .js automatically

mesqueeb avatar Feb 15 '25 01:02 mesqueeb

@mesqueeb @electrovir @guoh27 @speelbarrow @SeanMcMillan I've published a new package eslint-plugin-import-extensions

brianwestphal avatar Mar 25 '25 03:03 brianwestphal