Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1ff53f2f04 | ||
|
316bbd903b | ||
|
bce5016b53 | ||
|
ddd34a9465 | ||
|
2f1c785eef | ||
|
4eb7aee28e | ||
|
769bee0139 | ||
|
07a15be095 | ||
|
0af15d4bf4 | ||
|
d23abea648 | ||
|
eaff018580 | ||
|
327ab9dd35 |
@@ -34,7 +34,8 @@ For example:
|
|||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint ."
|
"lint": "eslint .",
|
||||||
|
"lint:fix": "eslint . --fix"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -54,7 +55,9 @@ Create `.vscode/settings.json`
|
|||||||
|
|
||||||
## Check Also
|
## Check Also
|
||||||
|
|
||||||
|
- [antfu/dotfiles](https://github.com/antfu/dotfiles) - My dotfiles
|
||||||
- [antfu/vscode-settings](https://github.com/antfu/vscode-settings) - My VS Code settings
|
- [antfu/vscode-settings](https://github.com/antfu/vscode-settings) - My VS Code settings
|
||||||
|
- [antfu/eslint-config](https://github.com/antfu/eslint-config) - My ESLint config
|
||||||
- [antfu/ts-starter](https://github.com/antfu/ts-starter) - My starter template for TypeScript library
|
- [antfu/ts-starter](https://github.com/antfu/ts-starter) - My starter template for TypeScript library
|
||||||
- [antfu/vitesse](https://github.com/antfu/vitesse) - My starter template for Vue & Vite app
|
- [antfu/vitesse](https://github.com/antfu/vitesse) - My starter template for Vue & Vite app
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-monorepo",
|
"name": "@antfu/eslint-config-monorepo",
|
||||||
"version": "0.19.4",
|
"version": "0.20.4",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config",
|
"name": "@antfu/eslint-config",
|
||||||
"version": "0.19.4",
|
"version": "0.20.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -135,6 +135,7 @@ module.exports = {
|
|||||||
'@typescript-eslint/no-unused-vars': 'off',
|
'@typescript-eslint/no-unused-vars': 'off',
|
||||||
'@typescript-eslint/no-use-before-define': 'off',
|
'@typescript-eslint/no-use-before-define': 'off',
|
||||||
'@typescript-eslint/no-var-requires': 'off',
|
'@typescript-eslint/no-var-requires': 'off',
|
||||||
|
'@typescript-eslint/comma-dangle': 'off',
|
||||||
'import/no-unresolved': 'off',
|
'import/no-unresolved': 'off',
|
||||||
'no-alert': 'off',
|
'no-alert': 'off',
|
||||||
'no-console': 'off',
|
'no-console': 'off',
|
||||||
@@ -293,5 +294,6 @@ module.exports = {
|
|||||||
// antfu
|
// antfu
|
||||||
'antfu/no-leading-newline': 'error',
|
'antfu/no-leading-newline': 'error',
|
||||||
'antfu/if-newline': 'error',
|
'antfu/if-newline': 'error',
|
||||||
|
// 'antfu/prefer-inline-type-import': 'error',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-basic",
|
"name": "@antfu/eslint-config-basic",
|
||||||
"version": "0.19.4",
|
"version": "0.20.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "eslint-plugin-antfu",
|
"name": "eslint-plugin-antfu",
|
||||||
"version": "0.19.4",
|
"version": "0.20.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
import ifNewline from './rules/if-newline'
|
import ifNewline from './rules/if-newline'
|
||||||
import noLeadingNewline from './rules/no-leading-newline'
|
import noLeadingNewline from './rules/no-leading-newline'
|
||||||
|
import preferInlineTypeImport from './rules/prefer-inline-type-import'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
rules: {
|
rules: {
|
||||||
'no-leading-newline': noLeadingNewline,
|
'no-leading-newline': noLeadingNewline,
|
||||||
'if-newline': ifNewline,
|
'if-newline': ifNewline,
|
||||||
|
'prefer-inline-type-import': preferInlineTypeImport,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -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' }],
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
})
|
@@ -0,0 +1,63 @@
|
|||||||
|
// Ported from https://github.com/gajus/eslint-plugin-canonical/blob/master/src/rules/preferInlineTypeImport.js
|
||||||
|
// by Gajus Kuizinas https://github.com/gajus
|
||||||
|
|
||||||
|
import { createEslintRule } from '../utils'
|
||||||
|
|
||||||
|
export const RULE_NAME = 'prefer-inline-type-import'
|
||||||
|
export type MessageIds = 'preferInlineTypeImport'
|
||||||
|
export type Options = []
|
||||||
|
|
||||||
|
export default createEslintRule<Options, MessageIds>({
|
||||||
|
name: RULE_NAME,
|
||||||
|
meta: {
|
||||||
|
type: 'suggestion',
|
||||||
|
docs: {
|
||||||
|
description: 'Newline after if',
|
||||||
|
recommended: 'error',
|
||||||
|
},
|
||||||
|
fixable: 'code',
|
||||||
|
schema: [],
|
||||||
|
messages: {
|
||||||
|
preferInlineTypeImport: 'Prefer inline type import',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultOptions: [],
|
||||||
|
create: (context) => {
|
||||||
|
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) {
|
||||||
|
yield * removeTypeSpecifier(fixer, sourceCode, node)
|
||||||
|
|
||||||
|
for (const specifier of node.specifiers)
|
||||||
|
yield fixer.insertTextBefore(specifier, 'type ')
|
||||||
|
},
|
||||||
|
loc: node.loc,
|
||||||
|
messageId: 'preferInlineTypeImport',
|
||||||
|
node,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
function *removeTypeSpecifier(fixer, sourceCode, node) {
|
||||||
|
const importKeyword = sourceCode.getFirstToken(node)
|
||||||
|
|
||||||
|
const typeIdentifier = sourceCode.getTokenAfter(importKeyword)
|
||||||
|
|
||||||
|
yield fixer.remove(typeIdentifier)
|
||||||
|
|
||||||
|
if (importKeyword.loc.end.column + 1 === typeIdentifier.loc.start.column) {
|
||||||
|
yield fixer.removeRange([
|
||||||
|
importKeyword.range[1],
|
||||||
|
importKeyword.range[1] + 1,
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-react",
|
"name": "@antfu/eslint-config-react",
|
||||||
"version": "0.19.4",
|
"version": "0.20.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -29,7 +29,12 @@ module.exports = {
|
|||||||
// Override JS
|
// Override JS
|
||||||
'no-useless-constructor': 'off',
|
'no-useless-constructor': 'off',
|
||||||
'indent': 'off',
|
'indent': 'off',
|
||||||
'@typescript-eslint/indent': ['error', 2],
|
'@typescript-eslint/indent': ['error', 2, {
|
||||||
|
ignoredNodes: [
|
||||||
|
'JSXAttribute',
|
||||||
|
'TSTypeParameterInstantiation',
|
||||||
|
],
|
||||||
|
}],
|
||||||
'no-unused-vars': 'off',
|
'no-unused-vars': 'off',
|
||||||
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
||||||
'no-redeclare': 'off',
|
'no-redeclare': 'off',
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-ts",
|
"name": "@antfu/eslint-config-ts",
|
||||||
"version": "0.19.4",
|
"version": "0.20.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-vue",
|
"name": "@antfu/eslint-config-vue",
|
||||||
"version": "0.19.4",
|
"version": "0.20.4",
|
||||||
"description": "",
|
"description": "",
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
Reference in New Issue
Block a user