Compare commits

...

7 Commits

Author SHA1 Message Date
Anthony Fu
c1355234c0 chore: release v0.39.6 2023-06-28 14:10:34 +02:00
Julian Meinking
6dfc773b05 docs: add eslint.validate to enable linting for supported filetypes with VSCode ESLint (#204)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
2023-06-28 14:10:01 +02:00
曾明健
2bf0c8d727 feat(ts): ban const enum (#201) 2023-06-28 14:05:23 +02:00
arily
504de8392a feat: switch to eslint-plugin-i (#205) 2023-06-28 14:04:55 +02:00
Mert
6cf4794985 docs: update organizeImports config for VS Code (#202) 2023-06-18 12:42:25 +02:00
曾明健
bbed70b969 refactor: use existing rules (#198) 2023-06-06 18:01:05 +02:00
Kirk Lin
f553c519f6 feat(vue): enforce order of define macros (#196) 2023-06-06 11:32:33 +02:00
15 changed files with 131 additions and 84 deletions

View File

@@ -41,23 +41,43 @@ For example:
}
```
### Config VS Code auto fix
### VS Code support (auto fix)
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) and create `.vscode/settings.json`
Install [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
```json
Add the following settings to your `settings.json`:
```jsonc
{
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": true,
"source.organizeImports": false,
// The following is optional.
// It's better to put under project setting `.vscode/settings.json`
// to avoid conflicts with working with different eslint configs
// that does not support all formats.
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml"
]
}
}
```
### TypeScript Aware Rules
Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root, which will introduce some stricter rules into your project. If you want to enable it while have no `tsconfig.eslint.json` in the project root, you can change tsconfig name by modifying `ESLINT_TSCONFIG` env.
Type aware rules are enabled when a `tsconfig.eslint.json` is found in the project root, which will introduce some stricter rules into your project. If you want to enable it while have no `tsconfig.eslint.json` in the project root, you can change tsconfig name by modifying `ESLINT_TSCONFIG` env.
```js
// .eslintrc.js

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-monorepo",
"version": "0.39.5",
"version": "0.39.6",
"private": true,
"packageManager": "pnpm@8.5.1",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",

View File

@@ -263,23 +263,10 @@ module.exports = {
'error',
{ name: 'global', message: 'Use `globalThis` instead.' },
{ name: 'self', message: 'Use `globalThis` instead.' },
{ name: 'isNaN', message: 'Use `Number.isNaN` instead.' },
{ name: 'isFinite', message: 'Use `Number.isFinite` instead.' },
{ name: 'parseFloat', message: 'Use `Number.parseFloat` instead.' },
{ name: 'parseInt', message: 'Use `Number.parseInt` instead.' },
],
'no-restricted-properties': [
'error',
{ object: 'globalThis', property: 'isNaN', message: 'Use `Number.isNaN` instead.' },
{ object: 'globalThis', property: 'isFinite', message: 'Use `Number.isFinite` instead.' },
{ object: 'globalThis', property: 'parseFloat', message: 'Use `Number.parseFloat` instead.' },
{ object: 'globalThis', property: 'parseInt', message: 'Use `Number.parseInt` instead.' },
{ object: 'window', property: 'isNaN', message: 'Use `Number.isNaN` instead.' },
{ object: 'window', property: 'isFinite', message: 'Use `Number.isFinite` instead.' },
{ object: 'window', property: 'parseFloat', message: 'Use `Number.parseFloat` instead.' },
{ object: 'window', property: 'parseInt', message: 'Use `Number.parseInt` instead.' },
{ object: 'Math', property: 'pow', message: 'Use the exponentiation operator (**) instead.' },
{ property: '__proto__', message: 'Use `Object.getPrototypeOf` instead.' },
{ property: '__proto__', message: 'Use `Object.getPrototypeOf` or `Object.setPrototypeOf` instead.' },
{ property: '__defineGetter__', message: 'Use `Object.defineProperty` instead.' },
{ property: '__defineSetter__', message: 'Use `Object.defineProperty` instead.' },
{ property: '__lookupGetter__', message: 'Use `Object.getOwnPropertyDescriptor` instead.' },
@@ -379,6 +366,8 @@ module.exports = {
'unicorn/throw-new-error': 'error',
// Prefer using the node: protocol
'unicorn/prefer-node-protocol': 'error',
// Prefer using number properties like `Number.isNaN` rather than `isNaN`
'unicorn/prefer-number-properties': 'error',
'no-use-before-define': ['error', { functions: false, classes: false, variables: true }],
'eslint-comments/disable-enable-pair': 'off',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-basic",
"version": "0.39.5",
"version": "0.39.6",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -22,7 +22,7 @@
"eslint-plugin-antfu": "workspace:*",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "npm:eslint-plugin-i@2.27.5-3",
"eslint-plugin-jsonc": "^2.8.0",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-n": "^16.0.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-react",
"version": "0.39.5",
"version": "0.39.6",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",

View File

@@ -159,6 +159,7 @@ module.exports = {
'antfu/generic-spacing': 'error',
'antfu/no-cjs-exports': 'error',
'antfu/no-ts-export-equal': 'error',
'antfu/no-const-enum': 'error',
// off
'@typescript-eslint/consistent-indexed-object-style': 'off',

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-ts",
"version": "0.39.5",
"version": "0.39.6",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",

View File

@@ -52,7 +52,7 @@ module.exports = {
'vue/component-options-name-casing': ['error', 'PascalCase'],
'vue/custom-event-name-casing': ['error', 'camelCase'],
'vue/define-macros-order': ['error', {
order: ['defineProps', 'defineEmits'],
order: ['defineOptions', 'defineProps', 'defineEmits', 'defineSlots'],
}],
'vue/html-comment-content-spacing': ['error', 'always', {
exceptions: ['-'],

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config-vue",
"version": "0.39.5",
"version": "0.39.6",
"description": "",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",

View File

@@ -1,6 +1,6 @@
{
"name": "@antfu/eslint-config",
"version": "0.39.5",
"version": "0.39.6",
"description": "Anthony's ESLint config",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
"license": "MIT",
@@ -21,7 +21,7 @@
"@typescript-eslint/parser": "^5.59.7",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-html": "^7.1.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-import": "npm:eslint-plugin-i@2.27.5-3",
"eslint-plugin-jsonc": "^2.8.0",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-promise": "^6.1.1",

View File

@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-antfu",
"version": "0.39.5",
"version": "0.39.6",
"license": "MIT",
"homepage": "https://github.com/antfu/eslint-config",
"main": "./dist/index.cjs",

View File

@@ -5,6 +5,7 @@ import preferInlineTypeImport from './rules/prefer-inline-type-import'
import topLevelFunction from './rules/top-level-function'
import noTsExportEqual from './rules/no-ts-export-equal'
import noCjsExports from './rules/no-cjs-exports'
import noConstEnum from './rules/no-const-enum'
export default {
rules: {
@@ -15,5 +16,6 @@ export default {
'top-level-function': topLevelFunction,
'no-cjs-exports': noCjsExports,
'no-ts-export-equal': noTsExportEqual,
'no-const-enum': noConstEnum,
},
}

View File

@@ -0,0 +1,25 @@
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
import { it } from 'vitest'
import rule, { RULE_NAME } from './no-const-enum'
const valids = [
'enum E {}',
]
const invalids = [
'const enum E {}',
]
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,
errors: [{ messageId: 'noConstEnum' }],
})),
})
})

View File

@@ -0,0 +1,33 @@
import { createEslintRule } from '../utils'
export const RULE_NAME = 'no-const-enum'
export type MessageIds = 'noConstEnum'
export type Options = []
export default createEslintRule<Options, MessageIds>({
name: RULE_NAME,
meta: {
type: 'problem',
docs: {
description: 'Disallow using `const enum` expression',
recommended: 'error',
},
schema: [],
messages: {
noConstEnum: 'Do not use `const enum` expression',
},
},
defaultOptions: [],
create: (context) => {
return {
TSEnumDeclaration: (node) => {
if (node.const) {
context.report({
node,
messageId: 'noConstEnum',
})
}
},
}
},
})

87
pnpm-lock.yaml generated
View File

@@ -41,8 +41,8 @@ importers:
specifier: ^7.1.0
version: 7.1.0
eslint-plugin-import:
specifier: ^2.27.5
version: 2.27.5(@typescript-eslint/parser@5.59.7)(eslint@8.41.0)
specifier: npm:eslint-plugin-i@2.27.5-3
version: /eslint-plugin-i@2.27.5-3(@typescript-eslint/parser@5.59.7)(eslint@8.41.0)
eslint-plugin-jsonc:
specifier: ^2.8.0
version: 2.8.0(eslint@8.41.0)
@@ -84,8 +84,8 @@ importers:
specifier: ^7.1.0
version: 7.1.0
eslint-plugin-import:
specifier: ^2.27.5
version: 2.27.5(@typescript-eslint/parser@5.59.7)(eslint@8.41.0)
specifier: npm:eslint-plugin-i@2.27.5-3
version: /eslint-plugin-i@2.27.5-3(@typescript-eslint/parser@5.59.7)(eslint@8.41.0)
eslint-plugin-jsonc:
specifier: ^2.8.0
version: 2.8.0(eslint@8.41.0)
@@ -837,10 +837,6 @@ packages:
resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==}
dev: false
/@types/json5@0.0.29:
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
dev: false
/@types/mdast@3.0.11:
resolution: {integrity: sha512-Y/uImid8aAwrEA24/1tcRZwpxX3pIFTSilcNDKSPn+Y2iDywSEachzRuvgAYYLR3wpGXAsMbv5lvKLDZLeYPAw==}
dependencies:
@@ -1810,14 +1806,14 @@ packages:
resolution: {integrity: sha512-gozW2blMLJCeFpBwugLTGyvVjNoeo1knonXAcatC6bjPBZitotxdWf7Gimr25N4c0AAOo4eOUfaG82IJPDpqCA==}
dependencies:
debug: 3.2.7
is-core-module: 2.11.0
resolve: 1.22.1
is-core-module: 2.12.1
resolve: 1.22.2
transitivePeerDependencies:
- supports-color
dev: false
/eslint-module-utils@2.7.4(@typescript-eslint/parser@5.59.7)(eslint-import-resolver-node@0.3.7)(eslint@8.41.0):
resolution: {integrity: sha512-j4GT+rqzCoRKHwURX7pddtIPGySnX9Si/cgMI5ztrcqOPtk5dDEeZ34CQVPphnqkJytlc97Vuk05Um2mJ3gEQA==}
/eslint-module-utils@2.8.0(@typescript-eslint/parser@5.59.7)(eslint-import-resolver-node@0.3.7)(eslint@8.41.0):
resolution: {integrity: sha512-aWajIYfsqCKRDgUfjEXNN/JlrzauMuSEy5sbd7WXbtW3EH6A6MpwEh42c7qD+MqQo9QMJ6fWLAeIJynx0g6OAw==}
engines: {node: '>=4'}
peerDependencies:
'@typescript-eslint/parser': '*'
@@ -1873,17 +1869,12 @@ packages:
htmlparser2: 8.0.2
dev: false
/eslint-plugin-import@2.27.5(@typescript-eslint/parser@5.59.7)(eslint@8.41.0):
resolution: {integrity: sha512-LmEt3GVofgiGuiE+ORpnvP+kAm3h6MLZJ4Q5HCyHADofsb4VzXFsRiWj3c0OFiV+3DWFh0qg3v9gcPlfc3zRow==}
/eslint-plugin-i@2.27.5-3(@typescript-eslint/parser@5.59.7)(eslint@8.41.0):
resolution: {integrity: sha512-fxJkCgJmJ1j/4fQwoonVtXT9nwF/MZ5GTUm9bzFvJQIauJgkkaPblqiMox+2pFjXN+2F7xUeq+UzCDJGBJ+vOA==}
engines: {node: '>=4'}
peerDependencies:
'@typescript-eslint/parser': '*'
eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8
peerDependenciesMeta:
'@typescript-eslint/parser':
optional: true
dependencies:
'@typescript-eslint/parser': 5.59.7(eslint@8.41.0)(typescript@5.0.4)
array-includes: 3.1.6
array.prototype.flat: 1.3.1
array.prototype.flatmap: 1.3.1
@@ -1891,16 +1882,17 @@ packages:
doctrine: 2.1.0
eslint: 8.41.0
eslint-import-resolver-node: 0.3.7
eslint-module-utils: 2.7.4(@typescript-eslint/parser@5.59.7)(eslint-import-resolver-node@0.3.7)(eslint@8.41.0)
eslint-module-utils: 2.8.0(@typescript-eslint/parser@5.59.7)(eslint-import-resolver-node@0.3.7)(eslint@8.41.0)
get-tsconfig: 4.6.0
has: 1.0.3
is-core-module: 2.11.0
is-core-module: 2.12.1
is-glob: 4.0.3
minimatch: 3.1.2
object.values: 1.1.6
resolve: 1.22.1
resolve: 1.22.3
semver: 6.3.0
tsconfig-paths: 3.14.2
transitivePeerDependencies:
- '@typescript-eslint/parser'
- eslint-import-resolver-typescript
- eslint-import-resolver-webpack
- supports-color
@@ -2370,6 +2362,12 @@ packages:
get-intrinsic: 1.2.0
dev: false
/get-tsconfig@4.6.0:
resolution: {integrity: sha512-lgbo68hHTQnFddybKbbs/RDRJnJT5YyGy2kQzVwbq+g67X73i+5MVTval34QxGkOe9X5Ujf1UYpCaphLyltjEg==}
dependencies:
resolve-pkg-maps: 1.0.0
dev: false
/giget@1.1.2:
resolution: {integrity: sha512-HsLoS07HiQ5oqvObOI+Qb2tyZH4Gj5nYGfF9qQcZNrPw+uEFhdXtgJr01aO2pWadGHucajYDLxxbtQkm97ON2A==}
hasBin: true
@@ -2816,13 +2814,6 @@ packages:
/json-stable-stringify-without-jsonify@1.0.1:
resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==}
/json5@1.0.2:
resolution: {integrity: sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==}
hasBin: true
dependencies:
minimist: 1.2.8
dev: false
/json5@2.2.3:
resolution: {integrity: sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==}
engines: {node: '>=6'}
@@ -3008,10 +2999,6 @@ packages:
brace-expansion: 2.0.1
dev: true
/minimist@1.2.8:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
dev: false
/minipass@3.3.6:
resolution: {integrity: sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==}
engines: {node: '>=8'}
@@ -3443,13 +3430,8 @@ packages:
resolution: {integrity: sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==}
engines: {node: '>=4'}
/resolve@1.22.1:
resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==}
hasBin: true
dependencies:
is-core-module: 2.11.0
path-parse: 1.0.7
supports-preserve-symlinks-flag: 1.0.0
/resolve-pkg-maps@1.0.0:
resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==}
dev: false
/resolve@1.22.2:
@@ -3460,6 +3442,15 @@ packages:
path-parse: 1.0.7
supports-preserve-symlinks-flag: 1.0.0
/resolve@1.22.3:
resolution: {integrity: sha512-P8ur/gp/AmbEzjr729bZnLjXK5Z+4P0zhIJgBgzqRih7hL7BOukHGtSTA3ACMY467GRFz3duQsi0bDZdR7DKdw==}
hasBin: true
dependencies:
is-core-module: 2.12.1
path-parse: 1.0.7
supports-preserve-symlinks-flag: 1.0.0
dev: false
/resolve@2.0.0-next.4:
resolution: {integrity: sha512-iMDbmAWtfU+MHpxt/I5iWI7cY6YVEZUQ3MBgPQ++XD1PELuJHIl82xBmObyP2KyQmkNB2dsqF7seoQQiAn5yDQ==}
hasBin: true
@@ -3689,11 +3680,6 @@ packages:
dependencies:
ansi-regex: 5.0.1
/strip-bom@3.0.0:
resolution: {integrity: sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==}
engines: {node: '>=4'}
dev: false
/strip-indent@3.0.0:
resolution: {integrity: sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==}
engines: {node: '>=8'}
@@ -3772,15 +3758,6 @@ packages:
dependencies:
is-number: 7.0.0
/tsconfig-paths@3.14.2:
resolution: {integrity: sha512-o/9iXgCYc5L/JxCHPe3Hvh8Q/2xm5Z+p18PESBU6Ff33695QnCHBEjcytY2q19ua7Mbl/DavtBOLq+oG0RCL+g==}
dependencies:
'@types/json5': 0.0.29
json5: 1.0.2
minimist: 1.2.8
strip-bom: 3.0.0
dev: false
/tslib@1.14.1:
resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
dev: false