eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

eslint-plugin-import upgrade issues on no-cycle

Open saravanakumar2504 opened this issue 1 year ago • 10 comments

The upgrade of eslint-plugin-import from version 2.26.0 to 2.31.0(to support flat config) has resulted in increased processing time for ESLint, primarily due to the import/no-cycle rule. Included screenshot as well

"import/no-cycle": [
      2,
      {
       "maxDepth": null,
       "ignoreExternal": false
      }
    ],

I followed this github thread and played with those configs(like toggling disableScc), but no luck. Can someone assit on this ?

Image

saravanakumar2504 avatar Dec 11 '24 11:12 saravanakumar2504

What happens if you set ignoreExternal to true?

ljharb avatar Dec 11 '24 14:12 ljharb

@ljharb : Facing same issue after setting ignoreExternal to true Image

saravanakumar2504 avatar Dec 12 '24 02:12 saravanakumar2504

cc @soryy708

ljharb avatar Dec 12 '24 02:12 ljharb

Possible duplicate of https://github.com/import-js/eslint-plugin-import/issues/3060 Upgrading from 2.26.0 to 2.31.0 is a superset of upgrading 2.27.5 to 2.31.0. If somewhere around 2.27.5 there was a performance regression, then upgrading from 2.26.0 would hit the same one, not a distinct one.

soryy708 avatar Dec 12 '24 13:12 soryy708

@saravanakumar2504 Can you please share some metadata about the project in which no-cycle performs pathologically? How many lines of code? How many files? Anything special about the project configuration? Is it a single project? Or a mono-repository with multiple projects?

As it is it's difficult to pin-point what causes some projects to benefit from SCC and others to be hindered. In a perfect world, a reproduction repository would be great, but practically those are usually proprietary.

soryy708 avatar Dec 13 '24 09:12 soryy708

@soryy708 : I undersrand your query. Since we are using mono-repo and our project files is very huge(1 lakh file) its difficult for me to mimic it.

saravanakumar2504 avatar Dec 13 '24 12:12 saravanakumar2504

(i believe a lakh is 100K)

ljharb avatar Dec 13 '24 18:12 ljharb

@soryy708 / @ljharb

I found the minimal config to replicate my issue. Kindly find my eslint.config.js below and when i remove config('import/resolver') its working as expected

'import/resolver': {
			// node needs to be declared first. see https://github.com/benmosher/eslint-plugin-import/issues/1396
			node: {},
			[resolverPath]: {
				debug: false,
			},
		},
const path = require('path');
const babelParser = require('@babel/eslint-parser');
const tsParser = require('@typescript-eslint/parser');
const js = require('@eslint/js');
const globals = require('globals');

const { FlatCompat } = require('@eslint/eslintrc');

const resolverPath = path.resolve(`${__dirname}/build/monorepo-utils/resolvers/eslint-resolver.js`);

const compat = new FlatCompat({
	baseDirectory: __dirname,
	recommendedConfig: js.configs.recommended,
});

const config = [
	...compat.extends(
		'airbnb-base',
		'airbnb/rules/react',
		'prettier',
		'prettier/react',
		'plugin:compat/recommended',
	),
	...compat.plugins(
		'jest',
		'react',
		'react-hooks',
		'json',
		'import',
		'formatjs',
		'@emotion',
	),
	{
		files: ['**/*.{js,jsx,ts,tsx,json}'],
		name: 'base config',
		plugins: {
			jsdoc: require('eslint-plugin-jsdoc'),
			'@typescript-eslint': require('@typescript-eslint/eslint-plugin'),
		},
		languageOptions: {
			parser: babelParser,
			globals: {
				...globals.browser,
			},
		},
		settings: {
			'import/extensions': ['.js', '.ts', '.tsx'],
			'import/resolver': {
				// node needs to be declared first. see https://github.com/benmosher/eslint-plugin-import/issues/1396
				node: {},
				[resolverPath]: {
					debug: false,
				},
			},
			'import/parsers': {
				'@babel/eslint-parser': ['.js'],
				'@typescript-eslint/parser': ['.ts', '.tsx'],
			},
		},
	},
	{
		name: 'typescript',
		files: ['**/*.{ts,tsx}'],
		languageOptions: {
			parser: tsParser,
			parserOptions: {
				sourceType: 'module',
				ecmaFeatures: {
					jsx: true,
				},
			},
		},
		rules: {
			'import/no-cycle': 2,
		},
	},
];

module.exports = config;

saravanakumar2504 avatar Dec 20 '24 06:12 saravanakumar2504

Much like what @saravanakumar2504 described, upgrading from 2.30.0 to 2.31.0 also slows down import/no-cycle in ArkType's monorepo by multiple orders of magnitude:

2.30.0

Rule                                     | Time (ms) | Relative
:----------------------------------------|----------:|--------:
@typescript-eslint/no-unused-vars        |   304.757 |    18.7%
import/no-cycle                          |   295.458 |    18.2%

2.31.0

Rule                                       | Time (ms) | Relative
:------------------------------------------|----------:|--------:
import/no-cycle                            | 59074.557 |    96.9%
@typescript-eslint/no-unused-vars          |   408.998 |     0.7%

ssalbdivad avatar Apr 09 '25 20:04 ssalbdivad