Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import/order throws error in every order #2084

Closed
vtaits opened this issue May 17, 2021 · 6 comments
Closed

import/order throws error in every order #2084

vtaits opened this issue May 17, 2021 · 6 comments

Comments

@vtaits
Copy link

vtaits commented May 17, 2021

Input:

/* eslint-disable @typescript-eslint/no-explicit-any */

import {
  Form,
} from 'react-final-form';
import type {
  FormProps as FinalFormProps,
} from 'react-final-form';
import {
  useMemo,
  useCallback,
} from 'react';
import type {
  ReactElement,
  ReactNode,
} from 'react';
import {
  serialize as formSchemaSerialize,
  parse as formSchemaParse,
  mapFieldErrors as formSchemaMapFieldErrors,
} from '@vtaits/form-schema';
import type {
  GetFieldSchema,
} from '@vtaits/form-schema';

Result:

   9:1  error  `react` import should occur before import of `react-final-form`                import/order
  17:1  error  `@vtaits/form-schema` import should occur before import of `react-final-form`  import/order

Trying to fix:

/* eslint-disable @typescript-eslint/no-explicit-any */

import {
  useMemo,
  useCallback,
} from 'react';
import type {
  ReactElement,
  ReactNode,
} from 'react';
import {
  serialize as formSchemaSerialize,
  parse as formSchemaParse,
  mapFieldErrors as formSchemaMapFieldErrors,
} from '@vtaits/form-schema';
import type {
  GetFieldSchema,
} from '@vtaits/form-schema';
import {
  Form,
} from 'react-final-form';
import type {
  FormProps as FinalFormProps,
} from 'react-final-form';

Result:

  11:1  error  `@vtaits/form-schema` import should occur before import of `react`  import/order
  19:1  error  `react-final-form` import should occur before import of `react`     import/order

2nd try:

/* eslint-disable @typescript-eslint/no-explicit-any */

import {
  serialize as formSchemaSerialize,
  parse as formSchemaParse,
  mapFieldErrors as formSchemaMapFieldErrors,
} from '@vtaits/form-schema';
import type {
  GetFieldSchema,
} from '@vtaits/form-schema';
import {
  Form,
} from 'react-final-form';
import type {
  FormProps as FinalFormProps,
} from 'react-final-form';
import {
  useMemo,
  useCallback,
} from 'react';
import type {
  ReactElement,
  ReactNode,
} from 'react';

Result:

  11:1  error  `react-final-form` import should occur before import of `@vtaits/form-schema`  import/order
  17:1  error  `react` import should occur before import of `@vtaits/form-schema`             import/order

I don't know internal magic, maybe reason of bug is typescript or monorepo. You can test it locally:

Repo:

https://github.com/vtaits/form-schema

File:

https://github.com/vtaits/form-schema/blob/master/packages/react-final-form-schema/src/core/Form.tsx

@ljharb
Copy link
Member

ljharb commented May 17, 2021

Seems like a pretty bad bug around import type. Presumably if you moved them all to import it'd pass?

@netcoding87
Copy link

I do have the same issue after updating from 2.22.1 to 2.23.2

import type { ReactElement, ReactNode } from 'react'
import { Children, cloneElement, isValidElement } from 'react'
1:1  warning  There should be at least one empty line between import groups  import/order
2:1  warning  `react` import should occur before import of `react`           import/order

@paztis
Copy link

paztis commented May 17, 2021

Try to invert the order.
All Import type may be after all classic import

@olee
Copy link

olee commented May 17, 2021

This is indeed a very bad regression causing a whole lot of errors in our codebase right now as well.
I think that merging #2087 sounds like a good solution.

@vtaits
Copy link
Author

vtaits commented May 19, 2021

Seems like a pretty bad bug around import type. Presumably if you moved them all to import it'd pass?

Yes, it passed without import type.

@geraintwhite
Copy link
Contributor

This is indeed a very bad regression causing a whole lot of errors in our codebase right now as well.
I think that merging #2087 sounds like a good solution.

I've marked the PR as ready for review with all checks now passing. It was draft before as I wasn't sure the approach was correct.

@ljharb ljharb closed this as completed in b39770d May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants