import-js / import-js/eslint-plugin-import
import plugin breaking in nx based mono-repo
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.9k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
I have been encountering a weird issue.
I have a react+typescript based project it was working fine.
Now, I migrated everything to nx-based mono-repo, and I'm getting the following error -
Maximum call stack size exceeded
Occurred while linting /Users/rishavpandey/Professional Work/Skuad/skuad-fe/apps/pay-platform/src/App.tsx:2
Rule: "import/namespace
These are imports in App.tsx -
import { useEffect } from 'react';
import { datadogRum } from '@datadog/browser-rum';
import HeaderSidebarWrapper from '@pay/old/components/HeaderSidebarWrapper';
import useGetConfig from '@pay/old/hooks/useGetConfig/useGetConfig';
import {
Accessors,
ConfigType,
} from '@pay/old/queries/graphql/types/coreTypes';
import useSetMixPanelUserId from '@pay/old/hooks/useSetMixPanelUserId';
import useTrackPageViews from '@pay/old/hooks/useTrackPageViews';
import { ContractContextProvider } from '@pay/old/contextData/contractCreationContext';
import { setGaUserSession } from '@pay/old/hooks/useGoogleAnalytics';
import useClarity from '@pay/old/hooks/useClarity';
import { useMainContext } from '@pay/contexts/MainContextProvider';
import { useContextState } from '@pay/old/contextData/mainAppContext';
import MainRouter from './router';
This is my current eslintrc config the internal app-
apps/pay-platform/.eslintrc.js -
const dotenv = require('dotenv');
dotenv.config();
module.exports = {
root: true,
parserOptions: {
project: 'apps/pay-platform/tsconfig.*?.json',
},
plugins: ['react', 'import', 'jsx-a11y', 'graphql'],
extends: [
'plugin:react/recommended',
'plugin:react-hooks/recommended',
// 'plugin:import/recommended',
// 'plugin:import/typescript',
'plugin:jsx-a11y/recommended',
'../../.eslintrc.js',
],
settings: {
react: {
version: 'detect',
},
// 'import/resolver': {
// typescript: {
// alwaysTryTypes: true,
// project: './tsconfig.*?.json',
// },
// node: {
// extensions: [',.js', ',.jsx', ',.ts', ',.tsx'],
// },
// },
},
rules: {
// // *** Import Rules ***
// 'import/no-named-as-default-member': 'error', // * Stricter than default
// 'import/no-named-as-default': 'error', // * Stricter than default
// 'import/no-duplicates': 'error', // * Stricter than default
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
],
pathGroups: [
{
pattern: '@pay/**',
group: 'internal',
position: 'before',
},
],
'newlines-between': 'always',
},
],
},
overrides: [],
};
As soon as I comment on anything related to the import plugin, Eslint will break.
The same config was working fine in an earlier standalone project, but now it's failing.
This is root level eslint config -
const tsNamingConvention = require('./ts-naming-convention');
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
project: ['./tsconfig.base.json'],
tsconfigRootDir: '.',
lib: ['dom', 'esnext'],
ecmaFeatures: {
jsx: true,
},
},
plugins: ['@nx', 'prettier', '@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@nx/typescript',
'plugin:@nx/javascript',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'prettier', // Ensure "prettier" is last
],
env: {
browser: true,
node: true,
es6: true,
},
globals: {
document: true,
window: true,
location: true,
fetch: true,
},
ignorePatterns: [
'node_modules/',
'dist/',
'**/*.spec.ts',
'**/*.generated.tsx',
'**/*.generated.ts',
'**/*.coreTypes.ts',
'**/*.cmsTypes.ts',
],
rules: {
// *** ESLint Recommended Rules with Stricter Settings ***
eqeqeq: 'error', // Enforce strict equality.
'array-callback-return': 'error', // Ensure a return statement in array callbacks.
'no-sequences': 'error', // Disallow comma operator.
'no-useless-concat': 'error', // Disallow unnecessary concatenation.
'no-redeclare': 'error', // Disallow variable redeclaration.
'no-lone-blocks': 'error', // Disallow unnecessary nested blocks.
'no-extra-boolean-cast': 'error', // Disallow unnecessary boolean casts.
'no-unexpected-multiline': 'error', // Disallow confusing multiline expressions.
'no-var': 'error', // Require let or const instead of var.
'prefer-spread': 'error', // Suggest using spread syntax instead of .apply().
'prefer-rest-params': 'error', // Suggest using rest parameters instead of arguments.
'no-console': ['error', { allow: ['warn', 'error'] }], // Disallow console logs.
'max-lines': [
'warn',
{ max: 500, skipComments: true, skipBlankLines: true },
],
// *** General JavaScript Rules ***
'no-template-curly-in-string': 'error', // Disallow template literal placeholder syntax in regular strings.
'no-restricted-globals': 'error', // Disallow specified global variables.
// *** Naming Convention Rules ***
'@typescript-eslint/naming-convention': tsNamingConvention,
},
overrides: [
{
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
rules: {
'@nx/enforce-module-boundaries': [
'error',
{
enforceBuildableLibDependency: true,
allow: [],
depConstraints: [
{
sourceTag: '*',
onlyDependOnLibsWithTags: ['*'],
},
],
},
],
},
},
],
};
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with apps/pay-platform/.eslintrc.js, the root ESLint config, and the failing App.tsx location. Reproduce linting with the import rules enabled and inspect the Nx and TypeScript project settings involved in resolving imports. Done means the monorepo can lint App.tsx without a call-stack overflow while the import rules remain enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100