Skip to content

Commit

Permalink
feat(eslint-config)!: upgrade to eslint v9, enable unicorn, ...
Browse files Browse the repository at this point in the history
* use compat plugin only when browserslist is present in package.json
* ignore nuxt pages filename casing with params
* enabled 2 shopify typescript rules
  • Loading branch information
DrJume committed Aug 5, 2024
1 parent 1640c56 commit e324654
Show file tree
Hide file tree
Showing 7 changed files with 1,087 additions and 1,174 deletions.
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,18 @@
"author": "Louis Haftmann",
"license": "MIT",
"scripts": {
"lint": "pnpm -r run stub && eslint .",
"lint": "eslint .",
"test": "pnpm -r run test",
"build": "pnpm -r run build",
"prepare": "pnpm -r run stub",
"release": "bumpp -r && pnpm run publish",
"publish": "pnpm -r publish --filter=!@louishaftmann/config-monorepo --no-git-checks --access public"
},
"devDependencies": {
"@louishaftmann/eslint-config": "workspace:*",
"@louishaftmann/prettier-config": "workspace:*",
"bumpp": "^9.4.1",
"eslint": "^8.57.0",
"rimraf": "^5.0.7",
"typescript": "^5.4.5"
"bumpp": "^9.4.2",
"eslint": "^9.8.0",
"typescript": "^5.5.4"
},
"changelogithub": {
"extends": "gh:falcondev-it/configs/changelogithub"
Expand Down
4 changes: 3 additions & 1 deletion packages/eslint-config/github.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { fixupPluginRules } from '@eslint/compat'
import { FlatCompat } from '@eslint/eslintrc'

const compat = new FlatCompat()
Expand All @@ -21,13 +22,14 @@ const github = compat.extends('plugin:github/recommended').map((configItem, inde
delete configItem.plugins['eslint-comments']
delete configItem.plugins.import
delete configItem.plugins.prettier
configItem.plugins.github = fixupPluginRules(configItem.plugins.github)
}

configItem.name = `github/${index}`
return configItem
})

