typescript-eslint: Symlinks cause parserOptions.project errors

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

https://github.com/nikparo/ts-eslint-symlinks

Expected Result

The targeted directories and files should be linted, whether or not there are symlinks elsewhere pointing at them.

Actual Result

If there is a symlink somewhere pointing at a directory, then linting it will throw Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. errors. At least if the symlink alphabetically comes before the directory.

> ts-eslint-symlinks@0.0.0 lint /Users/nik/Projects/tmp/ts-eslint-symlinks
> eslint libs/symlinked-lib/**/*.ts

  typescript-eslint:typescript-estree:parser parserOptions.project (excluding ignored) matched projects: Set { '/users/nik/projects/tmp/ts-eslint-symlinks/tsconfig.base.json' } +0ms
  typescript-eslint:typescript-estree:createProjectProgram Creating project program for: /Users/nik/Projects/tmp/ts-eslint-symlinks/libs/symlinked-lib/src/index.ts +0ms
  typescript-eslint:typescript-estree:createWatchProgram File did not belong to any existing programs, moving to create/update. /users/nik/projects/tmp/ts-eslint-symlinks/libs/symlinked-lib/src/index.ts +0ms
  typescript-eslint:typescript-estree:createWatchProgram Creating watch program for /users/nik/projects/tmp/ts-eslint-symlinks/tsconfig.base.json. +0ms

/Users/nik/Projects/tmp/ts-eslint-symlinks/libs/symlinked-lib/src/index.ts
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: libs/symlinked-lib/src/index.ts.
The file must be included in at least one of the projects provided

By deleting the symlink apps/legacy-app/libs (which points at libs) the errors go away. Whether the symlink is ignored or not using ignorePatterns does not seem to matter.

Additional Info

I believe I have tracked this down to the use of updatedProgram.getRootFileNames() in createWatchProgram.js. That method call seems to only get the first instance of a symlinked file. I.e. apps/legacy-app/libs/symlinked-lib/src/index.ts will be in the returned fileList, but libs/symlinked-lib/src/index.ts will not.

Versions

package version
@typescript-eslint/typescript-estree 4.14.1
TypeScript 4.1.3
node v12.20.0

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 22
  • Comments: 25 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Following this discussion, I think this will fix the issue, Change

https://github.com/typescript-eslint/typescript-eslint/blob/da485279f13cb95db1ee131a4f9c5367d54020fe/packages/typescript-estree/src/create-program/createProjectProgram.ts#L26

to

const realPath = fs.realpathSync(extra.filePath)
getProgramsForProjects(code, realPath, extra), 

@JoshuaKGoldberg, @bradzacher,

Sorry. My previous message was not intended to be pushy. I will wait patiently for this.

Some code already calls to fs functions. Search for 'fs' imports and you’ll come across files like useProvidedPrograms.ts.

Thanks. Tried applying the propsed fixed but tests went bananas.

Hoping that someone who knows this project will pick this up 🤞🙏

i have few news about this issue, and this seem to be caused by our normalization of paths <- that was a fix introduced to fix issues with editors

i can confirm that i can reproduce this issue on linux

@alex-kinokon Can you please provide your insight as PR ❤️

@alex-kinokon feel free to send a PR, that’d be lovely! I’m not 100% sure that the project: true issue is the same as the original one in the issue, but either way if there’s a demonstrable problem we’d happily take in a fix.

I’ll extend that invitation to everybody seeing this. We the maintainers haven’t had time to send a PR ourselves but I see at least 2-3 suggestions of how to fix the issue in the thread. Wonderful opportunity for someone to send a code contribution in. 😄

I’m also having this problem using ESLint from a symlink location resulting in the error project was set to `true` but couldn't find any tsconfig.json relative to .... The problem seems to be

https://github.com/typescript-eslint/typescript-eslint/blob/810fc8c9a18cb55af144d8945fdf38d841c9d486/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts#L36

https://github.com/typescript-eslint/typescript-eslint/blob/810fc8c9a18cb55af144d8945fdf38d841c9d486/packages/typescript-estree/src/parseSettings/getProjectConfigFiles.ts#L55-L58

from PR #6084. directory is the path before symlink resolution and parseSettings.tsconfigRootDir is the path after symlink resolution, causing the length comparison to fail. Perhaps we can wrap

https://github.com/typescript-eslint/typescript-eslint/blob/810fc8c9a18cb55af144d8945fdf38d841c9d486/packages/typescript-estree/src/parseSettings/createParseSettings.ts#L68-L73

with fs.realpathSync here?

i’m going to look into this