Skip to content

Commit

Permalink
build(eslint): add eslint configs
Browse files Browse the repository at this point in the history
  • Loading branch information
web-mech committed Aug 14, 2024
1 parent 9ad2407 commit 60ef4d9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
extends: [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier',
'plugin:vue/vue3-recommended',
'plugin:vue-pug/vue3-recommended',
'plugin:astro/recommended',
],
parserOptions: {
ecmaVersion: 'latest',
},
ignorePatterns: ['postcss.config.cjs'],
rules: {
'vue/no-setup-props-destructure': 'off',
},
overrides: [
{
files: ['src/**/*.astro'],
parser: 'astro-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
extraFileExtensions: ['.astro'],
},
},
],
}
16 changes: 16 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @ts-check

import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import eslintConfigPrettier from 'eslint-config-prettier'

export default tseslint.config({
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
eslintConfigPrettier,
],
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
},
})
22 changes: 22 additions & 0 deletions lint-staged.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ESLint } from 'eslint'

const removeIgnoredFiles = async (files) => {
const eslint = new ESLint()
const isIgnored = await Promise.all(
files.map((file) => {
return eslint.isPathIgnored(file)
}),
)
const filteredFiles = files
.filter((_, i) => !isIgnored[i])
.map((file) => `"${file}"`)
return filteredFiles.join(' ')
}

export default {
'*.{js,ts,mjs,vue}': async (files) => {
const filesToLint = await removeIgnoredFiles(files)
return [`eslint ${filesToLint}`]
},
'*': 'prettier --ignore-unknown --write',
}

0 comments on commit 60ef4d9

Please sign in to comment.