From 7e502eee7f923847d5234f26bb8c657d03f59562 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 11 Aug 2024 15:52:06 -0400 Subject: [PATCH] Update eslint config to flat config --- eslint.config.js | 28 ---------------------------- eslint.config.mjs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 28 deletions(-) delete mode 100644 eslint.config.js create mode 100644 eslint.config.mjs diff --git a/eslint.config.js b/eslint.config.js deleted file mode 100644 index 12cca90..0000000 --- a/eslint.config.js +++ /dev/null @@ -1,28 +0,0 @@ -// eslint.config.js (flat config) -import configRecommended from "eslint-config-eslint"; -import configPrettier from "eslint-config-prettier"; -import pluginPrettier from "eslint-plugin-prettier"; -import globals from "globals"; -import unusedImports from "eslint-plugin-unused-imports"; -import js from "@eslint/js"; - -export default [ - { - languageOptions: { - ecmaVersion: "latest", - sourceType: "module", - globals: { - ...globals.node, - }, - }, - rules: { - "no-console": "warn", - "no-unused-vars": "warn", - "unused-imports/no-unused-imports": 1, - }, - }, - js.configs.recommended, - pluginPrettier.configs.recommended, - configPrettier, - unusedImports.configs.recommended, -]; diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..5f06942 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,31 @@ +import path from "path"; +import { fileURLToPath } from "url"; +import { FlatCompat } from "@eslint/eslintrc"; +import mjs from "@eslint/js"; +import prettierConfig from 'eslint-config-prettier'; +import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: mjs.configs.recommended +}); + +export default [ + ...compat.extends().map( + config => ({ + ...config, + files: ["**/*.mjs", "**/*.js", "**/*.cjs"], + rules: { + ...config.rules, + // ...other your custom rules + "no-console": "warn", + "no-unused-vars": "warn", + "unused-imports/no-unused-imports": "error", + } + }) + ), + prettierConfig, // Turns off all ESLint rules that have the potential to interfere with Prettier rules. + eslintPluginPrettierRecommended +]; \ No newline at end of file