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/consistent-type-specifier-style] Autofix creates syntax errors and unprettified results #2790

Closed
KirillGalimov opened this issue May 31, 2023 · 4 comments

Comments

@KirillGalimov
Copy link

KirillGalimov commented May 31, 2023

Config:

'import/consistent-type-specifier-style': ['error', 'prefer-top-level']

Case 1:

input

import React, { createContext, type Reducer } from 'react';

export const Component = ({ propOne, propTwo }) => {
  return null;
};

output

import React, { createContext  } from 'react'; // unnecessary space added
import type {Reducer} from 'react'; // necessary spaces not added

export const Component = ({ propOne propTwo }) => { // comma removed (syntax error)
  return null;
};

Case 2:

input

import React, { createContext, type Reducer } from 'react';
import { useLocation, useHistory } from 'react-router';

export const Component = ({ propOne, propTwo }) => {
  return null;
};

output

import React, { createContext  } from 'react'; // unnecessary space added
import type {Reducer} from 'react'; // necessary spaces not added
import { useLocation useHistory } from 'react-router'; // comma removed (syntax error)

export const Component = ({ propOne, propTwo }) => {
  return null;
};
@makuko
Copy link

makuko commented May 31, 2023

I noticed the same behavior. It removes commas in random places unrelated to imports.

@ljharb
Copy link
Member

ljharb commented Jun 1, 2023

This is a major bug, thanks for reporting it.

"unprettified results" are never a bug; formatting is expected to be handled by other rules - but producing a syntax error is unacceptable, and additionally this rule should only be touching imports.

@aaronadamsCA
Copy link
Contributor

Note this seems to be a duplicate of #2753, fixed in #2754; the fix remains unreleased.

@ljharb
Copy link
Member

ljharb commented Jul 6, 2023

Thanks! Closed as a duplicate of #2753.

I'll try to get a release out soon.

@ljharb ljharb closed this as completed Jul 6, 2023
@ljharb ljharb closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants