Doesn't support TS 4.5 new import syntax
Closed this issue · 6 comments
TypeScript has introduced some new syntax for import/export.
But when we use it, auto-fix removes all type
identifiers. Also, due to this, the plugin highlights incorrect issues.
Config:
"import-newlines/enforce": [
"error",
{
"items": Infinity,
"max-len": 70,
"semi": true,
},
],
For example, at this point, the plugin complains about length and this is corect:
// 75 chars here
import { type importType1, type importType2, importFunction } from './src';
Fixing the code manually, and now the plugin started complaining that it should be written in one line:
import {
type importType1,
type importType2,
importFunction,
} from './src';
This code should be correct but the plugin raises issues because it didn't consider type
s.
And if we run autofix
, the plugin removes all the type
s. From its point of view, this code
// 75 chars here
import { type importType1, type importType2, importFunction } from './src';
should look correctly if we remove type
s only:
// 65 chars here
import { importType1, importType2, importFunction } from './src';
But seems, the plugin correctly works with the following syntax: import type { importType1, importType2, importType3 } from './src'
.
The plugin should correctly count chars with new TS 4.5 import syntax (when multiline chars count) and autofix shouldn't remove type
s if they are written.
Thanks for letting me know! Please upgrade to version 1.2.1 and reopen this if the issue persists.
Unfortunately this is still an issue in version 1.2.2. See example below.
Config:
'import-newlines/enforce': ['error', {
items: 3,
'max-len': 100,
}],
Typed import:
import type {
NavigationFailure,
LocationAsRelativeRaw,
RouteLocationNormalized,
} from 'vue-router';
ESLint says:
Imports must not be broken into multiple lines if there are 3 or less elements.(import-newlines/enforce)
But if we put it on one line ESLint says:
This line has a length of 102. Maximum allowed is 100.(max-len)
Because the line is too long.
According to the plugin the single line version of that import is
import type { NavigationFailure, LocationAsRelativeRaw, RouteLocationNormalized } from 'vue-router';
which is exactly 100 characters long, and thus it's expected to be left on a single line. What exactly is the single line version you ended up with that caused the max-len
ESLint error?
@SeinopSys sorry, I forgot to include in the example that there is a two space indent before the import.
@thimonwentink This is an entirely different issue caused by the indentation and is not specific to TypeScript imports. I've released v1.2.3 which should fix the issue but if you need more assistance please open a new issue with clear reproduction steps.
@SeinopSys sorry, I thought it was related. Thanks for the fix, it works :)