Compare commits

...

23 Commits

Author SHA1 Message Date
Anthony Fu
38f64ae9af release v0.20.5 2022-04-17 13:15:15 +08:00
Anthony Fu
22527f61de fix: SwitchCase indent 2022-04-17 13:15:12 +08:00
Anthony Fu
1ff53f2f04 release v0.20.4 2022-04-17 12:49:51 +08:00
Anthony Fu
316bbd903b fix: ts indent ingores 2022-04-17 12:49:48 +08:00
Anthony Fu
bce5016b53 release v0.20.3 2022-04-16 09:03:18 +08:00
Anthony Fu
ddd34a9465 fix: do not require comma-dangle in markdown 2022-04-16 09:02:55 +08:00
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
Anthony Fu
0af15d4bf4 release v0.20.0 2022-04-07 05:53:53 +08:00
Anthony Fu
d23abea648 feat: add prefer-inline-type-import 2022-04-07 05:53:48 +08:00
Anthony Fu
eaff018580 Update README.md 2022-04-06 20:45:50 +08:00
Anthony Fu
327ab9dd35 chore: update 2022-04-05 04:45:55 +08:00
Anthony Fu
ea70c5c6aa release v0.19.4 2022-04-02 23:51:48 +08:00
Anthony Fu
2e9948029c feat: new if-newline rule 2022-04-02 23:51:24 +08:00
Anthony Fu
a6692cc074 release v0.19.3 2022-04-02 23:18:43 +08:00
Anthony Fu
ded3cf2da2 feat: custom plugin 2022-04-02 23:18:36 +08:00
Anthony Fu
f1644757c8 release v0.19.2 2022-03-31 22:19:38 +08:00
Anthony Fu
a695d58bd0 chore: bye lerna 2022-03-31 22:19:27 +08:00
CondorHero
5f05cfcfd6 fix: eslint-plugin-import support TypeScript (#77)
Co-authored-by: CondorHero <love2xinwei@gmail.com>
2022-03-31 22:19:07 +08:00
Anthony Fu
25668d5d1c v0.19.1 2022-03-30 16:57:53 +08:00
Anthony Fu
0cc68e6219 fix: missing file, close #76 2022-03-30 16:57:42 +08:00
28 changed files with 1569 additions and 3444 deletions

View File

@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [0.19.1](https://github.com/antfu/eslint-config/compare/v0.19.0...v0.19.1) (2022-03-30)
### Bug Fixes
* missing file, close [#76](https://github.com/antfu/eslint-config/issues/76) ([0cc68e6](https://github.com/antfu/eslint-config/commit/0cc68e6219601b09ac8e258b869f23308e073af5))
# [0.19.0](https://github.com/antfu/eslint-config/compare/v0.18.9...v0.19.0) (2022-03-29)

View File

@@ -34,7 +34,8 @@ For example:
```json
{
"scripts": {
"lint": "eslint ."
"lint": "eslint .",
"lint:fix": "eslint . --fix"
}
}
```
@@ -54,7 +55,9 @@ Create `.vscode/settings.json`
## 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/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/vitesse](https://github.com/antfu/vitesse) - My starter template for Vue & Vite app

View File

@@ -1,6 +0,0 @@
{
"packages": [
"packages/*"
],
"version": "0.19.0"
}

View File

@@ -1,17 +1,19 @@
{
"name": "@antfu/eslint-config-monorepo",
"version": "0.20.5",
"private": true,
"license": "MIT",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"scripts": {
"preinstall": "npx only-allow pnpm",
"lint": "eslint .",
"release": "lerna publish --conventional-commits"
"prepare": "pnpm -r run stub",
"release": "bumpp package.json packages/*/package.json --commit --push --tag && pnpm -r publish --access public"
},
"devDependencies": {
"@antfu/eslint-config": "*",
"bumpp": "^7.1.1",
"eslint": "^8.12.0",
"lerna": "^4.0.0",
"eslint-plugin-antfu": "workspace:*",
"typescript": "^4.6.3"
}
}

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [0.19.1](https://github.com/antfu/eslint-config/compare/v0.19.0...v0.19.1) (2022-03-30)
**Note:** Version bump only for package @antfu/eslint-config
# [0.19.0](https://github.com/antfu/eslint-config/compare/v0.18.9...v0.19.0) (2022-03-29)

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config",
"version": "0.19.0",
"version": "0.20.5",
"description": "",
"keywords": [],
"license": "MIT",
@@ -13,8 +13,8 @@
"eslint": ">=7.4.0"
},
"dependencies": {
"@antfu/eslint-config-react": "^0.19.0",
"@antfu/eslint-config-vue": "^0.19.0",
"@antfu/eslint-config-react": "workspace:*",
"@antfu/eslint-config-vue": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"eslint-plugin-eslint-comments": "^3.2.0",

View File

@@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [0.19.1](https://github.com/antfu/eslint-config/compare/v0.19.0...v0.19.1) (2022-03-30)
### Bug Fixes
* missing file, close [#76](https://github.com/antfu/eslint-config/issues/76) ([0cc68e6](https://github.com/antfu/eslint-config/commit/0cc68e6219601b09ac8e258b869f23308e073af5))
# [0.19.0](https://github.com/antfu/eslint-config/compare/v0.18.9...v0.19.0) (2022-03-29)

View File

@@ -32,10 +32,11 @@ module.exports = {
plugins: [
'html',
'unicorn',
'antfu',
],
settings: {
'import/resolver': {
node: { extensions: ['.js', '.mjs', '.ts', '.d.ts'] },
node: { extensions: ['.js', '.mjs'] },
},
},
overrides: [
@@ -134,6 +135,7 @@ module.exports = {
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/comma-dangle': 'off',
'import/no-unresolved': 'off',
'no-alert': 'off',
'no-console': 'off',
@@ -288,5 +290,10 @@ module.exports = {
// yml
'yml/quotes': ['error', { prefer: 'single', avoidEscape: false }],
'yml/no-empty-document': 'off',
// antfu
'antfu/no-leading-newline': 'error',
'antfu/if-newline': 'error',
// 'antfu/prefer-inline-type-import': 'error',
},
}

View File

@@ -1,13 +1,13 @@
{
"name": "@antfu/eslint-config-basic",
"version": "0.19.0",
"version": "0.20.5",
"description": "",
"keywords": [],
"license": "MIT",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"main": "index.js",
"files": [
"index.js"
"*.js"
],
"scripts": {
"lint": "eslint . --config=index.js"
@@ -16,6 +16,7 @@
"eslint": ">=7.4.0"
},
"dependencies": {
"eslint-plugin-antfu": "workspace:*",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^6.2.0",
"eslint-plugin-import": "^2.25.4",

View File

@@ -0,0 +1,9 @@
{
"extends": "@antfu",
"plugins": [
"antfu"
],
"rules": {
"antfu/no-leading-newline": "error"
}
}

View File

@@ -0,0 +1,12 @@
import { defineBuildConfig } from 'unbuild'
export default defineBuildConfig({
entries: [
'src/index',
],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
},
})

View File

@@ -0,0 +1,31 @@
{
"name": "eslint-plugin-antfu",
"version": "0.20.5",
"license": "MIT",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist"
],
"scripts": {
"build": "rimraf dist && unbuild",
"stub": "unbuild --stub",
"test": "vitest",
"prepublishOnly": "nr build"
},
"dependencies": {
"@typescript-eslint/utils": "^5.17.0"
},
"devDependencies": {
"unbuild": "^0.7.0",
"vitest": "^0.8.2"
}
}

View File

@@ -0,0 +1,11 @@
import ifNewline from './rules/if-newline'
import noLeadingNewline from './rules/no-leading-newline'
import preferInlineTypeImport from './rules/prefer-inline-type-import'
export default {
rules: {
'no-leading-newline': noLeadingNewline,
'if-newline': ifNewline,
'prefer-inline-type-import': preferInlineTypeImport,
},
}

View File

@@ -0,0 +1,30 @@
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
import { it } from 'vitest'
import rule, { RULE_NAME } from './if-newline'
const valids = [
`if (true)
console.log('hello')
`,
`if (true) {
console.log('hello')
}`,
]
const invalids = [
['if (true) console.log(\'hello\')', 'if (true) \nconsole.log(\'hello\')'],
]
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],
errors: [{ messageId: 'missingIfNewline' }],
})),
})
})

