0

I have a project where I have tests and src of my code. I wish to use different prettier configs for tests and application sources, so VSC would do the formatting according to the folder i'm in. Is this possible ?

Currently it's doesn't work for me, so maybe I'm doing something wrong.

I have separate .prettierrc in my main folder and in my tests folder e.g

root/
 --tests/
 ----.prettierrc <-- one for tests
 --.prettierrc <-- one for the rest
DarkBee
  • 16,592
  • 6
  • 46
  • 58

1 Answers1

0

This is Configuration Overrides.

Example:

Root/
├── tests/
│   └── test.js
├── src/
│   └── app.js
├── index.js
└── .prettierrc
// .prettierrc
{
  "tabWidth": 2,
  "overrides": [
    {
      "files": ["src/**/*.js"],
      "options": {
        "singleQuote": true,
        "tabWidth": 8
      }
    },
    {
      "files": "tests/*.js",
      "options": {
        "singleQuote": false,
        "tabWidth": 16
      }
    }
  ]
}

Result:

// index.js:
if (true) {
  console.log("Hello");
}

// app.js
if (true) {
        console.log('Hello');
}


// test.js:
if (true) {
                console.log("Hello");
}
sha'an
  • 1,032
  • 1
  • 11
  • 24