From 21142b1c24e85e9b2071f970f342c144f8570a5f Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 15 Oct 2024 17:19:12 +0800 Subject: [PATCH 1/3] docs: fix type-aware linting example I know it's not an ideal solution. I may need to add additional options to the factory function later. --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 273b6fb..d305ec5 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ It is not always easy to set up the type-checking environment for ESLint without So we don't recommend you to configure individual type-aware rules and the corresponding language options all by yourself. Instead, you can start by extending from the `recommendedTypeChecked` configuration and then turn on/off the rules you need. +As of now, all the rules you need to turn on must appear *before* calling `...vueTsEslintConfig({ extends: ['recommendedTypeChecked'] })`, and all the rules you need to turn off must appear *after* calling it. + ```js // eslint.config.mjs import pluginVue from "eslint-plugin-vue"; @@ -118,15 +120,20 @@ import vueTsEslintConfig from "@vue/eslint-config-typescript"; export default [ ...pluginVue.configs["flat/essential"], + + { + files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.vue'], + rules: { + // Turn on other rules that you need. + '@typescript-eslint/require-array-sort-compare': 'error' + } + }, ...vueTsEslintConfig({ extends: ['recommendedTypeChecked'] }), { files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.vue'], rules: { // Turn off the recommended rules that you don't need. '@typescript-eslint/no-redundant-type-constituents': 'off', - - // Turn on other rules that you need. - '@typescript-eslint/require-array-sort-compare': 'error' } ] ``` From 6b2d0455f8e7b0c237e757bf7217401f5aa7047c Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 22 Oct 2024 16:55:38 +0800 Subject: [PATCH 2/3] chore: add more meaningful error message for incorrect config names --- src/index.ts | 19 +++++++++++++++++++ test/index.spec.ts | 11 +++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/index.ts b/src/index.ts index c8d887e..e202374 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,6 +70,25 @@ export default function createConfig({ }) } + // More meaningful error message for the user, in case they didn't know the correct config name. + for (const name of configNamesToExtend) { + if (!tseslint.configs[name]) { + const nameInCamelCase = name.replace(/-([a-z])/g, (_, letter) => + letter.toUpperCase(), + ) + + // @ts-expect-error + if (tseslint.configs[nameInCamelCase]) { + throw new Error( + `The config name "${name}" is not supported in "extends". ` + + `Please use "${nameInCamelCase}" instead.`, + ) + } + + throw new Error(`Unknown config name in "extends": ${name}.`) + } + } + const mayHaveJsxInSfc = supportedScriptLangs.jsx || supportedScriptLangs.tsx const needsTypeAwareLinting = configNamesToExtend.some( name => diff --git a/test/index.spec.ts b/test/index.spec.ts index babf340..86fe549 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -191,3 +191,14 @@ test('#87: should not error if the project root has an older version of espree i const { stdout } = await runLintAgainst('with-older-espree', FROM_FIXTURES) expect(stdout).toMatch(WHITESPACE_ONLY) }) + +test('should guide user to use camelCase names in "extends"', async () => { + const eslintConfigPath = path.join(__dirname, '../examples/type-checked/eslint.config.js') + const { modify, restore } = setupFileMutations(eslintConfigPath) + modify((oldContents) => oldContents.replace('recommendedTypeChecked', 'recommended-type-checked')) + const { failed, stderr } = await runLintAgainst('type-checked') + restore() + + expect(failed).toBe(true) + expect(stderr).contain('Please use "recommendedTypeChecked"') +}) From aaca88c20f2013554e0747f0ba5a133e2d62b564 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 22 Oct 2024 19:26:47 +0800 Subject: [PATCH 3/3] 14.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f1b75d0..82bc619 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vue/eslint-config-typescript", - "version": "14.1.1", + "version": "14.1.2", "description": "ESLint config for TypeScript + Vue.js projects", "main": "./dist/index.mjs", "type": "module", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy