Compare commits

...

26 Commits

Author SHA1 Message Date
Anthony Fu
a9b6d5f9ee release v0.23.0 2022-05-03 01:12:25 +08:00
Anthony Fu
e6a4d6db8b chore: update deps 2022-05-03 01:12:21 +08:00
QiroNT
ed0f5b1d76 feat: vue extensions (#89) 2022-05-03 01:07:25 +08:00
zz
65222e2e3a fix: remove deprecated rules (#88) 2022-05-03 00:10:59 +08:00
Anthony Fu
a1e890844f release v0.22.0 2022-05-01 08:53:43 +08:00
QiroNT
a2de527401 fix: complete typescript overrides (#87)
* fix: complete typescript overrides

* chore: typo
2022-05-01 08:53:21 +08:00
Anthony Fu
6080d3f74d release v0.21.1 2022-04-26 01:43:55 +08:00
liuq
b996c58bac fix: fixed rules not works (#86)
Co-authored-by: linka <lqadm@qq.com>
2022-04-26 01:43:26 +08:00
Anthony Fu
b8fe1fabea release v0.21.0 2022-04-25 13:26:25 +08:00
Anthony Fu
0ab9f88603 feat(eslint-plugin): new import dedupe rule 2022-04-25 13:26:07 +08:00
liyujun
17670e8e38 fix: space-before-function-paren allows space in anonymous and asyncArrow function. (#84) 2022-04-25 01:02:25 +08:00
Coder Zhao
686f285a37 chore: replace no-leading-newline with no-multiple-empty-lines (#82) 2022-04-24 22:11:01 +08:00
Anthony Fu
2d9efd4df6 release v0.20.7 2022-04-23 09:23:16 +08:00
Anthony Fu
b8e6cdf047 chore: updete deps 2022-04-23 09:23:11 +08:00
Anthony Fu
50c962197b release v0.20.6 2022-04-17 13:17:38 +08:00
Anthony Fu
bf19dc0adb fix: indents 2022-04-17 13:17:35 +08:00
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
19 changed files with 625 additions and 408 deletions

View File

@@ -1,6 +1,7 @@
{
"name": "@antfu/eslint-config-monorepo",
"version": "0.20.0",
"version": "0.23.0",
"packageManager": "pnpm@7.0.0",
"private": true,
"license": "MIT",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
@@ -12,8 +13,8 @@
"devDependencies": {
"@antfu/eslint-config": "*",
"bumpp": "^7.1.1",
"eslint": "^8.12.0",
"eslint": "^8.14.0",
"eslint-plugin-antfu": "workspace:*",
"typescript": "^4.6.3"
"typescript": "^4.6.4"
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config",
"version": "0.20.0",
"version": "0.23.0",
"description": "",
"keywords": [],
"license": "MIT",
@@ -15,22 +15,22 @@
"dependencies": {
"@antfu/eslint-config-react": "workspace:*",
"@antfu/eslint-config-vue": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0",
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^6.2.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsonc": "^2.2.1",
"eslint-plugin-n": "^15.1.0",
"eslint-plugin-n": "^15.2.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-unicorn": "^41.0.1",
"eslint-plugin-vue": "^8.5.0",
"eslint-plugin-unicorn": "^42.0.0",
"eslint-plugin-vue": "^8.7.1",
"eslint-plugin-yml": "^0.14.0",
"jsonc-eslint-parser": "^2.1.0",
"yaml-eslint-parser": "^0.5.0"
},
"devDependencies": {
"eslint": "^8.12.0"
"eslint": "^8.14.0"
},
"publishConfig": {
"access": "public"

View File

@@ -44,9 +44,9 @@ module.exports = {
files: ['*.json', '*.json5'],
parser: 'jsonc-eslint-parser',
rules: {
'quotes': ['error', 'double'],
'quote-props': ['error', 'always'],
'comma-dangle': ['error', 'never'],
'jsonc/quotes': ['error', 'double'],
'jsonc/quote-props': ['error', 'always'],
'jsonc/comma-dangle': ['error', 'never'],
},
},
{
@@ -135,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',
@@ -182,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',
@@ -291,8 +300,8 @@ module.exports = {
'yml/no-empty-document': 'off',
// antfu
'antfu/no-leading-newline': 'error',
'antfu/if-newline': 'error',
'antfu/prefer-inline-type-import': 'error',
'antfu/import-dedupe': 'error',
// 'antfu/prefer-inline-type-import': 'error',
},
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-basic",
"version": "0.20.0",
"version": "0.23.0",
"description": "",
"keywords": [],
"license": "MIT",
@@ -19,18 +19,18 @@
"eslint-plugin-antfu": "workspace:*",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^6.2.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsonc": "^2.2.1",
"eslint-plugin-markdown": "^2.2.1",
"eslint-plugin-n": "^15.1.0",
"eslint-plugin-n": "^15.2.0",
"eslint-plugin-promise": "^6.0.0",
"eslint-plugin-unicorn": "^41.0.1",
"eslint-plugin-unicorn": "^42.0.0",
"eslint-plugin-yml": "^0.14.0",
"jsonc-eslint-parser": "^2.1.0",
"yaml-eslint-parser": "^0.5.0"
},
"devDependencies": {
"eslint": "^8.12.0"
"eslint": "^8.14.0"
},
"publishConfig": {
"access": "public"

View File

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

View File

@@ -2,8 +2,5 @@
"extends": "@antfu",
"plugins": [
"antfu"
],
"rules": {
"antfu/no-leading-newline": "error"
}
]
}

View File

@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-antfu",
"version": "0.20.0",
"version": "0.23.0",
"license": "MIT",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
@@ -22,10 +22,10 @@
"prepublishOnly": "nr build"
},
"dependencies": {
"@typescript-eslint/utils": "^5.17.0"
"@typescript-eslint/utils": "^5.22.0"
},
"devDependencies": {
"unbuild": "^0.7.0",
"vitest": "^0.8.2"
"unbuild": "^0.7.4",
"vitest": "^0.9.4"
}
}

View File

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

View File

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

View File

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

View File

@@ -1,44 +0,0 @@
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

@@ -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.23.0",
"description": "",
"keywords": [],
"license": "MIT",
@@ -23,8 +23,8 @@
"eslint-plugin-react": "^7.29.4"
},
"devDependencies": {
"eslint": "^8.12.0",
"react": "^18.0.0",
"typescript": "^4.6.3"
"eslint": "^8.14.0",
"react": "^18.1.0",
"typescript": "^4.6.4"
}
}

View File

@@ -17,7 +17,6 @@ module.exports = {
'import/named': 'off',
// TS
'@typescript-eslint/semi': ['error', 'never'],
'@typescript-eslint/ban-ts-comment': ['error', { 'ts-ignore': 'allow-with-description' }],
'@typescript-eslint/member-delimiter-style': ['error', { multiline: { delimiter: 'none' } }],
'@typescript-eslint/type-annotation-spacing': ['error', {}],
@@ -29,7 +28,41 @@ module.exports = {
// Override JS
'no-useless-constructor': 'off',
'indent': 'off',
'@typescript-eslint/indent': ['error', 2],
'@typescript-eslint/indent': ['error', 2, {
SwitchCase: 1,
VariableDeclarator: 1,
outerIIFEBody: 1,
MemberExpression: 1,
FunctionDeclaration: { parameters: 1, body: 1 },
FunctionExpression: { parameters: 1, body: 1 },
CallExpression: { arguments: 1 },
ArrayExpression: 1,
ObjectExpression: 1,
ImportDeclaration: 1,
flatTernaryExpressions: false,
ignoreComments: false,
ignoredNodes: [
'TemplateLiteral *',
'JSXElement',
'JSXElement > *',
'JSXAttribute',
'JSXIdentifier',
'JSXNamespacedName',
'JSXMemberExpression',
'JSXSpreadAttribute',
'JSXExpressionContainer',
'JSXOpeningElement',
'JSXClosingElement',
'JSXFragment',
'JSXOpeningFragment',
'JSXClosingFragment',
'JSXText',
'JSXEmptyExpression',
'JSXSpreadChild',
'TSTypeParameterInstantiation',
],
offsetTernaryExpressions: true,
}],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'no-redeclare': 'off',
@@ -42,13 +75,50 @@ module.exports = {
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
'object-curly-spacing': 'off',
'@typescript-eslint/object-curly-spacing': ['error', 'always'],
'semi': 'off',
'@typescript-eslint/semi': ['error', 'never'],
'quotes': 'off',
'@typescript-eslint/quotes': ['error', 'single'],
'space-before-blocks': 'off',
'@typescript-eslint/space-before-blocks': ['error', 'always'],
'space-before-function-paren': 'off',
'@typescript-eslint/space-before-function-paren': [
'error',
{
anonymous: 'always',
named: 'never',
asyncArrow: 'always',
},
],
'space-infix-ops': 'off',
'@typescript-eslint/space-infix-ops': 'error',
'keyword-spacing': 'off',
'@typescript-eslint/keyword-spacing': ['error', { before: true, after: true }],
'comma-spacing': 'off',
'@typescript-eslint/comma-spacing': ['error', { before: false, after: true }],
'no-extra-parens': 'off',
'@typescript-eslint/no-extra-parens': ['error', 'functions'],
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': 'error',
'no-loss-of-precision': 'off',
'@typescript-eslint/no-loss-of-precision': 'error',
'lines-between-class-members': 'off',
'@typescript-eslint/lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
// The following rule overrides require a parser service, aka. require a `typescript.json` path.
// This needs to be done individually for each project, and it slows down linting significantly.
// 'no-throw-literal': 'off',
// '@typescript-eslint/no-throw-literal': 'error',
// 'no-implied-eval': 'off',
// '@typescript-eslint/no-implied-eval': 'error',
// 'dot-notation': 'off',
// '@typescript-eslint/dot-notation': ['error', { allowKeywords: true }],
// off
'@typescript-eslint/camelcase': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/parameter-properties': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/no-empty-function': 'off',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-ts",
"version": "0.20.0",
"version": "0.23.0",
"description": "",
"keywords": [],
"license": "MIT",
@@ -18,10 +18,10 @@
},
"dependencies": {
"@antfu/eslint-config-basic": "workspace:*",
"@typescript-eslint/eslint-plugin": "^5.17.0",
"@typescript-eslint/parser": "^5.17.0"
"@typescript-eslint/eslint-plugin": "^5.22.0",
"@typescript-eslint/parser": "^5.22.0"
},
"devDependencies": {
"eslint": "^8.12.0"
"eslint": "^8.14.0"
}
}

View File

@@ -30,5 +30,68 @@ module.exports = {
'vue/component-tags-order': ['error', {
order: ['script', 'template', 'style'],
}],
'vue/block-tag-newline': ['error', {
singleline: 'always',
multiline: 'always',
}],
'vue/component-name-in-template-casing': ['error', 'PascalCase'],
'vue/component-options-name-casing': ['error', 'PascalCase'],
'vue/custom-event-name-casing': ['error', 'camelCase'],
'vue/define-macros-order': ['error', {
order: ['defineProps', 'defineEmits'],
}],
'vue/html-comment-content-spacing': ['error', 'always', {
exceptions: ['-'],
}],
'vue/no-restricted-v-bind': ['error', '/^v-/'],
'vue/no-useless-v-bind': 'error',
'vue/no-v-text-v-html-on-component': 'error',
'vue/padding-line-between-blocks': ['error', 'always'],
'vue/prefer-separate-static-class': 'error',
// extensions
'vue/array-bracket-spacing': ['error', 'never'],
'vue/arrow-spacing': ['error', { before: true, after: true }],
'vue/block-spacing': ['error', 'always'],
'vue/brace-style': ['error', 'stroustrup', { allowSingleLine: true }],
'vue/comma-dangle': ['error', 'always-multiline'],
'vue/comma-spacing': ['error', { before: false, after: true }],
'vue/comma-style': ['error', 'last'],
'vue/dot-location': ['error', 'property'],
'vue/dot-notation': ['error', { allowKeywords: true }],
'vue/eqeqeq': ['error', 'smart'],
// 'vue/func-call-spacing': ['off', 'never'],
'vue/key-spacing': ['error', { beforeColon: false, afterColon: true }],
'vue/keyword-spacing': ['error', { before: true, after: true }],
'vue/no-constant-condition': 'warn',
'vue/no-empty-pattern': 'error',
'vue/no-extra-parens': ['error', 'functions'],
'vue/no-irregular-whitespace': 'error',
'vue/no-loss-of-precision': 'error',
'vue/no-restricted-syntax': [
'error',
'DebuggerStatement',
'LabeledStatement',
'WithStatement',
],
'vue/no-sparse-arrays': 'error',
'vue/object-curly-newline': ['error', { multiline: true, consistent: true }],
'vue/object-curly-spacing': ['error', 'always'],
'vue/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
'vue/object-shorthand': [
'error',
'always',
{
ignoreConstructors: false,
avoidQuotes: true,
},
],
'vue/operator-linebreak': ['error', 'before'],
'vue/prefer-template': 'error',
'vue/quote-props': ['error', 'consistent-as-needed'],
'vue/space-in-parens': ['error', 'never'],
'vue/space-infix-ops': 'error',
'vue/space-unary-ops': ['error', { words: true, nonwords: false }],
'vue/template-curly-spacing': 'error',
},
}

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-vue",
"version": "0.20.0",
"version": "0.23.0",
"description": "",
"keywords": [],
"license": "MIT",
@@ -17,9 +17,9 @@
},
"dependencies": {
"@antfu/eslint-config-ts": "workspace:*",
"eslint-plugin-vue": "^8.5.0"
"eslint-plugin-vue": "^8.7.1"
},
"devDependencies": {
"eslint": "^8.12.0"
"eslint": "^8.14.0"
}
}

644
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff