import storybook from "eslint-plugin-storybook";
import prettier from "eslint-config-prettier";
import path from "node:path";
import js from "@eslint/js";
import svelte from "eslint-plugin-svelte";
import { defineConfig, includeIgnoreFile } from "eslint/config";
import globals from "globals";
import ts from "typescript-eslint";

const gitignorePath = path.resolve(import.meta.dirname, ".gitignore");

export default defineConfig(
	{ ignores: ["src/lib/api/lexicons/"] },
	includeIgnoreFile(gitignorePath),
	js.configs.recommended,
	ts.configs.recommended,
	svelte.configs.recommended,
	storybook.configs["flat/recommended"],
	prettier,
	svelte.configs.prettier,
	{
		languageOptions: { globals: { ...globals.browser, ...globals.node } },
		rules: {
			// typescript owns undefined-name checks.
			"no-undef": "off"
		}
	},
	{
		files: ["**/*.svelte", "**/*.svelte.ts", "**/*.svelte.js"],
		languageOptions: {
			parserOptions: {
				projectService: { allowDefaultProject: [".storybook/StoryAuthProvider.svelte"] },
				extraFileExtensions: [".svelte"],
				parser: ts.parser
			}
		}
	},
	{
		rules: {}
	}
);
