diff --git a/Makefile b/Makefile index 55aa560..1a79d65 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..9d315fe --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,96 @@ +// @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 react from 'eslint-plugin-react'; +import globals from 'globals'; +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', + }, + + languageOptions: { + globals: { ...globals.browser }, + }, + + 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'], + + rules: { + '@typescript-eslint/no-unused-vars': [ + 'error', + { varsIgnorePattern: '[iI]gnored', argsIgnorePattern: '^_' }, + ], + '@typescript-eslint/explicit-module-boundary-types': 'off', + + 'no-void': ['error', { allowAsStatement: true }], + '@typescript-eslint/no-floating-promises': [ + 'error', + { ignoreVoid: true }, + ], + + 'no-use-before-define': 'off', + '@typescript-eslint/no-use-before-define': [ + 'error', + { functions: false, classes: false }, + ], + + 'no-useless-constructor': 'off', + '@typescript-eslint/no-useless-constructor': 'error', + }, + }, + { + files: ['**/*.spec.ts', '**/*.spec.tsx'], + + rules: { + '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/unbound-method': 'off', + }, + }, +); diff --git a/package.json b/package.json index e1f8d11..4c82c30 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,15 @@ "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-react": "^7.34.2", "prettier": "^3.3.1", + "typescript-eslint": "^7.12.0", "webpack-cli": "^5.1.4" }, "peerDependencies": {