diff --git a/index.ts b/index.ts index f56e8705..af589734 100755 --- a/index.ts +++ b/index.ts @@ -95,7 +95,8 @@ async function init() { argv.vitest ?? argv.cypress ?? argv.playwright ?? - argv.eslint + argv.eslint ?? + argv.eslintAirbnb ) === 'boolean' let targetDir = argv._[0] @@ -114,6 +115,7 @@ async function init() { needsVitest?: boolean needsE2eTesting?: false | 'cypress' | 'playwright' needsEslint?: boolean + needsEslintAirbnb?: boolean needsPrettier?: boolean } = {} @@ -233,6 +235,19 @@ async function init() { active: 'Yes', inactive: 'No' }, + { + name: 'needsEslintAirbnb', + type: (prev, values) => { + if (isFeatureFlagsUsed || !values.needsEslint) { + return null + } + return 'toggle' + }, + message: 'Add ESLint airbnb rules?', + initial: false, + active: 'Yes', + inactive: 'No' + }, { name: 'needsPrettier', type: (prev, values) => { @@ -270,6 +285,7 @@ async function init() { needsPinia = argv.pinia, needsVitest = argv.vitest || argv.tests, needsEslint = argv.eslint || argv['eslint-with-prettier'], + needsEslintAirbnb = argv.eslintAirbnb, needsPrettier = argv['eslint-with-prettier'] } = result @@ -347,7 +363,13 @@ async function init() { // Render ESLint config if (needsEslint) { - renderEslint(root, { needsTypeScript, needsCypress, needsCypressCT, needsPrettier }) + renderEslint(root, { + needsTypeScript, + needsCypress, + needsCypressCT, + needsPrettier, + needsEslintAirbnb + }) } // Render code template. diff --git a/template/eslint/package.json b/template/eslint/package.json index d3f28f02..4e4cd4e9 100644 --- a/template/eslint/package.json +++ b/template/eslint/package.json @@ -1,5 +1,6 @@ { "devDependencies": { - "eslint-plugin-cypress": "^2.12.1" + "eslint-plugin-cypress": "^2.12.1", + "@vue/eslint-config-airbnb": "^7.0.0" } } diff --git a/utils/renderEslint.ts b/utils/renderEslint.ts index bef8278c..eaf6370e 100644 --- a/utils/renderEslint.ts +++ b/utils/renderEslint.ts @@ -11,7 +11,7 @@ import deepMerge from './deepMerge' export default function renderEslint( rootDir, - { needsTypeScript, needsCypress, needsCypressCT, needsPrettier } + { needsTypeScript, needsCypress, needsCypressCT, needsPrettier, needsEslintAirbnb } ) { const additionalConfig: Linter.Config = {} const additionalDependencies = {} @@ -31,6 +31,14 @@ export default function renderEslint( additionalDependencies['eslint-plugin-cypress'] = eslintDeps['eslint-plugin-cypress'] } + if (needsEslintAirbnb) { + additionalConfig.extends = ['@vue/eslint-config-airbnb'] + additionalConfig.rules = { + 'linebreak-style': 0, + semi: 0 + } + additionalDependencies['@vue/eslint-config-airbnb'] = eslintDeps['@vue/eslint-config-airbnb'] + } const { pkg, files } = createESLintConfig({ vueVersion: '3.x',