Linux command
scalafmt 命令
文件
复制后可按需替换文件名、目录或参数。
常用示例
Format files
scalafmt [file.scala]
Format in place
scalafmt -i [file.scala]
Check formatting
scalafmt --check [file.scala]
Format directory
scalafmt [src/]
Use config file
scalafmt -c [.scalafmt.conf] [file.scala]
Show diff
scalafmt --diff [file.scala]
Format stdin
cat [file.scala] | scalafmt --stdin
说明
scalafmt is an opinionated code formatter for Scala that enforces consistent style across projects. It reformats source code according to configurable rules covering line length, indentation, alignment, and import ordering, supporting both Scala 2 and Scala 3 syntax through dialect configuration. The --check mode verifies formatting without modifying files, returning a non-zero exit code when changes would be made, which is useful for CI pipeline enforcement. The -i (in-place) mode directly modifies files during development. Configuration is defined in a .scalafmt.conf file at the project root using HOCON format.
参数
- -i, --inplace
- Modify files in place.
- --check
- Check only, no changes.
- -c, --config _FILE_
- Config file.
- --diff
- Show changes.
- --stdin
- Read from stdin.
- --stdout
- Write to stdout.
- --exclude _PATTERN_
- Exclude files.
- --help
- Show help.
FAQ
What is the scalafmt command used for?
scalafmt is an opinionated code formatter for Scala that enforces consistent style across projects. It reformats source code according to configurable rules covering line length, indentation, alignment, and import ordering, supporting both Scala 2 and Scala 3 syntax through dialect configuration. The --check mode verifies formatting without modifying files, returning a non-zero exit code when changes would be made, which is useful for CI pipeline enforcement. The -i (in-place) mode directly modifies files during development. Configuration is defined in a .scalafmt.conf file at the project root using HOCON format.
How do I run a basic scalafmt example?
Run `scalafmt [file.scala]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -i, --inplace do in scalafmt?
Modify files in place.