0

I have seen some React files that start with:

/**
 * @prettier
 */

What is the intention of this?

Gambit2007
  • 3,260
  • 13
  • 46
  • 86
  • 2
    This sounds like a job for "searching the web". In fact, "@prettier code comment" will guaranteed find you your answer. – Mike 'Pomax' Kamermans Feb 24 '20 at 23:27
  • Well i searched for "prettier file annotation" and couldn't find it.. – Gambit2007 Feb 24 '20 at 23:47
  • Interesting, because I found https://github.com/prettier/prettier/pull/2772 on the first page of results, which is a perfectly find jumping-off point to start reading up on what that comment does. – Mike 'Pomax' Kamermans Feb 25 '20 at 00:09
  • Good for you, I'll try to be as good as you in web searching. – Gambit2007 Feb 25 '20 at 00:22
  • Nice, but also remember that you're asking this not just for you, but also for future users who find this question, and my comment was as much for them as it is for you. Yes, there are accepted answers, but that doesn't make it any less important to uphold the ["search, and research, before posting"](/help/how-to-ask) policy that we're all expected to follow. (If you did, and you couldn't find it, by all means put that in your post in the future because that means no one will tell you search for it, but in the absence of that information: search first) – Mike 'Pomax' Kamermans Feb 25 '20 at 00:24

2 Answers2

1

The term is called a pragma

Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file. This is very useful when gradually transitioning large, unformatted codebases to prettier.

Harmenx
  • 938
  • 1
  • 5
  • 13
1

Require pragma

Prettier can restrict itself to only format files that contain a special comment, called a pragma, at the top of the file. This is very useful when gradually transitioning large, unformatted codebases to prettier.

For example, a file with the following as its first comment will be formatted when --require-pragma is supplied:

/**
 * @prettier
 */

or

/**
 * @format
 */

API Override:

requirePragma: <bool>
Andrii Gordiichuk
  • 1,783
  • 1
  • 12
  • 10