https://github.com/levelrin/dart-stylerin
An alternative Dart code formatter
https://github.com/levelrin/dart-stylerin
dart formatter
Last synced: 5 months ago
JSON representation
An alternative Dart code formatter
- Host: GitHub
- URL: https://github.com/levelrin/dart-stylerin
- Owner: levelrin
- License: mit
- Created: 2019-11-22T15:50:56.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2025-06-14T12:06:15.000Z (about 1 year ago)
- Last Synced: 2025-06-14T13:19:53.660Z (about 1 year ago)
- Topics: dart, formatter
- Language: Java
- Homepage:
- Size: 347 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/levelrin/dart-stylerin/actions/workflows/build.yml?query=branch%3Amain)
[](https://codecov.io/gh/levelrin/dart-stylerin)
[](https://github.com/levelrin/dart-stylerin)
[](https://github.com/levelrin/dart-stylerin/blob/main/LICENSE)
## About
It's a code formatter for [Dart](https://dart.dev/).
Yes, we have [the official formatter](https://dart.dev/tools/dart-format) already, but it's not good enough.
For example, we have the following code:
```dart
void main(){
final RussianDoll doll=RussianDoll('Rin',RussianDoll('Revomin',RussianDoll('Ian',RussianDoll('Rajitha'))));
doll.unwrap();
}
class RussianDoll{
final String _name;
final RussianDoll? _child;
const RussianDoll(this._name,[this._child]);
RussianDoll? child(){return this._child;}
void unwrap(){print(this._name);if(this._child!=null){this._child.unwrap();}}
}
```
The official formatter formats the code like this:
```dart
void main() {
final RussianDoll doll = RussianDoll('Rin',
RussianDoll('Revomin', RussianDoll('Ian', RussianDoll('Rajitha'))));
doll.unwrap();
}
```
Our formatter formats the code like this:
```dart
void main() {
final RussianDoll doll = RussianDoll(
'Rin',
RussianDoll(
'Revomin',
RussianDoll(
'Ian',
RussianDoll('Rajitha')
)
)
);
doll.unwrap();
}
```
Our format shows the composition better.
## Quick Start
Please install Java 11+ if you haven't already.
1. [Download](https://github.com/levelrin/dart-stylerin/releases) the zip file that matches with your Java version and unzip it to get the jar file.
2. Run the command `java -jar dart-stylerin-{app-version}-{java-version}.jar path/to/target.dart`
## Command Options
```
usage: java -jar dart-stylerin-{app-version}-{java-version}.jar [options]
-h,--help Show help messages.
-q,--quiet Do not print debug logs.
-r,--recursive Format files in the directory recursively.
-v,--version Print the version.
```
## Disclaimer
Not all [grammar rules](https://github.com/antlr/grammars-v4/blob/master/dart2/Dart2Parser.g4) are supported yet.
Please always be ready to recover the file and use our formatter at your own risk.
If you find a bug or have a suggestion, please create a new [issue](https://github.com/levelrin/dart-stylerin/issues).