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'); 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 * An extension on the default yeslint! generic config, with rules specific to
* Svelte codebases and JavaScript source code for browser environments. * Svelte codebases and JavaScript source code for browser environments.
@ -12,6 +20,7 @@ const generic = require('./generic.js');
* @type {import('eslint').Linter.Config} * @type {import('eslint').Linter.Config}
*/ */
const svelte = { const svelte = {
...generic,
parserOptions: { parserOptions: {
...generic.parserOptions, ...generic.parserOptions,
ecmaVersion: 2020, ecmaVersion: 2020,
@ -31,73 +40,72 @@ const svelte = {
...generic.plugins, ...generic.plugins,
'svelte', 'svelte',
], ],
overrides: [ { overrides: [
files: '*.svelte', ...generic.overrides,
parser: 'svelte-eslint-parser', {
rules: { files: '*.svelte',
'no-inner-declarations': 0, parser: 'svelte-eslint-parser',
'max-len': [ parserOptions: typescriptInstalled ? {
'warn', parser: '@typescript-eslint/parser',
{ } : undefined,
...generic.rules['max-len'][1], rules: {
code: 200, 'no-inner-declarations': 0,
}, 'svelte/no-inner-declarations': [
], 'error',
'svelte/no-inner-declarations': [ 'functions',
'error', ],
'functions', 'svelte/html-quotes': [
], 'error',
'svelte/html-quotes': [ {
'error', prefer: 'double',
{ dynamic: {
prefer: 'double', quoted: false,
dynamic: { avoidInvalidUnquotedInHTML: false,
quoted: false, },
avoidInvalidUnquotedInHTML: false,
}, },
}, ],
], 'svelte/no-useless-mustaches': 'warn',
'svelte/no-useless-mustaches': 'warn', 'svelte/require-store-reactive-access': 'warn',
'svelte/require-store-reactive-access': 'warn', 'svelte/no-reactive-literals': 'error',
'svelte/no-reactive-literals': 'error', 'svelte/html-closing-bracket-spacing': 'warn',
'svelte/html-closing-bracket-spacing': 'warn', 'svelte/indent': [
'svelte/indent': [ 'warn',
'warn', {
{ indent: 2,
indent: 2, ignoredNodes: [],
ignoredNodes: [], switchCase: 1,
switchCase: 1, alignAttributesVertically: false,
alignAttributesVertically: false, },
}, ],
], 'svelte/max-attributes-per-line': [
'svelte/max-attributes-per-line': [ 'warn',
'warn', {
{ multiline: 1,
multiline: 1, singleline: 4,
singleline: 4, },
}, ],
], 'svelte/first-attribute-linebreak': [
'svelte/first-attribute-linebreak': [ 'warn',
'warn', {
{ multiline: 'below',
multiline: 'below', singleline: 'beside',
singleline: 'beside', },
}, ],
], 'svelte/mustache-spacing': 'warn',
'svelte/mustache-spacing': 'warn', 'svelte/no-extra-reactive-curlies': 'error',
'svelte/no-extra-reactive-curlies': 'error', 'svelte/no-spaces-around-equal-signs-in-attribute': 'warn',
'svelte/no-spaces-around-equal-signs-in-attribute': 'warn', 'svelte/prefer-class-directive': 'warn',
'svelte/prefer-class-directive': 'warn', 'svelte/shorthand-attribute': 'warn',
'svelte/shorthand-attribute': 'warn', 'svelte/shorthand-directive': 'warn',
'svelte/shorthand-directive': 'warn', 'svelte/spaced-html-comment': 'warn',
'svelte/spaced-html-comment': 'warn', 'svelte/no-at-html-tags': 0,
'svelte/no-at-html-tags': 0, 'svelte/html-self-closing': [
'svelte/html-self-closing': [ 'warn',
'warn', 'all',
'all', ],
], },
}, },
} ], ],
rules: { rules: {
...generic.rules, ...generic.rules,
strict: 0, strict: 0,