javascriptformattingeslintprettiercodesandbox

How to configure ESLint / Prettier formatting rules on "codesandbox.io"


On codesandbox.io, how can I configure Prettier so that it doesn't change the line breaks?

Also, how can I deactivate specific ESLint rules. For example, I would like to turn off the react-hooks/rules-of-hooks rule. A newly created eslintrc file seems to be ignored in my ES201x project.


Solution

  • You can easily configure the formatting behaviour of your Sandbox by adding the prettier config file in the following way:

    1. Create the file .prettierrc in the root folder of the Sandbox.
    2. Using the JSON syntax add the formatting rules you want to the file.

    For example to change the the line wrapping which I guess annoys most of the people, set the printWidth value:

    {
      "trailingComma": "es5",
      "tabWidth": 2,
      "semi": false,
      "singleQuote": true,
      "printWidth": 25
    }
    
    
    1. Save the file and reload the Sandobox page.

    2. Next time you save any of the files the code will be formatted following the rules you had set in the .prettierrc.

    Other:

    Enjoy!

    enter image description here