简体   繁体   中英

How can I know that a JS or HTML or CSS file is well formatted via bash?

I know I can open a code editor and see the file and realize if it's formatted or not. But I want to create a script that does that. I want to search through a directory and find all of the files that are not formatted.

I know the formatting of each file differs. For example, to format Python you need a different set of rules and to format a JS or a C# file different rules apply.

However, since code editors do it behind the scene using some extensions or code-parser engines, I think there might be tools for shell too.

Can I do it? Can I install some dependencies and then search through code files in a directory and report the list of files that are not code-formatted?

You can add Prettier to your project, then run command to check unformatted files:

npx prettier --check.

To format your code, run:

npx prettier --write.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM