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.

Config overrides do not work for files in the parent directory

See original GitHub issue

I’m using prettier to format some json files with custom extensions (like VSCode’s .code-workspace files). The files are in the parent directory of the project, so I’m running prettier --write ../**/*.{json-1,json-2}.

The problem I have is that I cannot tell prettier that parser for .json-1 files is "json". This is my config:

{
    "overrides": [
        {
            "files": "*.json-1",
            "options": {
                "parser": "json"
            }
        }
    ]
}

And when I run prettier, it gives me this output:

[error] No parser could be inferred for file: ../test.json-1

I have also tried changing "files": "*.json-1" to "files": "**/*.json-1" and "files": "../**/*.json-1", but the behavior is the same.

Environments:

  • Prettier Version: 2.7.1
  • Running Prettier via: CLI
  • Runtime: Node.js v16.14.2
  • Operating System: Ubuntu 20.04.4
  • Prettier plugins (if any): –

Steps to reproduce:

Here’s the repro (in the prettier-parent-overrides branch): https://github.com/Shayan-To/repros/tree/prettier-parent-overrides

Go into the project directory cd prettier-proj, and after npm install, run npm run repro.

There are files both in the parent directory, and in the project directory. Prettier can infer the parser for none of the files in the parent directory.

Expected behavior:

The overrides configurations for the files in the parent directory can be set.

Actual behavior:

There seems to be no way to set overrides configurations for the files in the parent directory.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
thorn0commented, Oct 2, 2022

Forgot about this: https://prettier.io/docs/en/cli.html#--find-config-path-and---config You can specify the config file in the command line to get what you need.

1reaction
thorn0commented, Oct 1, 2022

you mean that I can add a prettierrc to a sub-directory of my project, and it will apply to files in that sub-directory?

Right

What if I’m formatting files in the parent directory (prettier --write …/**/*.json)? Will the prettierrc from the project directory apply there?

Only for files inside the project directory because your glob includes them.

Will the prettierrc from the parent directory apply there?

Yes

As for editorconfig, AFAIK, it’s all intended too, but I can’t comment more on it now. Feel free to search the issue tracker yourself to find the discussions that lead to the current state of things.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Override files in parent directory #14299 - eslint/eslint - GitHub
I'm sorry, we don't support parent directories in overrides, and we aren't making any further changes to this config system as we move...
Read more >
Configuration Files - ESLint - Pluggable JavaScript Linter
Here is how overrides work in a configuration file: The patterns are applied against the file path relative to the directory of the...
Read more >
Configuration override system - Drupal
Drupal 8 introduces a configuration override system that: Maintains these overrides as temporary layers on top of the standard configuration ...
Read more >
How to move and overwrite subdirectories (and files) to parent ...
If a directory exists in both the source and the destination, the contents are moved-and-merged recursively. If a file or directory exists in...
Read more >
is it possible to ignore .gitignore rules in subdirectory?
It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn't list excluded directories for...
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