|
1 | | -'use strict'; |
| 1 | +import jestDOM from 'eslint-plugin-jest-dom'; |
| 2 | +import svelte from 'eslint-plugin-svelte'; |
| 3 | +import tailwind from 'eslint-plugin-tailwindcss'; |
| 4 | +import testingLibrary from 'eslint-plugin-testing-library'; |
| 5 | +import globals from 'globals'; |
| 6 | +import ts from 'typescript-eslint'; |
2 | 7 |
|
3 | | -const baseConfig = require('@viamrobotics/eslint-config'); |
| 8 | +import { baseConfig, createConfig } from '@viamrobotics/eslint-config'; |
4 | 9 |
|
5 | | -module.exports = { |
6 | | - ...baseConfig, |
7 | | - extends: [ |
8 | | - ...baseConfig.extends, |
9 | | - 'plugin:tailwindcss/recommended', |
10 | | - 'plugin:svelte/recommended', |
11 | | - 'plugin:svelte/prettier', |
12 | | - ], |
13 | | - settings: { |
14 | | - svelte: { |
15 | | - ignoreWarnings: [ |
16 | | - '@typescript-eslint/no-unsafe-assignment', |
17 | | - '@typescript-eslint/no-unsafe-member-access', |
18 | | - ], |
19 | | - }, |
20 | | - tailwindcss: { |
21 | | - callees: ['classnames', 'cx'], |
22 | | - classRegex: '^(?:class|cx)$', |
23 | | - }, |
24 | | - }, |
25 | | - parserOptions: { |
26 | | - ...baseConfig.parserOptions, |
27 | | - extraFileExtensions: ['.svelte'], |
28 | | - }, |
29 | | - overrides: [ |
30 | | - ...baseConfig.overrides, |
31 | | - { |
32 | | - files: ['*.svelte'], |
33 | | - parser: 'svelte-eslint-parser', |
| 10 | +/** |
| 11 | + * @typedef {import('@viamrobotics/eslint-config').ConfigArray} ConfigArray |
| 12 | + */ |
| 13 | + |
| 14 | +/** @type {ConfigArray} */ |
| 15 | +const baseSvelteConfig = createConfig( |
| 16 | + baseConfig, |
| 17 | + tailwind.configs['flat/recommended'], |
| 18 | + svelte.configs['flat/recommended'], |
| 19 | + svelte.configs['flat/prettier'], |
| 20 | + |
| 21 | + // Base options and settings |
| 22 | + { |
| 23 | + name: 'viam/svelte/base', |
| 24 | + languageOptions: { |
34 | 25 | parserOptions: { |
35 | | - parser: '@typescript-eslint/parser', |
| 26 | + parser: ts.parser, |
| 27 | + extraFileExtensions: ['.svelte'], |
| 28 | + svelteFeatures: { |
| 29 | + experimentalGenerics: true, |
| 30 | + }, |
36 | 31 | }, |
37 | | - rules: { |
38 | | - // Redundant with `svelte-check` and build |
39 | | - 'svelte/valid-compile': 'off', |
40 | | - // Allows us to set option props to `undefined` by default |
41 | | - 'no-undef-init': 'off', |
| 32 | + globals: { |
| 33 | + ...globals.browser, |
42 | 34 | }, |
43 | 35 | }, |
44 | | - // Rules for tests |
45 | | - { |
46 | | - files: ['**/__tests__/**', '**/*.test.ts', '**/*.spec.ts'], |
47 | | - extends: ['plugin:jest-dom/recommended', 'plugin:testing-library/dom'], |
48 | | - rules: { |
49 | | - 'testing-library/await-async-events': [ |
50 | | - 'error', |
51 | | - { eventModule: ['fireEvent', 'userEvent'] }, |
52 | | - ], |
53 | | - 'testing-library/no-await-sync-events': 'off', |
54 | | - 'testing-library/no-node-access': [ |
55 | | - 'error', |
56 | | - { allowContainerFirstChild: true }, |
57 | | - ], |
58 | | - 'testing-library/prefer-explicit-assert': [ |
59 | | - 'error', |
60 | | - { assertion: 'toBeInTheDocument' }, |
| 36 | + settings: { |
| 37 | + svelte: { |
| 38 | + ignoreWarnings: [ |
| 39 | + '@typescript-eslint/no-unsafe-assignment', |
| 40 | + '@typescript-eslint/no-unsafe-member-access', |
61 | 41 | ], |
62 | | - 'testing-library/prefer-user-event': 'error', |
63 | 42 | }, |
| 43 | + tailwindcss: { |
| 44 | + callees: ['classnames', 'cx'], |
| 45 | + classRegex: '^(?:class|cx)$', |
| 46 | + }, |
| 47 | + }, |
| 48 | + rules: { |
| 49 | + // Too many false positives |
| 50 | + 'svelte/require-stores-init': 'off', |
64 | 51 | }, |
65 | | - ], |
66 | | -}; |
| 52 | + }, |
| 53 | + |
| 54 | + { |
| 55 | + name: 'viam/svelte/svelte-base', |
| 56 | + files: ['**/*.svelte'], |
| 57 | + rules: { |
| 58 | + // Allows us to set option props to `undefined` by default |
| 59 | + 'no-undef-init': 'off', |
| 60 | + }, |
| 61 | + }, |
| 62 | + |
| 63 | + { |
| 64 | + name: 'viam/svelte/component-testing', |
| 65 | + extends: [ |
| 66 | + jestDOM.configs['flat/recommended'], |
| 67 | + testingLibrary.configs['flat/dom'], |
| 68 | + ], |
| 69 | + files: ['**/__tests__/**', '**/*.test.ts', '**/*.spec.ts'], |
| 70 | + rules: { |
| 71 | + ...testingLibrary.configs['flat/dom'].rules, |
| 72 | + 'testing-library/await-async-events': [ |
| 73 | + 'error', |
| 74 | + { eventModule: ['fireEvent', 'userEvent'] }, |
| 75 | + ], |
| 76 | + 'testing-library/no-await-sync-events': 'off', |
| 77 | + 'testing-library/no-node-access': [ |
| 78 | + 'error', |
| 79 | + { allowContainerFirstChild: true }, |
| 80 | + ], |
| 81 | + 'testing-library/prefer-explicit-assert': [ |
| 82 | + 'error', |
| 83 | + { assertion: 'toBeInTheDocument' }, |
| 84 | + ], |
| 85 | + 'testing-library/prefer-user-event': 'error', |
| 86 | + }, |
| 87 | + } |
| 88 | +); |
| 89 | + |
| 90 | +export { baseSvelteConfig }; |
| 91 | +export { createConfig } from '@viamrobotics/eslint-config'; |
0 commit comments