From 1d657db63bf500c0d8979cd5818d3dc1a9c23498 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Sun, 6 Oct 2024 01:41:46 +0800 Subject: [PATCH] feat!: initial flat config support BREAKING CHANGES: - Dropped legacy `.eslintrc*` support - Dropped support for Vue 2 - Airbnb and Standard style guides are not yet supported It satisfies the use case for basic JavaScript / TypeScript projects with Vue 3. The formatting of `additionalConfigs` still needs to be improved to be able to be used in `create-vue`. The CLI functionality is too basic and needs to be improved. --- .editorconfig | 6 + .prettierrc.json | 6 + bin/create-eslint-config.js | 211 +- eslint.config.js | 13 + index.js | 244 +- package.json | 25 +- pnpm-lock.yaml | 4058 ++++------------- renderEjsFile.js | 21 + .../{editorconfigs.js => _editorconfig.ejs} | 28 +- templates/_prettierrc.json.ejs | 38 + templates/eslint.config.mjs.ejs | 23 + templates/prettierrcs.js | 47 - versionMap.cjs | 1 - 13 files changed, 1196 insertions(+), 3525 deletions(-) create mode 100644 .editorconfig create mode 100644 .prettierrc.json create mode 100644 eslint.config.js create mode 100644 renderEjsFile.js rename templates/{editorconfigs.js => _editorconfig.ejs} (51%) create mode 100644 templates/_prettierrc.json.ejs create mode 100644 templates/eslint.config.mjs.ejs delete mode 100644 templates/prettierrcs.js delete mode 100644 versionMap.cjs diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ecea360 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +[*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}] +charset = utf-8 +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..ad9bdac --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://json.schemastore.org/prettierrc", + "semi": false, + "singleQuote": true, + "arrowParens": "avoid" +} diff --git a/bin/create-eslint-config.js b/bin/create-eslint-config.js index 2c858d1..3dc6bfe 100644 --- a/bin/create-eslint-config.js +++ b/bin/create-eslint-config.js @@ -5,7 +5,7 @@ import path from 'node:path' import process from 'node:process' import { bold, blue, yellow, red, green, dim } from 'kolorist' -import createConfig, { deepMerge, CREATE_ALIAS_SETTING_PLACEHOLDER } from '../index.js' +import createConfig, { deepMerge } from '../index.js' const require = createRequire(import.meta.url) const Enquirer = require('enquirer') @@ -43,6 +43,7 @@ const pkg = JSON.parse(rawPkgJson) // 1. check for existing config files // `.eslintrc.*`, `eslintConfig` in `package.json` +// FIXME: `eslint.config.*` // ask if wanna overwrite? // https://eslint.org/docs/latest/user-guide/configuring/configuration-files#configuration-file-formats @@ -89,55 +90,20 @@ if (pkg.eslintConfig) { } // 2. Check Vue -// Not detected? Choose from Vue 2 or 3 -// TODO: better support for 2.7 and vue-demi let vueVersion +// Not detected? Abort +// Vue 2? Abort because this tool only supports Vue 3 try { vueVersion = requireInCwd('vue/package.json').version console.info(dim(`Detected Vue.js version: ${vueVersion}`)) } catch (e) { - const anwsers = await prompt({ - type: 'select', - name: 'vueVersion', - message: 'Which Vue.js version do you use in the project?', - choices: [ - '3.x', - '2.x' - ] - }) - vueVersion = anwsers.vueVersion + // FIXME: warning that this only support Vue 3 } -// 3. Choose a style guide -// - Error Prevention (ESLint Recommended) -// - Standard -// - Airbnb -const { styleGuide } = await prompt({ - type: 'select', - name: 'styleGuide', - message: 'Which style guide do you want to follow?', - choices: [ - { - name: 'default', - message: 'ESLint Recommended (Error-Prevention-Only)' - }, - { - name: 'airbnb', - message: `Airbnb ${dim('(https://airbnb.io/javascript/)')}` - }, - { - name: 'standard', - message: `Standard ${dim('(https://standardjs.com/)')}` - } - ] -}) - // 4. Check TypeScript // 4.1 Allow JS? -// 4.2 Allow JS in Vue? -// 4.3 Allow JSX (TSX, if answered no in 4.1) in Vue? +// 4.2 Allow JS in Vue? Allow JSX (TSX, if answered no in 4.1) in Vue? let hasTypeScript = false -const additionalConfig = {} try { const tsVersion = requireInCwd('typescript/package.json').version console.info(dim(`Detected TypeScript version: ${tsVersion}`)) @@ -154,108 +120,54 @@ try { hasTypeScript = anwsers.hasTypeScript } -// TODO: we don't have more fine-grained sub-rulsets in `@vue/eslint-config-typescript` yet -if (hasTypeScript && styleGuide !== 'default') { - const { allowJsInVue } = await prompt({ - type: 'toggle', - disabled: 'No', - enabled: 'Yes', - name: 'allowJsInVue', - message: `Do you use plain ${yellow('