diff --git a/Makefile b/Makefile index 7f700a5..2a250a7 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ lib/maxmind : .PHONY : fmt fmt : bun x prettier --write . + bun x eslint --fix . @ git diff-index --quiet HEAD .PHONY : test diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..8ef5a3f --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,76 @@ +// @ts-check + +import fs from 'node:fs'; + +import eslint from '@eslint/js'; +import prettierConfig from 'eslint-config-prettier'; +import importPlugin from 'eslint-plugin-import'; +import jest from 'eslint-plugin-jest'; +import react from 'eslint-plugin-react'; +import tseslint from 'typescript-eslint'; + +export default tseslint.config( + { + ignores: ['eslint.config.js'].concat( + fs.readFileSync('.gitignore', 'utf8').split('\n').filter(Boolean), + ), + }, + + eslint.configs.recommended, + ...tseslint.configs.strictTypeChecked, + { + languageOptions: { + parserOptions: { + project: true, + ecmaFeatures: { jsx: true }, + }, + }, + }, + prettierConfig, + + { + linterOptions: { + reportUnusedDisableDirectives: 'error', + }, + plugins: { + import: importPlugin, + react, + }, + }, + + { + settings: { + 'import/core-modules': ['bun:test'], + }, + + rules: { + 'import/order': [ + 'error', + { alphabetize: { order: 'asc' }, 'newlines-between': 'always' }, + ], + 'no-unused-vars': [ + 'error', + { varsIgnorePattern: '[iI]gnored', argsIgnorePattern: '^_' }, + ], + curly: 'error', + 'default-case': 'error', + }, + }, + { + files: ['**/*.ts', '**/*.tsx', '**/*.mts'], + rules: { + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': [ + 'error', + { varsIgnorePattern: '[iI]gnored', argsIgnorePattern: '^_' }, + ], + 'no-void': ['error', { allowAsStatement: true }], + }, + }, + { + files: ['**/*.spec.ts', '**/*.spec.tsx'], + plugins: { jest }, + settings: { jest: { version: 29 } }, + ...jest.configs['flat/recommended'], + }, +); diff --git a/package.json b/package.json index e1f8d11..70b1439 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,16 @@ "mmdb-lib": "^2.1.1" }, "devDependencies": { + "@eslint/js": "^9.4.0", "@types/bun": "latest", + "@types/eslint__js": "^8.42.3", + "eslint": "^9.4.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.29.1", + "eslint-plugin-jest": "^28.6.0", + "eslint-plugin-react": "^7.34.2", "prettier": "^3.3.1", + "typescript-eslint": "^7.12.0", "webpack-cli": "^5.1.4" }, "peerDependencies": {