Skip to content

Commit 45eb9ba

Browse files
authored
APP-7509: update common ESLint configs to v9 (#54)
1 parent e7d663f commit 45eb9ba

File tree

19 files changed

+1032
-1080
lines changed

19 files changed

+1032
-1080
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.eslintrc.cjs

Lines changed: 0 additions & 35 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
node_modules
22
dist
3-
*.d.cts
4-
*.d.ts
53
*.tgz
64
*.tsbuildinfo

eslint.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { baseConfig, createConfig } from '@viamrobotics/eslint-config';
2+
3+
export default createConfig(
4+
baseConfig,
5+
{
6+
languageOptions: {
7+
parserOptions: {
8+
projectService: true,
9+
tsconfigRootDir: import.meta.dirname,
10+
},
11+
},
12+
},
13+
{
14+
ignores: ['**/dist/**'],
15+
}
16+
);

package.json

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,20 @@
1717
},
1818
"packageManager": "[email protected]+sha256.06e65a4965baff6d6097f9c8f75c35f6d420974dbc03d775009056a69edfd271",
1919
"devDependencies": {
20-
"@types/node": "^22.10.1",
20+
"@types/node": "^22.13.1",
2121
"@types/semver": "^7.5.8",
22-
"@typescript-eslint/eslint-plugin": "^8.17.0",
23-
"@typescript-eslint/parser": "^8.17.0",
22+
"@typescript-eslint/eslint-plugin": "^8.23.0",
23+
"@typescript-eslint/parser": "^8.23.0",
2424
"@viamrobotics/eslint-config": "workspace:*",
2525
"@viamrobotics/prettier-config": "workspace:*",
2626
"@viamrobotics/typescript-config": "workspace:*",
27-
"concurrently": "^9.1.0",
28-
"eslint": "^8.57.1",
29-
"eslint-config-prettier": "^9.1.0",
30-
"eslint-plugin-jest-dom": "^5.5.0",
31-
"eslint-plugin-simple-import-sort": "^12.1.1",
32-
"eslint-plugin-svelte": "^2.46.1",
33-
"eslint-plugin-tailwindcss": "^3.17.5",
34-
"eslint-plugin-testing-library": "^7.0.0",
35-
"eslint-plugin-unicorn": "^56.0.1",
36-
"eslint-plugin-vitest": "^0.5.4",
37-
"prettier": "^3.4.1",
38-
"semver": "^7.6.3",
39-
"svelte": "^5.4.0",
40-
"tailwindcss": "3.4.15",
41-
"typescript": "^5.7.2",
42-
"vitest": "^2.1.8"
27+
"concurrently": "^9.1.2",
28+
"eslint": "^9.20.0",
29+
"prettier": "^3.5.0",
30+
"semver": "^7.7.1",
31+
"svelte": "^5.19.9",
32+
"tailwindcss": "3.4.16",
33+
"typescript": "^5.7.3",
34+
"vitest": "^3.0.5"
4335
}
4436
}

packages/eslint-config-svelte/README.md

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
# Viam's ESLint Config for Svelte
22

3-
This module contains [Viam][]'s shared [ESLint][] configurations for ESLint v8 in [Svelte][] projects.
3+
This module contains [Viam][]'s shared [ESLint][] configurations for ESLint v9 in [Svelte][] projects.
44

55
[viam]: https://www.viam.com/
66
[eslint]: https://eslint.org/
77
[svelte]: https://svelte.dev/
88

99
## Base config
1010