View File

@@ -0,0 +1,45 @@
import { createEslintRule } from '../utils'
export const RULE_NAME = 'if-newline'
export type MessageIds = 'missingIfNewline'
export type Options = []
export default createEslintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Newline after if',
recommended: 'error',
},
fixable: 'code',
schema: [],
messages: {
missingIfNewline: 'Expect newline after if',
},
},
defaultOptions: [],
create: (context) => {
return {
IfStatement(node) {
if (!node.consequent)
return
if (node.consequent.type === 'BlockStatement')
return
if (node.test.loc.end.line === node.consequent.loc.start.line) {
context.report({
node,
loc: {
start: node.test.loc.end,
end: node.consequent.loc.start,
},
messageId: 'missingIfNewline',
fix(fixer) {
return fixer.replaceTextRange([node.consequent.range[0], node.consequent.range[0]], '\n')
},
})
}
},
}
},
})

View File

@@ -0,0 +1,27 @@
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
import { it } from 'vitest'
import rule, { RULE_NAME } from './no-leading-newline'
const valids = [
'import {} from \'foo\'',
`// comment
import {} from ''`,
]
const invalids = [
'\n\nimport {} from \'fo\'',
]
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,
output: i.trim(),
errors: [{ messageId: 'noLeadingNewline' }],
})),
})
})

View File

@@ -0,0 +1,44 @@
import { createEslintRule } from '../utils'
export const RULE_NAME = 'no-leading-newline'
export type MessageIds = 'noLeadingNewline'
export type Options = []
export default createEslintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Do not allow leading newline',
recommended: 'error',
},
fixable: 'whitespace',
schema: [],
messages: {
noLeadingNewline: 'No leading newline allowed',
},
},
defaultOptions: [],
create: (context) => {
return {
Program(node) {
const code = context.getSourceCode()
const match = code.text.match(/^[\s]+/)?.[0] || ''
if (match.includes('\n')) {
const line = match.split('\n')
context.report({
node,
loc: {
start: { line: 0, column: 0 },
end: { line: line.length - 1, column: line[line.length - 1].length },
},
messageId: 'noLeadingNewline',
fix(fixer) {
return fixer.replaceTextRange([0, match.length], '')
},
})
}
},
}
},
})

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

@@ -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,
])
}
}

View File

@@ -0,0 +1,5 @@
import { ESLintUtils } from '@typescript-eslint/utils'
export const createEslintRule = ESLintUtils.RuleCreator(
ruleName => ruleName,
)

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [0.19.1](https://github.com/antfu/eslint-config/compare/v0.19.0...v0.19.1) (2022-03-30)
**Note:** Version bump only for package @antfu/eslint-config-react
# [0.19.0](https://github.com/antfu/eslint-config/compare/v0.18.9...v0.19.0) (2022-03-29)
**Note:** Version bump only for package @antfu/eslint-config-react

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-react",
"version": "0.19.0",
"version": "0.20.5",
"description": "",
"keywords": [],
"license": "MIT",
@@ -19,7 +19,7 @@
"access": "public"
},
"dependencies": {
"@antfu/eslint-config-ts": "^0.19.0",
"@antfu/eslint-config-ts": "workspace:*",
"eslint-plugin-react": "^7.29.4"
},
"devDependencies": {

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [0.19.1](https://github.com/antfu/eslint-config/compare/v0.19.0...v0.19.1) (2022-03-30)
**Note:** Version bump only for package @antfu/eslint-config-ts
# [0.19.0](https://github.com/antfu/eslint-config/compare/v0.18.9...v0.19.0) (2022-03-29)
**Note:** Version bump only for package @antfu/eslint-config-ts

View File

@@ -4,8 +4,14 @@ const basic = require('@antfu/eslint-config-basic')
module.exports = {
extends: [
'@antfu/eslint-config-basic',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
],
settings: {
'import/resolver': {
node: { extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.d.ts'] },
},
},
overrides: basic.overrides,
rules: {
'import/named': 'off',
@@ -23,7 +29,13 @@ module.exports = {
// Override JS
'no-useless-constructor': 'off',
'indent': 'off',
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/indent': ['error', 2, {
ignoredNodes: [
'JSXAttribute',
'TSTypeParameterInstantiation',
],
SwitchCase: 1,
}],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'no-redeclare': 'off',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-ts",
"version": "0.19.0",
"version": "0.20.5",
"description": "",
"keywords": [],
"license": "MIT",
@@ -17,7 +17,7 @@
"typescript": ">=3.9"
},
"dependencies": {
"@antfu/eslint-config-basic": "^0.19.0",
"@antfu/eslint-config-basic": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0"
},

View File

@@ -3,6 +3,14 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [0.19.1](https://github.com/antfu/eslint-config/compare/v0.19.0...v0.19.1) (2022-03-30)
**Note:** Version bump only for package @antfu/eslint-config-vue
# [0.19.0](https://github.com/antfu/eslint-config/compare/v0.18.9...v0.19.0) (2022-03-29)

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-vue",
"version": "0.19.0",
"version": "0.20.5",
"description": "",
"keywords": [],
"license": "MIT",
@@ -16,7 +16,7 @@
"access": "public"
},
"dependencies": {
"@antfu/eslint-config-ts": "^0.19.0",
"@antfu/eslint-config-ts": "workspace:*",
"eslint-plugin-vue": "^8.5.0"
},
"devDependencies": {

4590
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff