├── .editorconfig ├── .github ├── MAINTENANCE.md ├── renovate.json └── workflows │ └── publish.yml ├── .gitignore ├── .prettierrc.json ├── LICENSE ├── README.md ├── bin └── create-eslint-config.js ├── eslint.config.js ├── index.d.ts ├── index.js ├── package.json ├── pnpm-lock.yaml ├── renderEjsFile.js └── templates ├── _editorconfig.ejs ├── _gitattributes ├── _prettierrc.json.ejs ├── eslint.config.js.ejs └── eslint.config.ts.ejs /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.{js,jsx,mjs,cjs,ts,tsx,mts,cts,vue}] 2 | charset = utf-8 3 | indent_size = 2 4 | indent_style = space 5 | insert_final_newline = true 6 | trim_trailing_whitespace = true 7 | -------------------------------------------------------------------------------- /.github/MAINTENANCE.md: -------------------------------------------------------------------------------- 1 | This document explains how to perform the project's maintenance tasks. 2 | 3 | ### Creating a new release 4 | 5 | Anyone with write access to the repository can request a new release. To do so, follow these steps: 6 | 7 | 1. Run `pnpm version ` locally to bump the version number and create a new commit / tag. 8 | 2. Push the commit and tag to the repository by running `git push --follow-tags`. 9 | 3. The release will be automatically published to npm by GitHub Actions once approved by an administrator. 10 | 4. Go to and create a new release with the tag that was just created. Describe the notable changes in the release notes. 11 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": [ 4 | "github>haoqunjiang/renovate-presets:npm.json5" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 7 | 8 | jobs: 9 | release: 10 | # Use Publish environment for deployment protection 11 | environment: Publish 12 | runs-on: ubuntu-latest 13 | permissions: 14 | contents: read 15 | id-token: write 16 | steps: 17 | - uses: actions/checkout@v4 18 | - uses: actions/setup-node@v4 19 | with: 20 | node-version: 'lts/*' 21 | registry-url: 'https://registry.npmjs.org' 22 | - run: npm publish 23 | env: 24 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/prettierrc", 3 | "semi": false, 4 | "singleQuote": true, 5 | "arrowParens": "avoid" 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 vuejs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `@vue/create-eslint-config` 2 | 3 | Utility to setup ESLint in Vue.js projects. 4 | 5 | ## Usage 6 | 7 | Run the following command in your project root: 8 | 9 | With npm: 10 | 11 | ```sh 12 | npm create @vue/eslint-config@latest 13 | ``` 14 | 15 | With pnpm: 16 | 17 | ```sh 18 | pnpm create @vue/eslint-config 19 | ``` 20 | 21 | With Yarn: 22 | 23 | ```sh 24 | yarn create @vue/eslint-config 25 | ``` 26 | -------------------------------------------------------------------------------- /bin/create-eslint-config.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs' 3 | import { createRequire } from 'node:module' 4 | import path from 'node:path' 5 | import process from 'node:process' 6 | import { bold, blue, yellow, red, green, dim } from 'kolorist' 7 | 8 | import createConfig, { deepMerge } from '../index.js' 9 | 10 | const require = createRequire(import.meta.url) 11 | const Enquirer = require('enquirer') 12 | const enquirer = new Enquirer() 13 | 14 | function abort() { 15 | console.error(red('✖') + ' Operation cancelled') 16 | process.exit(1) 17 | } 18 | 19 | function prompt(questions) { 20 | return enquirer.prompt(questions).catch(abort) 21 | } 22 | 23 | const cwd = process.cwd() 24 | const requireInCwd = createRequire(path.resolve(cwd, 'index.cjs')) 25 | 26 | // Only works in directories that has a `package.json` 27 | const pkgJsonPath = path.resolve(cwd, 'package.json') 28 | if (!existsSync(pkgJsonPath)) { 29 | console.error( 30 | `${bold(yellow('package.json'))} not found in the current directory.`, 31 | ) 32 | abort() 33 | } 34 | 35 | const rawPkgJson = readFileSync(pkgJsonPath, 'utf-8') 36 | function inferIndent(rawJson) { 37 | const lines = rawJson.split('\n') 38 | const firstLineWithIndent = lines.find( 39 | l => l.startsWith(' ') || l.startsWith('\t'), 40 | ) 41 | 42 | if (!firstLineWithIndent) { 43 | return '' 44 | } 45 | return /^\s+/.exec(firstLineWithIndent)[0] 46 | } 47 | const indent = inferIndent(rawPkgJson) 48 | const pkg = JSON.parse(rawPkgJson) 49 | 50 | // 1. check for existing config files 51 | // `.eslintrc.*`, `eslintConfig` in `package.json` 52 | // FIXME: `eslint.config.*` 53 | // ask if wanna overwrite? 54 | 55 | // https://eslint.org/docs/latest/user-guide/configuring/configuration-files#configuration-file-formats 56 | // The experimental `eslint.config.js` isn't supported yet 57 | const eslintConfigFormats = ['js', 'cjs', 'yaml', 'yml', 'json'] 58 | for (const fmt of eslintConfigFormats) { 59 | const configFileName = `.eslintrc.${fmt}` 60 | const fullConfigPath = path.resolve(cwd, configFileName) 61 | if (existsSync(fullConfigPath)) { 62 | const { shouldRemove } = await prompt({ 63 | type: 'toggle', 64 | disabled: 'No', 65 | enabled: 'Yes', 66 | name: 'shouldRemove', 67 | message: 68 | `Found existing ESLint config file: ${bold(blue(configFileName))}.\n` + 69 | 'Do you want to remove the config file and continue?', 70 | initial: false, 71 | }) 72 | 73 | if (shouldRemove) { 74 | unlinkSync(fullConfigPath) 75 | } else { 76 | abort() 77 | } 78 | } 79 | } 80 | 81 | if (pkg.eslintConfig) { 82 | const { shouldRemoveConfigField } = await prompt({ 83 | type: 'toggle', 84 | disabled: 'No', 85 | enabled: 'Yes', 86 | name: 'shouldRemoveConfigField', 87 | message: 88 | `Found existing ${bold(blue('eslintConfig'))} field in ${bold(yellow('package.json'))}.\n` + 89 | 'Do you want to remove the config field and continue?', 90 | initial: false, 91 | }) 92 | 93 | if (shouldRemoveConfigField) { 94 | delete pkg.eslintConfig 95 | } 96 | } 97 | 98 | // 2. Check Vue 99 | let vueVersion 100 | // Not detected? Abort 101 | // Vue 2? Abort because this tool only supports Vue 3 102 | try { 103 | vueVersion = requireInCwd('vue/package.json').version 104 | console.info(dim(`Detected Vue.js version: ${vueVersion}`)) 105 | } catch {} 106 | 107 | if (!vueVersion || !/^3/.test(vueVersion)) { 108 | const { continueAnyway } = await prompt({ 109 | type: 'toggle', 110 | disabled: 'No', 111 | enabled: 'Yes', 112 | name: 'continueAnyway', 113 | message: 'Vue 3.x is required but not detected. Continue anyway?', 114 | initial: false, 115 | }) 116 | if (!continueAnyway) { 117 | abort() 118 | } 119 | } 120 | 121 | // 4. Check TypeScript 122 | // 4.1 Allow JS? 123 | // 4.2 Allow JS in Vue? Allow JSX (TSX, if answered no in 4.1) in Vue? 124 | let detectedTypeScript = false 125 | try { 126 | const tsVersion = requireInCwd('typescript/package.json').version 127 | console.info(dim(`Detected TypeScript version: ${tsVersion}`)) 128 | detectedTypeScript = true 129 | } catch {} 130 | 131 | const { hasTypeScript } = await prompt({ 132 | type: 'toggle', 133 | disabled: 'No', 134 | enabled: 'Yes', 135 | name: 'hasTypeScript', 136 | message: 'Does your project use TypeScript?', 137 | initial: detectedTypeScript, 138 | }) 139 | 140 | const supportedScriptLangs = {} 141 | // FIXME: Use a multi-select prompt 142 | // if (hasTypeScript) { 143 | // const { allowJsInVue } = await prompt({ 144 | // type: 'toggle', 145 | // disabled: 'No', 146 | // enabled: 'Yes', 147 | // name: 'allowJsInVue', 148 | // message: `Do you use plain ${yellow('