Search code examples
reactjstypescriptcode-formattinglinter

React Typescript linter that replaces single quotes with double on push to git


Do any of you know a linter for React TypeScript, that replaces single quotes with double quotes on push to git. So next time someone pulls the project down, there is only double quotes.


Solution

  • I have this scenario currently implemented using husky and eslint.

    In the pre-commit file from husky, I have this command

    eslint ./src/. --fix
    

    And in .eslintrc this rule

    "quotes": [
        "error",
        "double",
        {
            "allowTemplateLiterals": true
        }
    ]
    

    Eslint with the --fix flag will try to fix what it cans things like adding semicolons or updating quotes. With the rule I'm saying: I want all quotes to be double quotes but allow me to use template literals.

    This does not affect react props you can still have props like

    When running a commit command, husky will trigger the hook and add double quotes so the commit will have the changes.