1

I use pre-commit, I want to use it together with .py files, I reformat file black module, but I also have a web folder where the react files are, I have 2 questions at once, what is relevant for reformatting the code for js and how can I unite so that when the pre-commit run is started, the web folder is checked for reformatting the js code

UPDATE: the question that worried me the most is the js and py file conflict, but I used:

  - repo: https://github.com/prettier/prettier
    rev: 2.1.2
    hooks:
      - id: prettier
anthony sottile
  • 61,815
  • 15
  • 148
  • 207
big-vl
  • 134
  • 1
  • 7

2 Answers2

3

though pre-commit is written in python, it has support for many different programming languages including javascript

there's a whole list of supported tools in the pre-commit documentation -- the most popular probably being eslint or prettier (though, tool suggestion is generally off-topic on stack overflow since it's highly opinion based)


disclaimer: I'm the author of pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • 1
    the question that worried me the most is the js and py file conflict, but I used ``` - repo: https://github.com/prettier/prettier rev: 2.1.2 hooks: - id: prettier``` – big-vl Sep 24 '20 at 02:31
  • 1
    ah, you can tell prettier to not run against python with `exclude` / `exclude_types` – anthony sottile Sep 24 '20 at 02:37
1

This is my config file for formatting React.js/React.ts using Prettier and pre-commit , if anyone is interested. I have it set to single-quotes, but you can mess with the arguments as you desire. Shoutouts to my brother for creating this amazing tool!

repos:
  - repo: https://github.com/prettier/prettier
    rev: 2.1.1
    hooks:
      - id: prettier
        args: [--single-quote=true]