|
| 1 | +### Before You File a Bug Report Please Confirm You Have Done The Following... |
| 2 | + |
| 3 | +- [X] I have tried restarting my IDE and the issue persists. |
| 4 | +- [X] I have updated to the latest version of the packages. |
| 5 | + |
| 6 | +### What version of ESLint are you using? |
| 7 | + |
| 8 | +^8.57.0 |
| 9 | + |
| 10 | +### What version of `eslint-plugin-astro` are you using? |
| 11 | + |
| 12 | +^1.2.2 |
| 13 | + |
| 14 | +### What did you do? |
| 15 | + |
| 16 | +Please find the minimal reproducible case in the repository linked below |
| 17 | +<details> |
| 18 | +<summary>Configuration</summary> |
| 19 | +``` |
| 20 | +{ |
| 21 | + "name": "astro-eslint-plugin-issue-report", |
| 22 | + "type": "module", |
| 23 | + "version": "0.0.2", |
| 24 | + "scripts": { |
| 25 | + "dev": "astro dev", |
| 26 | + "start": "astro dev", |
| 27 | + "build": "astro check && astro build", |
| 28 | + "preview": "astro preview", |
| 29 | + "astro": "astro", |
| 30 | + "lint": "eslint ." |
| 31 | + }, |
| 32 | + "dependencies": { |
| 33 | + "@astrojs/check": "^0.7.0", |
| 34 | + "astro": "^4.11.3", |
| 35 | + "typescript": "^5.5.2" |
| 36 | + }, |
| 37 | + "devDependencies": { |
| 38 | + "@typescript-eslint/parser": "^7.14.1", |
| 39 | + "eslint": "^8.57.0", |
| 40 | + "eslint-plugin-astro": "^1.2.2", |
| 41 | + "typescript-eslint": "^7.14.1" |
| 42 | + } |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +``` |
| 47 | +import eslintPluginAstro from 'eslint-plugin-astro'; |
| 48 | +import tseslint from "typescript-eslint"; |
| 49 | +/** @type {import("@typescript-eslint/utils").TSESLint.FlatConfig.ConfigArray} */ |
| 50 | +export default [ |
| 51 | + {ignores: ["*.config.*"]}, |
| 52 | + ...tseslint.configs.strictTypeChecked, |
| 53 | + ...tseslint.configs.stylisticTypeChecked, |
| 54 | + // First issue, eslintPluginAstro MUST be defined after, since it overrides the typescript parser |
| 55 | + ...eslintPluginAstro.configs["flat/all"], |
| 56 | + { |
| 57 | + rules: { |
| 58 | + '@typescript-eslint/await-thenable': "error", |
| 59 | + // Error: Error while loading rule '@typescript-eslint/await-thenable': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. |
| 60 | + "@typescript-eslint/no-explicit-any": "error", |
| 61 | + }, |
| 62 | + }, |
| 63 | + { |
| 64 | + languageOptions: { |
| 65 | + parserOptions: { |
| 66 | + project: ["./tsconfig.json", "./tsconfig.eslint.json"], |
| 67 | + // When typescript/eslint v8 comes out this will become projectService |
| 68 | + // https://github.com/typescript-eslint/typescript-eslint/issues/9141 |
| 69 | + // EXPERIMENTAL_useProjectService: true, |
| 70 | + // DEPRECATED__createDefaultProgram: true, |
| 71 | + tsconfigRootDir: import.meta.dirname, |
| 72 | + }, |
| 73 | + }, |
| 74 | + } |
| 75 | +]; |
| 76 | +``` |
| 77 | +</details> |
| 78 | + |
| 79 | +```astro |
| 80 | +--- |
| 81 | +const a = 1; |
| 82 | +console.log("b"); |
| 83 | +
|
| 84 | +const c: any = 1; |
| 85 | +const b = 0; |
| 86 | +--- |
| 87 | +
|
| 88 | +<html lang="en"> |
| 89 | + <head> |
| 90 | + <meta charset="utf-8" /> |
| 91 | + <link rel="icon" type="image/svg+xml" href="/favicon.svg" /> |
| 92 | + <meta name="viewport" content="width=device-width" /> |
| 93 | + <meta name="generator" content={Astro.generator} /> |
| 94 | + <title>Astro</title> |
| 95 | + </head> |
| 96 | + <body id="myroot"> |
| 97 | + <div class="container"> |
| 98 | + <h1>Astro {a}</h1> |
| 99 | + </div> |
| 100 | + </body> |
| 101 | +
|
| 102 | + <script> |
| 103 | + const c = null!; |
| 104 | + const d: any = 1; |
| 105 | +
|
| 106 | + const element = document.getElementById("my-root")!; |
| 107 | + element.offsetLeft += 4; |
| 108 | + console.log(d); |
| 109 | + console.log("c"); |
| 110 | + const container = document.querySelector(".container")!; |
| 111 | + container.scrollLeft += 2; |
| 112 | + </script> |
| 113 | +</html> |
| 114 | +``` |
| 115 | + |
| 116 | + |
| 117 | +### What did you expect to happen? |
| 118 | + |
| 119 | +The code in <script> tags is linted |
| 120 | + |
| 121 | +### What actually happened? |
| 122 | + |
| 123 | +The code in between `---` is linted, but not the one inside `script` tags |
| 124 | + |
| 125 | +### Link to Minimal Reproducible Example |
| 126 | + |
| 127 | +Minimal error can be found here, I made a tag: https://github.com/alexrecuenco/astro-eslint-plugin-report-issue/tree/minimal-error |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | +I did some further exploration and, I describe my brief findings on the commit message at this tag https://github.com/alexrecuenco/astro-eslint-plugin-report-issue/tree/type-discrepancy |
| 132 | + |
| 133 | +__ |
| 134 | + |
| 135 | +### Additional comments |
| 136 | + |
| 137 | +First of all, I made a similar issue that seems to have dissapeared with a somewhat similar issue, I thought it was fixed, but it turns out it isn't. Nonetheless, the issue was either deleted or cleaned up so I can't reference it anymore |
| 138 | + |
| 139 | +By following the recommendations of this plugin's authors I added |
| 140 | + |
| 141 | +```js |
| 142 | + { |
| 143 | + languageOptions: { |
| 144 | + parserOptions: { |
| 145 | + project: ["./tsconfig.json"], |
| 146 | + tsconfigRootDir: import.meta.dirname, |
| 147 | + }, |
| 148 | + }, |
| 149 | + } |
| 150 | + |
| 151 | +``` |
| 152 | + |
| 153 | +And it seemd to have worked, I stopped getting errors when running. However, turns out, the issue was still hiding away, by running with `--debug` you can see that all the *"virtual files"* that reference the <script> tags are not parsed, so you never get feedback on them, it crashes silently while processing those files (And since those files are virtual, you also don't get reports at the top |
| 154 | + |
| 155 | + |
| 156 | +```bash |
| 157 | + eslint:linter Resolving configuration again because the file content or extension was changed. +1ms |
| 158 | + eslint:linter With flat config: /Volumes/Workspace/external/astro-eslint-plugin-report-issue/src/pages/index.astro/1_1.ts +0ms |
| 159 | + eslint:linter Parsing: /Volumes/Workspace/external/astro-eslint-plugin-report-issue/src/pages/index.astro/1_1.ts +11ms |
| 160 | + eslint:linter Parsing error: ESLint was configured to run on `<tsconfigRootDir>/src/pages/index.astro/1_1.ts` using `parserOptions.project`: <tsconfigRootDir>/tsconfig.json |
| 161 | +However, that TSConfig does not include this file. Either: |
| 162 | +- Change ESLint's list of included files to not include this file |
| 163 | +- Change that TSConfig to include this file |
| 164 | +- Create a new TSConfig that includes this file and include it in your parserOptions.project |
| 165 | +See the typescript-eslint docs for more info: https://typescript-eslint.io/troubleshooting/typed-linting#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file |
| 166 | + eslint:linter Error: ESLint was configured to run on `<tsconfigRootDir>/src/pages/index.astro/1_1.ts` using `parserOptions.project`: <tsconfigRootDir>/tsconfig.json |
| 167 | +However, that TSConfig does not include this file. Either: |
| 168 | +- Change ESLint's list of included files to not include this file |
| 169 | +- Change that TSConfig to include this file |
| 170 | +- Create a new TSConfig that includes this file and include it in your parserOptions.project |
| 171 | + |
| 172 | +``` |
| 173 | + |
| 174 | +I have tried to solve it by upgrading to version 8 of typescript eslint and eslint 9, since `projectService` is meant to process files that are "outside the project", but that didn't work due to some other incompatibility between different projects |
| 175 | + |
| 176 | +For that reason, I switched to using `EXPERIMENTAL_useProjectService`, but when that is used now the .astro file, the section in-between the `---` files doesn't run anymore, that one is now the one getting the parse error |
| 177 | + |
| 178 | +Finally, I ran eslint with a debugger line by line, and found |
| 179 | + |
| 180 | + |
| 181 | +<rootDir>/node_modules/@typescript-eslint/typescript-estree/dist/create-program/createProjectProgram.js |
| 182 | + |
| 183 | +```js |
| 184 | +function createProjectProgram(parseSettings, programsForProjects) { |
| 185 | + log('Creating project program for: %s', parseSettings.filePath); |
| 186 | + const astAndProgram = (0, node_utils_1.firstDefined)(programsForProjects, currentProgram => (0, shared_1.getAstFromProgram)(currentProgram, parseSettings.filePath)); |
| 187 | + // The file was either matched within the tsconfig, or we allow creating a default program |
| 188 | + // eslint-disable-next-line deprecation/deprecation -- will be cleaned up with the next major |
| 189 | + if (astAndProgram || parseSettings.DEPRECATED__createDefaultProgram) { |
| 190 | + return astAndProgram; |
| 191 | + } |
| 192 | + ... |
| 193 | +} |
| 194 | + |
| 195 | +``` |
| 196 | + |
| 197 | + |
| 198 | +Well, running with `DEPRECATED__createDefaultProgram: true` it "works". |
| 199 | + |
| 200 | +But of course, once you do that, the recommended trick to create a `jsx.d.ts` stops working, it regards everything as "any" (that is what the tag `type-discrepancy` explores) |
| 201 | + |
| 202 | + |
| 203 | +All the 3 setting permutations and the `--debug` output can be found in the repo at `/results-*.md` |
| 204 | + |
| 205 | + |
| 206 | +I hope this report is helpful to find how to fix this |
0 commit comments