11-
Extend the [config](./eslint-config-svelte.js) in `.eslintrc.cjs`.
11+
Extend the [config](./eslint-config-svelte.js) in `eslint.config.js`.
12+
13+
> [!TIP]
14+
> See the typescript-eslint docs on [type-aware linting](https://typescript-eslint.io/getting-started/typed-linting) to learn about how to configure `languageOptions`. Using `projectService: true` is recommended for new projects, but older projects may continue to use `project: './tsconfig.json'` for performance or compatibility reasons.
1215
1316
```shell
14-
pnpm add --save-dev \
15-
eslint@^8.56.0 \
16-
@viamrobotics/eslint-config-svelte \
17-
@typescript-eslint/parser \
18-
@typescript-eslint/eslint-plugin \
19-
eslint-config-prettier \
20-
eslint-plugin-jest-dom \
21-
eslint-plugin-simple-import-sort \
22-
eslint-plugin-svelte \
23-
eslint-plugin-tailwindcss \
24-
eslint-plugin-testing-library \
25-
eslint-plugin-unicorn \
26-
eslint-plugin-vitest
17+
pnpm add --save-dev eslint @viamrobotics/eslint-config-svelte
2718
```
2819

2920
```js
30-
// .eslintrc.cjs
31-
'use strict';
32-
33-
module.exports = {
34-
root: true,
35-
extends: ['@viamrobotics/eslint-config-svelte'],
36-
parserOptions: {
37-
tsconfigRootDir: __dirname,
38-
projectService: true,
21+
// eslint.config.js
22+
import path from 'node:path';
23+
24+
import {
25+
baseSvelteConfig,
26+
createConfig,
27+
} from '@viamrobotics/eslint-config-svelte';
28+
29+
export default createConfig(
30+
baseSvelteConfig,
31+
{
32+
languageOptions: {
33+
parserOptions: {
34+
projectService: true,
35+
tsconfigRootDir: import.meta.dirname,
36+
},
37+
},
38+
settings: {
39+
tailwindcss: {
40+
config: path.join(import.meta.dirname, 'tailwind.config.ts'),
41+
},
42+
},
3943
},
40-
};
4144
```
4245
4346
## Non-Svelte projects
Lines changed: 82 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,91 @@
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';
27

3-
const baseConfig = require('@viamrobotics/eslint-config');
8+
import { baseConfig, createConfig } from '@viamrobotics/eslint-config';
49

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: {
3425
parserOptions: {
35-
parser: '@typescript-eslint/parser',
26+
parser: ts.parser,
27+
extraFileExtensions: ['.svelte'],
28+
svelteFeatures: {
29+
experimentalGenerics: true,
30+
},
3631
},
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,
4234
},
4335
},
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',
6141
],
62-
'testing-library/prefer-user-event': 'error',
6342
},
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',
6451
},
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';

packages/eslint-config-svelte/package.json

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"publishConfig": {
44
"access": "public"
55
},
6-
"version": "0.8.0",
6+
"version": "1.0.0",
77
"description": "ESLint configuration for Svelte projects at Viam.",
8-
"type": "commonjs",
8+
"type": "module",
99
"main": "./eslint-config-svelte.js",
1010
"types": "./dist/eslint-config-svelte.d.ts",
1111
"exports": {
@@ -26,21 +26,28 @@
2626
],
2727
"license": "Apache-2.0",
2828
"dependencies": {
29-
"@viamrobotics/eslint-config": "workspace:*"
29+
"@typescript-eslint/utils": "~8.23.0",
30+
"@viamrobotics/eslint-config": "workspace:^",
31+
"eslint-plugin-jest-dom": "~5.5.0",
32+
"eslint-plugin-svelte": "~3.0.0 || ~3.0.0-next",
33+
"eslint-plugin-tailwindcss": "~3.17.5",
34+
"eslint-plugin-testing-library": "~7.1.1",
35+
"globals": "^15.13.0",
36+
"typescript-eslint": "~8.23.0"
3037
},
3138
"peerDependencies": {
32-
"@typescript-eslint/eslint-plugin": ">=6 <9",
33-
"@typescript-eslint/parser": ">=6 <9",
34-
"eslint": ">=8 <9",
35-
"eslint-config-prettier": ">=9 <10",
36-
"eslint-plugin-jest-dom": ">=5 <6",
37-
"eslint-plugin-simple-import-sort": ">=12 <13",
38-
"eslint-plugin-svelte": ">=2 <3",
39-
"eslint-plugin-tailwindcss": ">=3 <4",
40-
"eslint-plugin-testing-library": ">=6 <8",
41-
"eslint-plugin-unicorn": ">=47 <57",
42-
"eslint-plugin-vitest": ">=0.5 <0.6",
39+
"eslint": ">=9 <10",
40+
"svelte": "*",
41+
"tailwindcss": ">=3 <4",
4342
"typescript": ">=5 <6",
4443
"vitest": "*"
44+
},
45+
"peerDependenciesMeta": {
46+
"svelte": {
47+
"optional": true
48+
},
49+
"vitest": {
50+
"optional": true
51+
}
4552
}
4653
}

packages/eslint-config-svelte/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"outDir": "dist"
99
},
1010
"references": [{ "path": "../eslint-config" }],
11-
"include": ["*.js"]
11+
"include": ["*.js", "typings"]
1212
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare module 'eslint-plugin-tailwindcss' {
2+
import type { Linter } from 'eslint';
3+
4+
const rules: Linter.RulesRecord;
5+
const configs: { 'flat/recommended': Linter.Config };
6+
7+
export default { rules, configs };
8+
}

0 commit comments

Comments
 (0)