Add parserOptions for Svelte + TypeScript

This commit is contained in:
Romein van Buren 2024-07-25 13:17:28 +02:00
parent 27d8247ad0
commit 5d5d224d25
No known key found for this signature in database

View File

@ -2,6 +2,14 @@
const generic = require('./generic.js');
let typescriptInstalled = true;
try {
require('typescript');
typescriptInstalled = true;
}
catch { /* not installed */ }
/**
* An extension on the default yeslint! generic config, with rules specific to
* Svelte codebases and JavaScript source code for browser environments.
@ -12,6 +20,7 @@ const generic = require('./generic.js');
* @type {import('eslint').Linter.Config}
*/
const svelte = {
...generic,
parserOptions: {
...generic.parserOptions,
ecmaVersion: 2020,
@ -31,18 +40,16 @@ const svelte = {
...generic.plugins,
'svelte',
],
overrides: [ {
overrides: [
...generic.overrides,
{
files: '*.svelte',
parser: 'svelte-eslint-parser',
parserOptions: typescriptInstalled ? {
parser: '@typescript-eslint/parser',
} : undefined,
rules: {
'no-inner-declarations': 0,
'max-len': [
'warn',
{
...generic.rules['max-len'][1],
code: 200,
},
],
'svelte/no-inner-declarations': [
'error',
'functions',
@ -97,7 +104,8 @@ const svelte = {
'all',
],
},
} ],
},
],
rules: {
...generic.rules,
strict: 0,