Compare commits

..

4 Commits

Author SHA1 Message Date
Anthony Fu
2f1c785eef release v0.20.2 2022-04-07 06:14:31 +08:00
Anthony Fu
4eb7aee28e chore: disable prefer-inline-type-import by default 2022-04-07 06:14:22 +08:00
Anthony Fu
769bee0139 release v0.20.1 2022-04-07 06:06:58 +08:00
Anthony Fu
07a15be095 fix(inline-type): ignore default import 2022-04-07 06:06:50 +08:00
10 changed files with 38 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-monorepo",
"version": "0.20.0",
"version": "0.20.2",
"private": true,
"license": "MIT",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config",
"version": "0.20.0",
"version": "0.20.2",
"description": "",
"keywords": [],
"license": "MIT",

View File

@@ -293,6 +293,6 @@ module.exports = {
// antfu
'antfu/no-leading-newline': 'error',
'antfu/if-newline': 'error',
'antfu/prefer-inline-type-import': 'error',
// 'antfu/prefer-inline-type-import': 'error',
},
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-basic",
"version": "0.20.0",
"version": "0.20.2",
"description": "",
"keywords": [],
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-antfu",
"version": "0.20.0",
"version": "0.20.2",
"license": "MIT",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",

View File

@@ -0,0 +1,27 @@
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
import { it } from 'vitest'
import rule, { RULE_NAME } from './prefer-inline-type-import'
const valids = [
'import { type Foo } from \'foo\'',
'import type Foo from \'foo\'',
'import type * as Foo from \'foo\'',
]
const invalids = [
['import type { Foo } from \'foo\'', 'import { type Foo } from \'foo\''],
]
it('runs', () => {
const ruleTester: RuleTester = new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
})
ruleTester.run(RULE_NAME, rule, {
valid: valids,
invalid: invalids.map(i => ({
code: i[0],
output: i[1].trim(),
errors: [{ messageId: 'preferInlineTypeImport' }],
})),
})
})

View File

@@ -26,6 +26,9 @@ export default createEslintRule<Options, MessageIds>({
const sourceCode = context.getSourceCode()
return {
ImportDeclaration: (node) => {
// ignore bare type imports
if (node.specifiers.length === 1 && ['ImportNamespaceSpecifier', 'ImportDefaultSpecifier'].includes(node.specifiers[0].type))
return
if (node.importKind === 'type') {
context.report({
*fix(fixer) {

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-react",
"version": "0.20.0",
"version": "0.20.2",
"description": "",
"keywords": [],
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-ts",
"version": "0.20.0",
"version": "0.20.2",
"description": "",
"keywords": [],
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-vue",
"version": "0.20.0",
"version": "0.20.2",
"description": "",
"keywords": [],
"license": "MIT",