import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.38k stars 1.54k forks source link

[import/order] rule needed to be run 6 times before it actually sorted #2143

Open dimitropoulos opened 3 years ago

dimitropoulos commented 3 years ago

Hi!

I'm trying to use import/order in Insomnia instead of eslint-plugin-simple-import-sort. One problem we hit is that some files in the project needed the rule to run multiple times in order for the rule to work. One of the worst ones required the rule to be run 6 times before it worked:

Here is the input: ```ts import React, { PureComponent, RefObject } from 'react'; import { autoBindMethodsForReact } from 'class-autobind-decorator'; import { AUTOBIND_CFG, ACTIVITY_HOME, COLLAPSE_SIDEBAR_REMS, DEFAULT_PANE_HEIGHT, DEFAULT_PANE_WIDTH, DEFAULT_SIDEBAR_WIDTH, getAppName, MAX_PANE_HEIGHT, MAX_PANE_WIDTH, MAX_SIDEBAR_REMS, MIN_PANE_HEIGHT, MIN_PANE_WIDTH, MIN_SIDEBAR_REMS, PREVIEW_MODE_SOURCE, ACTIVITY_MIGRATION, SortOrder, } from '../../common/constants'; import fs from 'fs'; import { clipboard, ipcRenderer, remote, SaveDialogOptions } from 'electron'; import { parse as urlParse } from 'url'; import HTTPSnippet from 'httpsnippet'; import ReactDOM from 'react-dom'; import { connect } from 'react-redux'; import { Action, bindActionCreators, Dispatch } from 'redux'; import Wrapper from '../components/wrapper'; import WorkspaceEnvironmentsEditModal from '../components/modals/workspace-environments-edit-modal'; import Toast from '../components/toast'; import CookiesModal from '../components/modals/cookies-modal'; import RequestSwitcherModal from '../components/modals/request-switcher-modal'; import SettingsModal, { TAB_INDEX_SHORTCUTS } from '../components/modals/settings-modal'; import { importUri, loadRequestStart, loadRequestStop, newCommand, setActiveWorkspace, setActiveActivity, goToNextActivity, importFile, importClipBoard, exportRequestsToFile, } from '../redux/modules/global'; import { initialize } from '../redux/modules/entities'; import { database as db } from '../../common/database'; import * as models from '../../models'; import { selectActiveCookieJar, selectActiveEnvironment, selectActiveGitRepository, selectActiveOAuth2Token, selectActiveRequest, selectActiveRequestMeta, selectActiveRequestResponses, selectActiveResponse, selectActiveSpace, selectActiveUnitTestResult, selectActiveUnitTests, selectActiveUnitTestSuite, selectActiveUnitTestSuites, selectActiveWorkspace, selectActiveWorkspaceClientCertificates, selectActiveWorkspaceMeta, selectEntitiesLists, selectSettings, selectSyncItems, selectUnseenWorkspaces, selectWorkspaceRequestsAndRequestGroups, selectWorkspacesForActiveSpace, } from '../redux/selectors'; import { selectSidebarChildren } from '../redux/sidebar-selectors'; import RequestCreateModal from '../components/modals/request-create-modal'; import GenerateCodeModal from '../components/modals/generate-code-modal'; import WorkspaceSettingsModal from '../components/modals/workspace-settings-modal'; import RequestSettingsModal from '../components/modals/request-settings-modal'; import RequestRenderErrorModal from '../components/modals/request-render-error-modal'; import * as network from '../../network/network'; import { debounce, generateId, getContentDispositionHeader, } from '../../common/misc'; import { getDataDirectory } from '../../common/electron-helpers'; import * as mime from 'mime-types'; import * as path from 'path'; import * as render from '../../common/render'; import { getKeys } from '../../templating/utils'; import { showAlert, showModal, showPrompt } from '../components/modals/index'; import { exportHarRequest } from '../../common/har'; import { hotKeyRefs } from '../../common/hotkeys'; import { executeHotKey } from '../../common/hotkeys-listener'; import KeydownBinder from '../components/keydown-binder'; import ErrorBoundary from '../components/error-boundary'; import * as plugins from '../../plugins'; import * as templating from '../../templating/index'; import { NUNJUCKS_TEMPLATE_GLOBAL_PROPERTY_NAME } from '../../templating/index'; import AskModal from '../components/modals/ask-modal'; import { Request, updateMimeType } from '../../models/request'; import * as themes from '../../plugins/misc'; import FileSystemDriver from '../../sync/store/drivers/file-system-driver'; import { VCS } from '../../sync/vcs/vcs'; import SyncMergeModal from '../components/modals/sync-merge-modal'; import { GitVCS, GIT_CLONE_DIR, GIT_INSOMNIA_DIR, GIT_INTERNAL_DIR } from '../../sync/git/git-vcs'; import { NeDBClient } from '../../sync/git/ne-db-client'; import { fsClient } from '../../sync/git/fs-client'; import { routableFSClient } from '../../sync/git/routable-fs-client'; import { getWorkspaceLabel } from '../../common/get-workspace-label'; import * as requestOperations from '../../models/helpers/request-operations'; import { GrpcProvider } from '../context/grpc'; import { sortMethodMap } from '../../common/sorting'; import withDragDropContext from '../context/app/drag-drop-context'; import { trackSegmentEvent } from '../../common/analytics'; import getWorkspaceName from '../../models/helpers/get-workspace-name'; import * as workspaceOperations from '../../models/helpers/workspace-operations'; import { isCollection, isWorkspace } from '../../models/workspace'; import { GrpcRequest, isGrpcRequest, isGrpcRequestId } from '../../models/grpc-request'; import { isEnvironment } from '../../models/environment'; import { GrpcRequestMeta } from '../../models/grpc-request-meta'; import { RequestMeta } from '../../models/request-meta'; import { isRequestGroup, RequestGroup } from '../../models/request-group'; import { WorkspaceMeta } from '../../models/workspace-meta'; import { Response } from '../../models/response'; import { RenderContextAndKeys } from '../../common/render'; import { RootState } from '../redux/modules'; ```

This seems broken maybe? I say that in part because simple-import-sort sorts it in one pass.

ljharb commented 3 years ago

eslint runs multiple passes on the cli (I’m not sure what insomnia is, but if it’s using eslint programmatically, that’d be what it needs to fix), but I’m sure there’s improvement here in the rule to be had.

dimitropoulos commented 3 years ago

Good clarification: what I mean is that with import/order and the above example input, I need to run eslint --fix multiple times for the rule to sort and stop erroring, whereas simple-import-sort sorts it (with no remaining errors) in 1 run of eslint --fix.

Since out of hundreds of files there were only 3 or 4 that were like this, I thought it might be useful to you to have the input file if anyone else ever hits this or would like to work on it.

Feel free to close or whatever: we're going to stick with simple-import-sort for now so this isn't a problem for us.


Insomnia is an open source API client for REST/gRPC/OpenAPI made by Kong. Was just mentioning for context.