Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOTDIR with virtual filenames from processors #393

Closed
btmills opened this issue Feb 28, 2021 · 4 comments · Fixed by #401
Closed

ENOTDIR with virtual filenames from processors #393

btmills opened this issue Feb 28, 2021 · 4 comments · Fixed by #401

Comments

@btmills
Copy link

btmills commented Feb 28, 2021

What version of eslint are you using? 7.21.0

What version of prettier are you using? 2.2.1

What version of eslint-plugin-prettier are you using? 3.3.1

{
  "script": {
    "test": "eslint README.md"
  },
  "devDependencies": {
    "eslint": "^7.21.0",
    "eslint-config-prettier": "^8.1.0",
    "eslint-plugin-markdown": "^2.0.0",
    "eslint-plugin-prettier": "^3.3.1",
    "prettier": "^2.2.1"
  }
}

Please paste any applicable config files that you're using (e.g. .prettierrc or .eslintrc files)

No .prettierrc.

// .eslintrc.js
module.exports = {
    root: true,
    extends: ['plugin:prettier/recommended', 'plugin:markdown/recommended'],
};

What source code are you linting?

# README.md

```js
var x = 123;
```

What did you expect to happen?

npm test should run without throwing an exception.

What actually happened?

$ npm test
Oops! Something went wrong! :(

ESLint: 7.21.0

Error: ENOTDIR: not a directory, stat '.../README.md/0_0.js'
Occurred while linting .../README.md/0_0.js:1
    at Object.statSync (node:fs:1128:3)
    at isTypeSync (.../node_modules/prettier/third-party.js:9748:46)
    at getDirectorySync (.../node_modules/prettier/third-party.js:9802:62)
    at ExplorerSync.searchSync (.../node_modules/prettier/third-party.js:9950:66)
    at _resolveConfig (.../node_modules/prettier/index.js:25592:50)
    at Function.resolveConfig.sync (.../node_modules/prettier/index.js:25621:42)
    at Program (.../node_modules/eslint-plugin-prettier/eslint-plugin-prettier.js:167:40)
    at .../node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (.../node_modules/eslint/lib/linter/safe-emitter.js:45:38)

Credit to eslint/markdown#174 for originally reporting this. My examples are based on that issue.

eslint-plugin-markdown v2 switched to use the new processor API that was released as part of ESLint v6. Instead of returning each extracted code block as a string, processors can now return both the source code text and a filename. In the example code above, the code block's returned filename would be 0.js, with the extension coming from the code block's syntax tag.

The new processor API uses the code block's filename to construct a virtual filename as parentFilename + path.sep + index + filenameFromPreprocess. In the example above, the code block's virtual filename becomes README.md/0_0.js.

Based on the stack trace and a bit of stepping in a debugger, it looks like the exception is thrown when the rule tries to load the .prettierrc for the file. If I set usePrettierrc: false, a very similar exception is thrown in a call a few lines later.

This exception would occur with any processor that uses the new processor API and yields virtual filenames.

Depending on what it might take to handle code blocks with virtual filenames, eslint/eslint#11989 may be a related issue.

@JounQin
Copy link
Member

JounQin commented Mar 11, 2021

I have the same situation when implementing linting code blocks for eslint-plugin-mdx which use virtual filename same as eslint-plugin-markdown.

@JounQin
Copy link
Member

JounQin commented Mar 13, 2021

Personally I add a hack check for it in eslint-plugin-mdx, if you like it I can raise a PR.

https://github.com/mdx-js/eslint-mdx/blob/master/packages/eslint-plugin-mdx/src/rules/helpers.ts#L58-L71


@lydell @fisker @BPScott

@JounQin
Copy link
Member

JounQin commented Mar 23, 2021

For anyone maybe interested, #401 should fix this issue, I just published @rxts/eslint-plugin-prettier@^3.4.0-1 as workaround, you can use "eslint-plugin-prettier": "npm:@rxts/eslint-plugin-prettier@^3.4.0-1" in package.json.

Once that PR been merged and released, I'll deprecate it.

@nonameolsson
Copy link

Thank you, this solves the problem! Hope this PR will get merged.

BPScott pushed a commit that referenced this issue Apr 14, 2021
* feat: support processor virtual filename

close #393

* refactor: normalize filepath first in case recursive virtual filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants