question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.prettierignore entries containing path separators are ignored

See original GitHub issue

What version of eslint are you using? 5.9.0

What version of prettier are you using? 1.15.2

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

Please paste any applicable config files that you’re using (e.g. .prettierrc or .eslintrc files) https://github.com/edmorley/testcase-eslint-plugin-prettier-ignore/blob/master/.eslintrc.js https://github.com/edmorley/testcase-eslint-plugin-prettier-ignore/blob/master/.prettierignore

What source code are you linting? https://github.com/edmorley/testcase-eslint-plugin-prettier-ignore/blob/master/src/not_pretty.js

Steps to reproduce

  1. Git clone https://github.com/edmorley/testcase-eslint-plugin-prettier-ignore
  2. yarn install
  3. yarn prettier:check # runs prettier
  4. yarn eslint:check # runs eslint and so eslint-plugin-prettier

What did you expect to happen?

  • No errors reported by either yarn prettier:check or yarn eslint:check, since the file with bad formatting is listed in .prettierignore.

What actually happened?

  • No errors reported by yarn prettier:check (as expected)
  • Formatting errors reported by yarn eslint:check:
$ yarn eslint:check
yarn run v1.12.3
$ eslint src

C:\Users\Ed\src\testcase-eslint-plugin-prettier-ignore\src\not_pretty.js
  1:12  error  Replace `⏎··'a'` with `"a"`  prettier/prettier

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

Additional Notes

  • The error goes away if I edit the .prettierignore entry to not contain a path component (eg changing it to not_pretty.js)
  • The variations /src/not_pretty.js and ./src/not_pretty.js didn’t help.
  • This reproduced on both Windows and Ubuntu.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
BPScottcommented, Nov 30, 2018

Yo @edmorley, it looks like prettier 1.15.3 got released with a fix for this. It seems to work for me in your test repo. Can you give it a go and close this issue if it works for you.

1reaction
BPScottcommented, Nov 21, 2018

Thanks for the report and the minimal reproduction repo (my favourite kind!)

It seems like Prettier’s getFileInfo() only works out nested ignore paths correctly if you specify a relative filepath.

Replacing https://github.com/prettier/eslint-plugin-prettier/blob/master/eslint-plugin-prettier.js#L166-L168 with

const relativeFilepath = require('path').relative(process.cwd(), filepath);
const prettierFileInfo = prettier.getFileInfo.sync(relativeFilepath, {
  ignorePath: '.prettierignore'
});

Seems to fix things, but I think this should be addressed upstream - getFileInfo() and getFileInfo.sync() should be able to work out ignores if you give it relative or absolute paths.


Minimal test to prove this: Save the following file as check-getinfo.js then run it with node check-getinfo.js and note that the values differ. I would expect them both to be true.

const path = require("path");
const prettier = require("prettier");

filePath = "src/not_pretty.js";
options = { ignorePath: ".prettierignore" };

const relativeInfo = prettier.getFileInfo.sync(filePath, options);
const absoluteInfo = prettier.getFileInfo.sync(path.resolve(filePath), options);

console.log("relativePath is Ignored:", relativeInfo.ignored);
console.log("absolutePath is Ignored:", absoluteInfo.ignored);

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignoring Code - Prettier
Use .prettierignore to ignore (i.e. not reformat) certain files and folders completely. Use “prettier-ignore” comments to ignore parts of files.
Read more >
Documentation: MultiQC
If the --ignore-symlinks flag is set, MultiQC will ignore symlinked ... Note that pattern delimiters are not needed (use pattern , not /pattern/...
Read more >
How to ignore node_modules from prettier - Stack Overflow
According the npm package description, prettier ignores the files you wrote a path in .prettierrc , .prettierignore , and .editorconfig .
Read more >
prettier ignore all files | The AI Search Engine You Control
Runtime: Node.js v8.11.4; Operating System: macOS. Steps to reproduce: Create a index.d.ts file with the following content:.
Read more >
Relay
RelayThe GraphQL client that scales with you. · Built for scale · Keeps iteration quick · Automatic optimizations · Data consistency · Fetching...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found