Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: antfu/eslint-config
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.20.7
Choose a base ref
...
head repository: antfu/eslint-config
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.21.0
Choose a head ref
  • 4 commits
  • 14 files changed
  • 3 contributors

Commits on Apr 24, 2022

  1. Copy the full SHA
    686f285 View commit details
  2. Copy the full SHA
    17670e8 View commit details

Commits on Apr 25, 2022

  1. Copy the full SHA
    0ab9f88 View commit details
  2. release v0.21.0

    antfu committed Apr 25, 2022
    Copy the full SHA
    b8fe1fa View commit details
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-monorepo",
"version": "0.20.7",
"version": "0.21.0",
"private": true,
"license": "MIT",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
2 changes: 1 addition & 1 deletion packages/all/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config",
"version": "0.20.7",
"version": "0.21.0",
"description": "",
"keywords": [],
"license": "MIT",
12 changes: 10 additions & 2 deletions packages/basic/index.js
Original file line number Diff line number Diff line change
@@ -183,7 +183,15 @@ module.exports = {
],
'object-curly-spacing': ['error', 'always'],
'no-return-await': 'off',
'space-before-function-paren': ['error', 'never'],
'space-before-function-paren': [
'error',
{
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
},
],
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 1 }],

// es6
'no-var': 'error',
@@ -292,8 +300,8 @@ module.exports = {
'yml/no-empty-document': 'off',

// antfu
'antfu/no-leading-newline': 'error',
'antfu/if-newline': 'error',
'antfu/import-dedupe': 'error',
// 'antfu/prefer-inline-type-import': 'error',
},
}
2 changes: 1 addition & 1 deletion packages/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-basic",
"version": "0.20.7",
"version": "0.21.0",
"description": "",
"keywords": [],
"license": "MIT",
9 changes: 8 additions & 1 deletion packages/basic/standard.js
Original file line number Diff line number Diff line change
@@ -202,7 +202,14 @@ module.exports = {
'semi': ['error', 'never'],
'semi-spacing': ['error', { before: false, after: true }],
'space-before-blocks': ['error', 'always'],
'space-before-function-paren': ['error', 'always'],
'space-before-function-paren': [
'error',
{
'anonymous': 'always',
'named': 'never',
'asyncArrow': 'always'
}
],
'space-in-parens': ['error', 'never'],
'space-infix-ops': 'error',
'space-unary-ops': ['error', { words: true, nonwords: false }],
5 changes: 1 addition & 4 deletions packages/eslint-plugin-antfu/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -2,8 +2,5 @@
"extends": "@antfu",
"plugins": [
"antfu"
],
"rules": {
"antfu/no-leading-newline": "error"
}
]
}
2 changes: 1 addition & 1 deletion packages/eslint-plugin-antfu/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-antfu",
"version": "0.20.7",
"version": "0.21.0",
"license": "MIT",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
4 changes: 2 additions & 2 deletions packages/eslint-plugin-antfu/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ifNewline from './rules/if-newline'
import noLeadingNewline from './rules/no-leading-newline'
import importDedupe from './rules/import-dedupe'
import preferInlineTypeImport from './rules/prefer-inline-type-import'

export default {
rules: {
'no-leading-newline': noLeadingNewline,
'if-newline': ifNewline,
'import-dedupe': importDedupe,
'prefer-inline-type-import': preferInlineTypeImport,
},
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
import { it } from 'vitest'
import rule, { RULE_NAME } from './no-leading-newline'
import rule, { RULE_NAME } from './import-dedupe'

const valids = [
'import {} from \'foo\'',
`// comment
import {} from ''`,
'import { a } from \'foo\'',
]
const invalids = [
'\n\nimport {} from \'fo\'',
[
'import { a, b, a, a, c, a } from \'foo\'',
'import { a, b, c, } from \'foo\'',
],
]

it('runs', () => {
@@ -19,9 +20,9 @@ it('runs', () => {
ruleTester.run(RULE_NAME, rule, {
valid: valids,
invalid: invalids.map(i => ({
code: i,
output: i.trim(),
errors: [{ messageId: 'noLeadingNewline' }],
code: i[0],
output: i[1],
errors: [{ messageId: 'importDedupe' }, { messageId: 'importDedupe' }, { messageId: 'importDedupe' }],
})),
})
})
55 changes: 55 additions & 0 deletions packages/eslint-plugin-antfu/src/rules/import-dedupe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { createEslintRule } from '../utils'

export const RULE_NAME = 'import-dedupe'
export type MessageIds = 'importDedupe'
export type Options = []

export default createEslintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Fix duplication in imports',
recommended: 'error',
},
fixable: 'code',
schema: [],
messages: {
importDedupe: 'Expect no duplication in imports',
},
},
defaultOptions: [],
create: (context) => {
return {
ImportDeclaration(node) {
if (node.specifiers.length <= 1)
return

const names = new Set<string>()
node.specifiers.forEach((n) => {
const id = n.local.name
if (names.has(id)) {
context.report({
node,
loc: {
start: n.loc.end,
end: n.loc.start,
},
messageId: 'importDedupe',
fix(fixer) {
const s = n.range[0]
let e = n.range[1]
if (context.getSourceCode().text[e] === ',')
e += 1
return fixer.removeRange([s, e])
},
})
}
names.add(id)
})

// console.log(node)
},
}
},
})
44 changes: 0 additions & 44 deletions packages/eslint-plugin-antfu/src/rules/no-leading-newline.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-react",
"version": "0.20.7",
"version": "0.21.0",
"description": "",
"keywords": [],
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-ts",
"version": "0.20.7",
"version": "0.21.0",
"description": "",
"keywords": [],
"license": "MIT",
2 changes: 1 addition & 1 deletion packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-vue",
"version": "0.20.7",
"version": "0.21.0",
"description": "",
"keywords": [],
"license": "MIT",