Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable prettier for a single file

Tags:

I need to disable prettier for a single file (API URLs file) in my project in Vs-code. actually, I need each API and its URL to be in one line, but prettier breaks them in two lines.

before

export const GET_SEARCH_TEACHERS = params => myexampleFunction_app_base(`teachers/search/${params.search}`); 

after

export const GET_SEARCH_TEACHERS = params => myexampleFunction_app_base(`teachers/search/${params.search}`); 
like image 597
Hamid Shoja Avatar asked Jan 23 '20 10:01

Hamid Shoja


People also ask

How do I disable prettier on a specific file?

To disable Prettier checks for a single file, we can add the path of the file we want Prettier to ignore into the . prettierignore file. We follow the . gitignore file syntax to add it.

How do I disable prettier in VSCode for a specific project?

prettier-vscode", If you want to disable Prettier for a specific language, you can set the editor. defaultFormatter to null .

How do I disable prettier in HTML?

format. enable will turn off the default VS Code formatter. To exclude all html files in a project from being formatted you can add a . prettierignore file to the project root and ignore all html files.

Does prettier ignore Node_modules?

Prettier's CLI ignores node_modules by default.


2 Answers

If you want a certain file in a repo to never be formatted by prettier, you can add it to a .prettierignore file: Disable Prettier for one file

From the docs:

To exclude files from formatting, create a .prettierignore file in the root of your project. .prettierignore uses gitignore syntax.

Example:

# Ignore artifacts:  build  coverage  # Ignore all HTML files: *.html  
like image 79
Zunaib Imtiaz Avatar answered Sep 28 '22 01:09

Zunaib Imtiaz


Thanks to evolutionxbox, so far couple of solutions were found.

Ignoring Files or Folders

To exclude files from formatting, add entries to a .prettierignore file in the project root or set the --ignore-path CLI option. .prettierignore uses gitignore syntax.

/app/src/scripts/example.js /app/src/folder/ 

Ignore based on extension

To exclude files based on extesntion you can add entries to a .prettierignore file as well

*.html.erb 

Ignore lines

JavaScript

A JavaScript comment of // prettier-ignore will exclude the next node in the abstract syntax tree from formatting.

    matrix(       1, 0, 0,       0, 1, 0,       0, 0, 1     )      // prettier-ignore     matrix(       1, 0, 0,       0, 1, 0,       0, 0, 1     ) 

will be transformed to:

    matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);      // prettier-ignore     matrix(       1, 0, 0,       0, 1, 0,       0, 0, 1     ) 

JSX

    <div>       {/* prettier-ignore */}       <span     ugly  format=''   />     </div> 

more: https://prettier.io/docs/en/ignore.html

Using an extension

We can use an extension to toggle formatting like prettier on the specific page when you need it.

Formatting Toggle https://marketplace.visualstudio.com/items?itemName=tombonnike.vscode-status-bar-format-toggle

like image 35
Hamid Shoja Avatar answered Sep 28 '22 02:09

Hamid Shoja