Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add @vue/eslint-config-airbnb select option #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ async function init() {
argv.vitest ??
argv.cypress ??
argv.playwright ??
argv.eslint
argv.eslint ??
argv.eslintAirbnb
) === 'boolean'

let targetDir = argv._[0]
Expand All @@ -114,6 +115,7 @@ async function init() {
needsVitest?: boolean
needsE2eTesting?: false | 'cypress' | 'playwright'
needsEslint?: boolean
needsEslintAirbnb?: boolean
needsPrettier?: boolean
} = {}

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion template/eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"devDependencies": {
"eslint-plugin-cypress": "^2.12.1"
"eslint-plugin-cypress": "^2.12.1",
"@vue/eslint-config-airbnb": "^7.0.0"
}
}
10 changes: 9 additions & 1 deletion utils/renderEslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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',
Expand Down