/** @type {import('eslint').Linter.FlatConfig[]} */
/** @type {import('eslint').Linter.Config[]} */
export default [
...github,
{
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-config/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import type { TypedFlatConfigItem } from '@antfu/eslint-config'
import type antfu from '@antfu/eslint-config'

declare function eslintConfig(config: {
nuxt: boolean
unicorn?: boolean
tsconfigPath?: string[]
/** @deprecated */ configs?: TypedFlatConfigItem[]
tsconfigPath?: string
}): ReturnType<typeof antfu>

export { eslintConfig, eslintConfig as default }
110 changes: 57 additions & 53 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import antfu from '@antfu/eslint-config'
import { FlatCompat } from '@eslint/eslintrc'
import shopifyEslintPlugin from '@shopify/eslint-plugin'
import eslintConfigPrettier from 'eslint-config-prettier'
import eslintPluginCompat from 'eslint-plugin-compat'
import eslintPluginUnicorn from 'eslint-plugin-unicorn'
import { loadPackageJSON } from 'local-pkg'

import github from './github.js'
import nuxtRules from './nuxt.js'

delete eslintConfigPrettier.rules['vue/html-self-closing']

const compat = new FlatCompat()

/** @type {import('./index.d.ts').eslintConfig} */
export function eslintConfig({ nuxt = false, tsconfigPath, unicorn = false, configs }) {
export function eslintConfig({ nuxt = false, tsconfigPath }) {
return antfu({
stylistic: false,

Expand All @@ -23,8 +22,8 @@ export function eslintConfig({ nuxt = false, tsconfigPath, unicorn = false, conf
vue: {
sfcBlocks: {
blocks: {
styles: false
}
styles: false,
},
},
overrides: {
// force <script lang="ts">
Expand Down Expand Up @@ -55,53 +54,50 @@ export function eslintConfig({ nuxt = false, tsconfigPath, unicorn = false, conf
.prepend(github)
.append(nuxt ? nuxtRules : [])
.override('antfu/unicorn/rules', (config) => {
if (unicorn) delete config.plugins
delete config.plugins
return config
})
.insertBefore('antfu/unicorn/rules', unicorn && eslintPluginUnicorn.configs['flat/recommended'])
.append(
unicorn && [
{
name: 'falcondev/unicorn/rules',
rules: {
'unicorn/filename-case': [
'error',
{
case: 'kebabCase',
ignore: [/^README\./],
},
],
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-null': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/prefer-ternary': 'off',
'unicorn/catch-error-name': ['error', { name: 'err' }],
'unicorn/no-abusive-eslint-disable': 'off',
},
},
{
name: 'falcondev/unicorn/overrides',
files: ['**/composables/**/*'],
rules: {
'unicorn/filename-case': ['error', { case: 'camelCase' }],
},
},
{
name: 'falcondev/unicorn/overrides',
files: ['**/components/**/*'],
rules: {
'unicorn/filename-case': ['error', { case: 'pascalCase' }],
},
},
{
name: 'falcondev/unicorn/ignore',
files: ['.github/**/*', '**/prisma/migrations/**/*', '**/db/migrations/meta/**/*'],
rules: {
'unicorn/filename-case': 'off',
},
.insertBefore('antfu/unicorn/rules', eslintPluginUnicorn.configs['flat/recommended'])
.append([
{
name: 'falcondev/unicorn/rules',
rules: {
'unicorn/filename-case': [
'error',
{
case: 'kebabCase',
ignore: [/^README\./],
},
],
'unicorn/prevent-abbreviations': 'off',
'unicorn/no-null': 'off',
'unicorn/no-array-callback-reference': 'off',
'unicorn/prefer-ternary': 'off',
'unicorn/catch-error-name': ['error', { name: 'err' }],
'unicorn/no-abusive-eslint-disable': 'off',
},
],
)
},
{
name: 'falcondev/unicorn/overrides',
files: ['**/composables/**/*'],
rules: { 'unicorn/filename-case': ['error', { case: 'camelCase' }] },
},
{
name: 'falcondev/unicorn/overrides',
files: ['**/components/**/*'],
rules: { 'unicorn/filename-case': ['error', { case: 'pascalCase' }] },
},
{
name: 'falcondev/unicorn/overrides',
files: [String.raw`**/pages/**/*\[*\]*.vue`],
rules: { 'unicorn/filename-case': 'off' },
},
{
name: 'falcondev/unicorn/ignore',
files: ['.github/**/*', '**/prisma/migrations/**/*', '**/db/migrations/meta/**/*'],
rules: { 'unicorn/filename-case': 'off' },
},
])
.append({
name: 'falcondev/rules',
rules: {
Expand Down Expand Up @@ -158,9 +154,11 @@ export function eslintConfig({ nuxt = false, tsconfigPath, unicorn = false, conf
})
.append({
name: 'falcondev/shopify',
...compat.plugins('@shopify/eslint-plugin')[0],
plugins: { '@shopify': shopifyEslintPlugin },
rules: {
'@shopify/prefer-early-return': 'error',
'@shopify/typescript-prefer-pascal-case-enums': 'error',
'@shopify/typescript-prefer-singular-enums': 'error',
},
})
.append(
Expand All @@ -175,8 +173,14 @@ export function eslintConfig({ nuxt = false, tsconfigPath, unicorn = false, conf
rules: { 'yaml/no-empty-mapping-value': 'off' },
},
)
.append(eslintPluginCompat.configs['flat/recommended'])
.append(configs ?? [])
.append(
(async () => {
const packageJSON = await loadPackageJSON()
if (!('browserslist' in packageJSON)) return

return eslintPluginCompat.configs['flat/recommended']
})(),
)
.append({
name: 'prettier/disables',
...eslintConfigPrettier,
Expand Down
18 changes: 10 additions & 8 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@
"maintained node versions"
],
"dependencies": {
"@antfu/eslint-config": "^2.21.1",
"@antfu/eslint-config": "^2.24.1",
"@eslint/compat": "^1.1.1",
"@eslint/eslintrc": "^3.1.0",
"@nuxt/eslint-config": "^0.3.13",
"@shopify/eslint-plugin": "^45.0.0",
"@nuxt/eslint-config": "^0.5.0",
"@shopify/eslint-plugin": "^46.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-compat": "^5.0.0",
"eslint-plugin-compat": "^6.0.0",
"eslint-plugin-github": "^5.0.1",
"eslint-plugin-unicorn": "^54.0.0"
"eslint-plugin-unicorn": "^55.0.0",
"local-pkg": "^0.5.0"
},
"devDependencies": {
"@types/eslint": "^8.56.10",
"@types/eslint": "^9.6.0",
"@types/eslint-config-prettier": "^6.11.3",
"@types/eslint__eslintrc": "^2.1.1",
"eslint": "^8.57.0"
"@types/eslint__eslintrc": "^2.1.2",
"eslint": "^9.8.0"
}
}
2 changes: 1 addition & 1 deletion packages/prettier-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"prettier-plugin-tailwindcss": "^0.6.5"
},
"devDependencies": {
"prettier": "^3.3.2"
"prettier": "^3.3.3"
}
}
Loading

0 comments on commit e324654

Please sign in to comment.