Skip to content

Commit

Permalink
feat(eslint-config): support ESLint v9 (#731)
Browse files Browse the repository at this point in the history
* feat(eslint-config): support ESLint v9

* add changeset
  • Loading branch information
yusukebe authored Sep 8, 2024
1 parent f7a950a commit 80cd26a
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 80 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-plums-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/eslint-config': major
---

feat: support ESLint v9
8 changes: 4 additions & 4 deletions packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ yarn add @hono/eslint-config

## Setting

`.eslintrc.cjs`
`eslint.config.mjs`

```js
module.exports = {
extends: ['@hono/eslint-config'],
}
import baseConfig from '@hono/eslint-config'

export default [...baseConfig]
```

## Authors
Expand Down
164 changes: 99 additions & 65 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,109 @@
const { defineConfig } = require('eslint-define-config')
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { FlatCompat } from '@eslint/eslintrc'
import js from '@eslint/js'
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import importX from 'eslint-plugin-import-x'

module.exports = defineConfig({
root: true,
extends: [
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat.extends(
'eslint:recommended',
'plugin:n/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 2021,
},
plugins: ['@typescript-eslint', 'import-x'],
globals: {
fetch: false,
Response: false,
Request: false,
addEventListener: false,
},
rules: {
curly: ['error', 'all'],
quotes: ['error', 'single'],
semi: ['error', 'never'],
'no-debugger': ['error'],
'no-empty': ['warn', { allowEmptyCatch: true }],
'no-process-exit': 'off',
'no-useless-escape': 'off',
'prefer-const': [
'warn',
{
destructuring: 'all',
},
],
'sort-imports': [
'error',
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
'prettier'
),
{
plugins: {
'@typescript-eslint': typescriptEslint,
'import-x': importX,
},

languageOptions: {
globals: {
fetch: false,
Response: false,
Request: false,
addEventListener: false,
},
],

'import-x/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'import-x/no-duplicates': 'error',
parser: tsParser,
ecmaVersion: 2021,
sourceType: 'module',
},

'n/no-missing-import': 'off',
'n/no-missing-require': 'off',
'n/no-deprecated-api': 'off',
'n/no-unpublished-import': 'off',
'n/no-unpublished-require': 'off',
'n/no-unsupported-features/es-syntax': 'off',
rules: {
curly: ['error', 'all'],
quotes: ['error', 'single'],
semi: ['error', 'never'],
'no-debugger': ['error'],

'@typescript-eslint/ban-types': [
'error',
{
types: {
Function: false,
'{}': false,
'no-empty': [
'warn',
{
allowEmptyCatch: true,
},
},
],
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
],

'no-process-exit': 'off',
'no-useless-escape': 'off',

'prefer-const': [
'warn',
{
destructuring: 'all',
},
],

'import-x/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'import-x/order': [
'error',
{
groups: ['external', 'builtin', 'internal', 'parent', 'sibling', 'index'],
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'import-x/no-duplicates': 'error',

'n/no-missing-import': 'off',
'n/no-missing-require': 'off',
'n/no-deprecated-api': 'off',
'n/no-unpublished-import': 'off',
'n/no-unpublished-require': 'off',
'n/no-unsupported-features/es-syntax': 'off',
'n/no-unsupported-features/node-builtins': 'off',

'@typescript-eslint/consistent-type-imports': [
'error',
{
prefer: 'type-imports',
},
],
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/no-empty-function': [
'error',
{
allow: ['arrowFunctions'],
},
],
'@typescript-eslint/no-unused-expressions': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/no-var-requires': 'off',
},
},
ignorePatterns: ['dist'],
})
]
16 changes: 11 additions & 5 deletions packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"name": "@hono/eslint-config",
"version": "0.0.6",
"description": "ESLint Config for Hono projects",
"main": "index.js",
"type": "module",
"module": "./index.js",
"exports": {
".": "./index.js"
},
"license": "MIT",
"publishConfig": {
"registry": "https://registry.npmjs.org",
Expand All @@ -14,12 +18,14 @@
},
"homepage": "https://github.com/honojs/middleware",
"peerDependencies": {
"eslint": "^8.57.0",
"eslint": "^9.0.0",
"typescript": "^5.0.0"
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.10.0",
"@typescript-eslint/eslint-plugin": "^8.4.0",
"@typescript-eslint/parser": "^8.4.0",
"eslint-config-prettier": "^9.1.0",
"eslint-define-config": "^2.1.0",
"eslint-import-resolver-typescript": "^3.6.3",
Expand All @@ -28,7 +34,7 @@
},
"devDependencies": {
"@types/eslint": "^8",
"eslint": "^8.57.0",
"eslint": "^9.10.0",
"typescript": "^5.3.3"
}
}
Loading

0 comments on commit 80cd26a

Please sign in to comment.