diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 977a4ae594..0000000000 --- a/.eslintignore +++ /dev/null @@ -1,24 +0,0 @@ -# Repository -.vscode/ - -patches/ - -# Desktop (packages/desktop) -packages/desktop/electron-builder-config.js -packages/desktop/out/ -packages/desktop/public/ -packages/desktop/electron/lib/keychain.js - -# Shared (packages/shared) -packages/shared/src/assets/ -!packages/shared/src/lib/tests/ -packages/shared/src/locales/ -!packages/shared/src/locales/en.json - -# Common files and folders -**/node_modules/ -**/out/ -**/tests/ - -# ESLint configuration and files -**/.eslintrc.js diff --git a/.eslintrc.js b/eslint.config.js similarity index 66% rename from .eslintrc.js rename to eslint.config.js index c678416171..f2fedafb66 100644 --- a/.eslintrc.js +++ b/eslint.config.js @@ -1,15 +1,19 @@ -const parserOptions = { - ecmaVersion: 6, - sourceType: 'module', -} +const globals = require('globals') +const jsEslint = require('@eslint/js') +const securityPlugin = require('eslint-plugin-security') +const sveltePlugin = require('eslint-plugin-svelte') +const babelParser = require('@babel/eslint-parser') +const tsEslint = require('typescript-eslint') +// const tsParser = require('@typescript-eslint/parser') +const svelteParser = require('svelte-eslint-parser') const eslintRules = { 'arrow-body-style': 'off', // OFF b/c blocks style allows for readability and ensure scope 'arrow-spacing': 'error', 'eol-last': 'error', - 'eqeqeq': 'error', + eqeqeq: 'error', 'func-call-spacing': 'error', - 'indent': 'off', // OFF b/c causes problems between Prettier and ESLint + indent: 'off', // OFF b/c causes problems between Prettier and ESLint 'linebreak-style': 'off', // OFF b/c Windows (Git) puts CRLF line endings 'missing-declaration': 'off', // OFF b/c throws errors on imports / require statements 'multiline-ternary': 'off', // OFF b/c causes problems between Prettier and ESLint @@ -39,14 +43,14 @@ const eslintRules = { 'prefer-arrow-callback': 'warn', 'prefer-const': 'warn', 'prefer-destructuring': 'off', // OFF b/c it's not really correct - 'quotes': ['error', 'single'], - 'semi': 'off', // OFF b/c we aren't using semicolons + quotes: ['error', 'single'], + semi: 'off', // OFF b/c we aren't using semicolons 'space-before-function-paren': 'off', // OFF b/c we aren't using spaces before function parameters / signatures 'spaced-comment': 'error', } const eslintRulesOnlyTypescript = { - 'no-undef': 'off' // Typescript handles undefined variables better than eslint + 'no-undef': 'off', // Typescript handles undefined variables better than eslint } const typescriptEslintRules = { @@ -104,51 +108,87 @@ const svelteSettings = { 'svelte/ignore-warnings': () => false, } -module.exports = { - env: { - browser: true, - es6: true, - node: true, - }, - extends: ['eslint:recommended', 'plugin:svelte/recommended'], - overrides: [ - { - files: ['**/*.ts', '**/*.svelte'], - extends: [ - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:@typescript-eslint/recommended-requiring-type-checking', - ], - parser: '@typescript-eslint/parser', +const parserOptions = { + ecmaVersion: 2021, + sourceType: 'module', +} + +module.exports = [ + jsEslint.configs.recommended, + securityPlugin.configs.recommended, + ...sveltePlugin.configs['flat/recommended'], + { + languageOptions: { parserOptions: { ...parserOptions, - extraFileExtensions: ['.svelte'], - project: './tsconfig.lint.json', - tsconfigRootDir: './', + requireConfigFile: false, + }, + parser: babelParser, + globals: { + ...globals.browser, + ...globals.node, + ...globals.es2021, }, - plugins: ['@typescript-eslint'], - rules: linterRules, - settings: svelteSettings, }, - { - files: '**/*.svelte', - parser: 'svelte-eslint-parser', - settings: svelteSettings, + rules: { + ...eslintRules, + }, + }, + ...tsEslint.config({ + files: ['**/*.ts'], + extends: [jsEslint.configs.recommended, ...tsEslint.configs.recommended], + languageOptions: { + // parser: svelteParser, parserOptions: { - parser: '@typescript-eslint/parser' + ...parserOptions, + // extraFileExtensions: ['.svelte'], + project: './tsconfig.lint.json', + tsconfigRootDir: './', }, - rules: { - ...linterRules, - ...svelteRules, - } }, - ], - parser: '@babel/eslint-parser', - parserOptions: { - ...parserOptions, - requireConfigFile: false, - }, - rules: { - ...eslintRules, + rules: linterRules, + // settings: svelteSettings, + }), + // { + // files: ['**/*.svelte'], + // settings: svelteSettings, + // // ...sveltePlugin.configs['flat/recommended'], + // languageOptions: { + // parser: svelteParser, + // parserOptions: { + // ...parserOptions, + // extraFileExtensions: ['.svelte'], + // project: './tsconfig.lint.json', + // tsconfigRootDir: './', + // }, + // }, + // rules: { + // // ...linterRules, + // ...svelteRules, + // }, + // }, + { + ignores: [ + // Repository + '.vscode/', + 'patches/', + + // Desktop (packages/desktop) + 'packages/desktop/electron-builder-config.js', + 'packages/desktop/out/', + 'packages/desktop/public/', + 'packages/desktop/electron/lib/keychain.js', + + // Shared (packages/shared) + 'packages/shared/src/assets/', + '!packages/shared/src/lib/tests/', + 'packages/shared/src/locales/', + '!packages/shared/src/locales/en.json', + + // Common files and folders + '**/node_modules/', + '**/out/', + '**/tests/', + ], }, -} +]