Skip to content

Commit a91d709

Browse files
committed
When you add the recommendation from ota-meshi/eslint-plugin-astro#168 (comment)
You get "unsafe assignment of an error typed value" with `DEPRECATED__createDefaultProgram`
1 parent b0fe6c2 commit a91d709

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

eslint.config.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export default [
1717
{
1818
languageOptions: {
1919
parserOptions: {
20-
project: ["./tsconfig.json"],
20+
project: ["./tsconfig.json", "./tsconfig.eslint.json"],
2121
// When typescript/eslint v8 comes out this will become projectService
2222
// https://github.com/typescript-eslint/typescript-eslint/issues/9141
23-
// EXPERIMENTAL_useProjectService: true,
23+
EXPERIMENTAL_useProjectService: true,
2424
DEPRECATED__createDefaultProgram: true,
2525
tsconfigRootDir: import.meta.dirname,
2626
},

eslint.jsx.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import "astro/astro-jsx";
2+
declare namespace astroHTML.JSX {
3+
Element = HTMLElement
4+
}
5+
// See https://stackoverflow.com/a/75543975 and https://github.com/ota-meshi/eslint-plugin-astro/issues/168#issuecomment-1439480332
6+
// See https://github.com/withastro/astro/blob/4d13cf031b2e4242e0055b48c09a80d69b9ed15d/packages/astro/astro-jsx.d.ts#L34-L37
7+
declare global {
8+
type Element = HTMLElement;
9+
namespace JSX {
10+
// type Element = astroHTML.JSX.Element // We want to use this, but it is defined as any.
11+
type Element = HTMLElement;
12+
// type IntrinsicElements = astroHTML.JSX.IntrinsicElements;
13+
}
14+
}

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
2-
"name": "",
2+
"name": "astro-eslint-plugin-issue-report",
33
"type": "module",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"scripts": {
66
"dev": "astro dev",
77
"start": "astro dev",
88
"build": "astro check && astro build",
99
"preview": "astro preview",
10-
"astro": "astro"
10+
"astro": "astro",
11+
"lint": "eslint ."
1112
},
1213
"dependencies": {
1314
"@astrojs/check": "^0.7.0",

src/pages/index.astro

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@ const b = 0;
2525
const d: any = 1;
2626

2727
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
28+
// Unsafe assignment of an error typed value
2829
const element = document.getElementById("myroot")!;
2930
// no error
3031
console.log(element.offsetLeft + 4);
3132
// error Invalid operand for a '+' operation. Operands must each be a number or string. Got `any` @typescript-eslint/restrict-plus-operands
32-
console.log(element.offsetLeft += 4);
33+
console.log((element.offsetLeft += 4));
3334
console.log(d);
3435
console.log("c");
36+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
3537
const container = document.querySelector(".container")!;
3638
container.scrollLeft += 2;
39+
function scrollRight() {
40+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
41+
const other = document.querySelector(".other")!;
42+
const value = other.scrollLeft;
43+
other.scrollLeft = value + 2;
44+
}
45+
scrollRight();
3746
</script>
3847
</html>

tsconfig.eslint.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This allows linting all files, including those that are excluded from our typescript compilation
2+
{
3+
"extends": "./tsconfig.json",
4+
// WARN: If 'include' is changed on the main config, this file would overwrite it, so you should consider modifying this.
5+
"include": [
6+
"eslint.jsx.d.ts",
7+
"**/*.json",
8+
".astro/**/*",
9+
"src/**/*",
10+
"bin/**/*",
11+
"__tests__/**/*",
12+
".*.js",
13+
"*.js",
14+
".*.ts",
15+
"*.ts",
16+
],
17+
}

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"extends": "astro/tsconfigs/strict"
2+
"extends": "astro/tsconfigs/strict",
3+
"include": ["eslint.jsx.d.ts"]
34
}

0 commit comments

Comments
 (0)