Skip to content

Instantly share code, notes, and snippets.

@pejalo
Created July 9, 2023 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pejalo/635395339353a78e85514fdacd572fab to your computer and use it in GitHub Desktop.
Save pejalo/635395339353a78e85514fdacd572fab to your computer and use it in GitHub Desktop.
eslint for svelte in flat configuration format
// this file uses eslint's new "flat configuration" format:
// https://eslint.org/docs/latest/use/configure/configuration-files-new
// as of now, there are not many resources online on how to use it.
import js from "@eslint/js"
import globals from 'globals'
import sveltePlugin from 'eslint-plugin-svelte'
import svelteParser from 'svelte-eslint-parser'
import { js as myJsRules, svelte as mySvelteRules } from "./my-eslint-rules.js"
export default [
// according to eslint docs, this "enables the rules that ESLint
// recommends everyone use to avoid potential errors"
js.configs.recommended,
{
files: ["**/*.js", "**/*.svelte"],
// vite+svelte setup creates its own config files. we can let them be.
ignores: ["*config*"],
languageOptions: {
// allow globals like 'document' to be recognized
globals: globals.browser,
},
// apply my basic js rules
rules: {
...myJsRules,
},
},
// in the future the following might be useful, once it gets updated
// to support eslint's new "flat configuration" format.
// svelte.configs.recommended,
// apply all svelte rules
{
files: ["**/*.svelte"],
plugins: {
// needed for 'svelte/*' rules to be recognized as plugin rules
svelte: sveltePlugin,
},
languageOptions: {
// needed for .svelte file format to be understood
parser: svelteParser,
},
rules: {
// the following two are not picked up by sveltePlugin, which isn't in flat config format
...sveltePlugin.configs.base.rules,
...sveltePlugin.configs.recommended.rules,
// apply my svelte rules
...mySvelteRules,
},
},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment