p-hatan/ mirror

pub repository

mirror.p-hatan.ir

dart_style

0.1.5+1

Opinionated, automatic Dart source code formatter.

Download archive

Readme

The dart_style package defines an automatic, opinionated formatter for Dart code. It replaces the whitespace in your program with what it deems to be the best formatting for it. Resulting code should following the Dart style guide but, moreso, should look nice to most human readers, most of the time.

It handles indentation, inline whitespace and (by far the most difficult), intelligent line wrapping. It has no problems with nested collections, function expressions, long argument lists, or otherwise tricky code.

Running it

The package exposes a simple command-line wrapper around the core formatting library. The easiest way to invoke it is to globally activate the package and let pub put its executable on your path:

$ pub global activate dart_style
$ dartfmt ...

If you don't want dartformat on your path, you can run it explicitly:

$ pub global activate dart_style --no-executables
$ pub global run dart_style:format ...

The formatter takes a list of paths, which can point to directories or files. If the path is a directory, it processes every .dart file in that directory or any of its subdirectories.

By default, it formats each file and just prints the resulting code to stdout. If you pass -w, it will instead overwrite your existing files with the formatted results.

You may pass a --line-length option to control the width of the page that it wraps lines to fit within, but you're strongly encouraged to keep the default line length of 80 columns.

Validating files

If you want to use the formatter in something like a presubmit script or commit hook, you can use the --dry-run option. If you pass that, the formatter prints the paths of the files whose contents would change if the formatter were run normally. If it prints no output, then everything is already correctly formatted.

Using it programmatically

The package also exposes a single dart_style library containing a programmatic API for formatting code. Simple usage looks like this:

import 'package:dart_style/dart_style.dart';

main() {
  var formatter = new DartFormatter();

  try {
    print(formatter.format("""
    library an_entire_compilation_unit;

    class SomeClass {}
    """));

    print(formatter.formatStatement("aSingle(statement);"));
  } on FormatterException catch (ex) {
    print(ex);
  }
}

Stability

You can rely on the formatter to not break your code or change its semantics. If it does do so, this is a critical bug and we'll fix it quickly.

The rules the formatter uses to determine the "best" way to split a line may change over time. We don't promise that code produced by the formatter today will be identical to the same code run through a later version of the formatter. We do hope that you'll like the output of the later version more.

Changelog

0.1.5+1

  • Fix test file to work in main Dart repo test runner.

0.1.5

  • Change executable name from dartformat to dartfmt.

0.1.4

  • Don't mangle comma after function-typed initializing formal (#156).
  • Add --dry-run option to show files that need formatting (#67).
  • Try to avoid splitting in before index argument (#158, #160).
  • Support await for statements (#154).
  • Don't delete commas between enum values with doc comments (#171).
  • Put a space between nested unary - calls (#170).
  • Allow -t flag to preserve compability with old formatter (#166).
  • Support --machine flag for machine-readable output (#164).
  • If no paths are provided, read source from stdin (#165).

0.1.3

  • Split different operators with the same precedence equally (#130).
  • No spaces for empty for loop clauses (#132).
  • Don't touch files whose contents did not change (#127).
  • Skip formatting files in hidden directories (#125).
  • Don't include trailing whitespace when preserving selection (#124).
  • Force constructor initialization lists to their own line if the parameter list is split across multiple lines (#151).
  • Allow splitting in index operator calls (#140).
  • Handle sync* and async* syntax (#151).
  • Indent the parameter list more if the body is a wrapped "=>" (#144).

0.1.2

  • Move split conditional operators to the beginning of the next line.

0.1.1

  • Support formatting enums (#120).
  • Handle Windows line endings in multiline strings (#126).
  • Increase nesting for conditional operators (#122).

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add dart_style
pubspec.yaml
name: dart_style
version: 0.1.5+1
author: Dart Team <misc@dartlang.org>
description: Opinionated, automatic Dart source code formatter.
homepage: https://github.com/dart-lang/dart_style
dependencies:
  analyzer: '>=0.23.0 <0.24.0'
  args: '>=0.12.1 <0.13.0'
  path: '>=1.0.0 <2.0.0'
  source_span: '>=1.0.0 <2.0.0'
dev_dependencies:
  browser: '>=0.10.0 <0.11.0'
  scheduled_test: '>=0.11.2 <0.12.0'
  unittest: '>=0.11.0 <0.12.0'
executables:
  dartfmt: format
  dartformat: format # Allow the old name for compatibility.

# Tell the bots not to bother building the tests since they don't run in a
# browser anyway.
transformers:
- $dart2js:
    $exclude: 'test/**'

Version history

VersionPublishedArchiveSHA-256
0.1.02015-01-08T17:27:59.164130ZDownload9e778e28e1d853606fe4ffa24be6a9b26eeba5177220f0568b9ae84ead6d272b
0.1.12015-01-09T19:24:02.530820ZDownload5751240a67c6b45b3a23d1b8c650113c95bf81ff8ddc7eab7a27e9664a80ded4
0.1.22015-01-12T22:48:41.064670ZDownloadd74c289961754b0feb1dc6a047c320e339d7c6af31e519fab22b9497b3136a29
0.1.32015-02-02T17:15:53.279150ZDownload9396f0e6c620f131c26af3f18c002bceb67ad4e0ced311a67739e8cda3f7cba1
0.1.42015-02-20T19:29:22.690880ZDownload346f72af495b1831ad70e040d2eacd2658ab308451809367f542e2bd3e9f95de
0.1.52015-02-20T21:47:18.459960ZDownload4a09017d0c034488dd26515de7b510d6d0810b6763cd3d0bbb8e187399e3497d
0.1.5+12015-02-26T21:18:14.699780ZDownload570f057832438e4026618fd49b543a1fa1ec4864cb30744b7279608a7955e520
0.1.5+22015-02-26T23:55:40.752050ZDownload1b3e085368fb217ba22fe3394f69db6025d5e4654c7d1f1b2d2d5b3f977fd968
0.1.5+32015-02-27T01:45:36.902670ZDownloadf95f8bbe8250a4335f849f1272e43f18d692fc4fd9a24884ca28c62b7b82df57
0.1.62015-03-03T17:23:18.397170ZDownloadb0dce2310341119b4c0a7b01b9498849d74a054ca5192540687b0e49732b679a
0.1.72015-03-11T21:14:10.590520ZDownload3178883efd9b2e23dca9a53a71372d3eabe600300a1ed5d890fa12ccc2dc14cb
0.1.82015-04-23T20:18:51.981160ZDownload4c209c076ebe13fdaeb418c107caaf5611086a8be9d586ecc85f161c5595b8d2
0.1.8+12015-06-30T22:56:40.652ZDownloadafa425160167e4d603788bb6cc72d865d63623193f72e8a8b4adbfec17fcd45a
0.1.8+22015-07-22T01:10:36.234ZDownload02dbc99b8b1c6b2c2d0338d3361d3e8da4af2c63a961abf81e3d4755e007daf6
0.2.0-rc.12015-06-19T20:18:38.485ZDownload4a3d858ea77fce4e1939d1e4d3573431f99353bc683e932d6a0a79fcc03106ff
0.2.0-rc.22015-07-24T20:21:26.350ZDownload75872d86d74cabed26823d10fc6082de46224ec2896918cd8a07a6dd40be184c
0.2.0-rc.32015-07-28T00:00:44.149ZDownloadca918e090a54012bcdc66f3bd8a976d82332e8e449657084de1c11b2b047aa64
0.2.0-rc.42015-07-30T16:20:06.085ZDownloaddd6d404bac7c6c6b144e887304563920b355217e90a1b5e784ca86fe58fba8ef
0.2.02015-07-30T21:26:06.172ZDownload23622edbddc05fc28cd6e7af519806bc92c81f9754052ee30bf22c8b100f96c9
0.2.12015-12-07T22:51:21.293ZDownload6a4dd214f4f15b271a52b779a2c3d4c2675e43e09c1b2551b61cae6248f0474e
0.2.22015-12-09T01:06:59.599ZDownloadece931b7f256b683fdf68fe8cf2262701fa2c67300caf451e125e00164cbf7c4
0.2.32016-01-15T01:28:13.266ZDownloadaf19927d18158b30f5ac75424529118dc1b26da8f8edbca3ad72967df725f758
0.2.42016-01-16T00:51:37.913ZDownload4a99662720dea551d5a4cad20506df3024281aa3fdbec7d7a3cdc7a56b78877f
0.2.72016-07-29T00:51:32.060ZDownload4421866d42f23db20e95020dd52937246330c8ed259442aec4ee200ca6440e68
0.2.82016-07-29T22:19:15.784ZDownload1efec90bfd94fe35d12a1779bf7dd5b873b2e1809dab35760e144f0c5e3f945a
0.2.92016-08-01T22:06:04.086ZDownloadd47ba521ef7c698b9bceca4050c5ba99e3fae9ae16d59ce2368cfaf94ca9973f
0.2.9+12016-08-16T22:12:44.527ZDownload2dfa66b21b7650db1089462a4de0d37a02ccaed2ef17f176e61ca37b7f4dcdbd
0.2.102016-09-14T23:44:59.689ZDownload46ccd080fbdc3cfba0190b5ee9a961345a6ebf60403439a089a369503b74f76f
0.2.112016-10-07T00:28:01.622ZDownload7dcc3061ba8a2bb9b9aecb1b1fa6a2930e2735bfe26fed0401ad0ae8f100e8c7
0.2.11+12016-10-19T21:35:19.853ZDownloadd97672bb7211a491b905f275332f773ea3e380bdd6d8571dd0e5e1d4b54d275a
0.2.122016-11-29T22:01:20.375ZDownload016232c2a20be004d7e5b51fe90f4dde7106251db35978c9bf09bd30a2f36235
0.2.132016-11-29T23:43:03.518ZDownloada66525b6741b694889ec2803b5be0c22a7c74c2c4c926d352ba7612df35ddb90
0.2.142017-01-11T18:16:51.802ZDownload3a422f54cedd82ba6dbc60f658a2111ef0b584fee5dd960d36852cc7a464c6e2
0.2.152017-01-23T21:47:43.321ZDownload0d91471ca71fd1b8fe7a73f22ba16578ba384d24171dc89ded4c0995fb978639
0.2.162017-02-03T22:17:39.477ZDownload9fd6feba26e544df0b7217fb8b8bcef65904ea60460162a2d04adf775ff8d73e
1.0.02017-03-21T23:36:57.852158ZDownload9c82b9bfe7f0224ac276bc1696d73c15bab8dbeea7f2fdb31ba03a41f90467d1
1.0.12017-03-24T23:51:42.320482ZDownload187bcdf906bddb5d7401201171b93b4c8d3e7df66e0081ba5f6e7dcfe31f7a81
1.0.2-dev2017-03-29T21:42:08.487482ZDownloada0e468993fea149f3200d7d034e8fd6679c3e482e17aee15514613724df21d5d
1.0.32017-04-06T20:15:19.799825ZDownloada7cd12db7c857c5b74a805a6c4cfa0309dac8d3e285f0700d092f0ed31b0d851
1.0.42017-04-26T20:31:02.246047ZDownload5bfdbbaf7e2069caf2bdf99a1f6c4e75ebf89d0bd4fe8aa7e74ae7a5191f902b
1.0.52017-05-04T17:49:39.376426ZDownloade9e394018a75e68187fda2e4581e44795c765254cc5f46cc65b92565ace93e68
1.0.62017-05-10T00:29:47.122234ZDownloadd51eddcdae5b22cb85367ae1684bedfe2e82660900428733188ba7ef24abbe1f
1.0.72017-07-06T00:12:54.596430ZDownload55545ec86f16964bd0c872fca5ec3f9665773d48bf70c6c9eaaf9ee7b81f09fd
1.0.82017-09-21T21:40:47.303222ZDownload5c0fee3ee7e202e299ed6949cdc1f81f189258b590ee5f8b5ac04181d52d82a8
1.0.92018-01-04T20:08:15.192190ZDownload1f573055d96724d64722c03bd6ede4647a2f71ebd78787cb95c333ef22bb8f35
1.0.9+12018-02-02T22:58:51.186666ZDownload4f118d470b4852af8ca783b6f2e58a88e8b4c1dee2450fc10c532cb27938f599
1.0.102018-02-22T01:44:45.304811ZDownload450f321135fa26f917a792e1d48f3ca5be11084e66aaf4fc5960b0a7fc8d5fc6
1.0.112018-04-24T20:54:45.055458ZDownloadba545ef3bda1b09cbd137bfb2263cdc3578bcb87170b9352daa50685dfe79f5a
1.0.122018-04-30T17:13:09.759497ZDownloadd9e2271fbcda8fa1ac7058e3d0ba54429f884e5c26de28147a484bcba02e6f54
1.0.132018-05-14T20:52:44.062453ZDownload3cfb5d13eebdabe8987b7ba18b0e4cb581eae580d636dc4f3341c9c30eebb1b2
1.0.142018-05-15T17:41:51.765323ZDownload4547b9418d14086a2d7327eec8448b058accfd64cb542171b8f904b3aa8b4ece
1.1.02018-06-18T23:00:58.661855ZDownload3b32eb5027792aa2fe689e3f46d1aa51c7a1e920b5e72eb2b9f14be9a017c3c8
1.1.12018-06-27T20:57:39.333368ZDownload7a0d433774c8c511b3a5a9b4c663cf0f28ee182cadcd44d559a69a6ce6c7d3b1
1.1.22018-07-06T21:00:06.671858ZDownload8c3666f7d1c3aa83a7be55847b4dedd833ad9a33a2cd6fb0abe58e013a4f7488
1.1.32018-07-17T01:46:41.777669ZDownloadfefc47d50c5d6e2d037ca9a68e64edc076b54b69aea5c2ecf2a5272adf974027
1.2.02018-09-18T21:42:50.625637ZDownloada1d9fd4ab9efd72ac7c4b58e5b933b554dfa2a725b42b369070a58d1f1946294
1.2.12018-12-03T19:16:20.275052ZDownload596cf287a1b60928257ac054457a0fdf6ade46a6a915092932aa111f6b06d90d
1.2.22018-12-07T17:13:48.369919ZDownloadd62fe00fba3e5957786583edff6f941bade5f977b3fb178966d583738d0e5087
1.2.32019-01-30T20:47:50.805234ZDownload452c5e58bca914c4ac9f0b3e99a2b615224f1dd333360269260396a6ad5180e9
1.2.42019-03-13T17:51:04.156580ZDownload63f99f22681860f58033bd5d1735d02929f17b023f9b85284c808eb81272ee63
1.2.52019-03-27T23:16:29.313683ZDownload3d22afc620adbb7ccb352845dd09b119bccdf4d94a787091993c291653e5c028
1.2.62019-04-05T00:44:58.151119ZDownload566c52aef51ce006c7d2bf430779717286c1c576870ae31d242888c43d3dd74b
1.2.72019-04-05T22:50:48.150146ZDownload26e0d83ae5ece44b9c3c7a0fa643f99b992d46e12a1ea56e32121dea68fee34c
1.2.82019-06-06T23:20:06.649512ZDownload1d675546f9cb9938f4d657435b67b1dfc0b751dcd66053e4b16e33ecd3ca42b0
1.2.92019-07-08T21:01:00.033230ZDownloadfc7e07bac454cca1236fe52ac3fb36e83347d3c7f24c3d1197356d8b9bc5fdd3
1.2.102019-08-19T20:36:06.472085ZDownload5b184ae32341245b8c07d47fa3b80d6eebfd9204d9316fbc247031cd923f8458
1.3.02019-09-25T19:46:15.187190ZDownloadeb5e977e1df401ef9e886406d520ee9ac1ebb2a04fa46ad4ec0ef6c6dad5227b
1.3.12019-09-26T20:17:56.453637ZDownloadb2dc0f3593dc2586a914fb936e5a292ec61941883f4c1cfbc6ba21b783850013
1.3.22019-10-21T18:00:20.510889ZDownload9e534504ca0d6f4da2a273506a02fc974acab5c2540414b60d3a760e8c0b361b
1.3.32019-10-29T00:58:41.457008ZDownloadc3773323a468c58d96e0134dbaa485b5e61286fb87d41104a756f6fa2a08dc9c
1.3.42020-04-06T18:13:57.904146ZDownloada7762bd5e3ea500b292dc7c6f4e44c16cc81f683167344b666056de17e6cc067
1.3.52020-04-23T00:43:21.243857ZDownloadb83168dd2a3bf98140c11a63480f4494788a59f74c6e5797c3a202e2691f78bf
1.3.62020-04-23T20:53:12.012292ZDownload26ac7f85fd26fbe5eb20393c75440100eea1bc27cbd394be6578b2a544fba71f
1.3.72020-08-28T22:52:05.342747ZDownload2a2cef5d6b06e3ef6e46945a733597c410f6f5f864b60ba054c77f8070a36d20
1.3.82020-10-20T17:53:45.892463ZDownload469f0ba747c9daa46ac8b3f4f28627bfafb4e70d411e8fa5c6e388b32eca059b
1.3.8+12020-10-29T17:46:52.291148ZDownloaddf63b1204202de43633683c2d3db5699c1ce072df3c3d54a2a1b1a3ab51232b1
1.3.92020-11-02T19:31:57.873131ZDownload04dd4735877eb3b896e19f895e54b522e2cc2a8b94d71a14774a82e7e2267604
1.3.102020-11-19T22:13:57.995021ZDownload918f91b8bdd1ac67b0f638ce7998eae04cb9d5c703f60f97fb639aecbf2212ba
1.3.112021-01-13T21:53:15.354408ZDownload278086e3195b7d1ec7b070e97be44dbb93672af4bc832e055b8ff835bd1acf83
1.3.122021-02-09T00:05:35.248382ZDownloadd54208b00d826e28e7c94be1a7e06312c3f58587424ad00616569ab09106c5a0
1.3.132021-02-12T21:18:41.441515ZDownload2cd619951f0e03f6b59d96b60d44c39d1bcfc3857056f3bbb1979c57f7e03dd5
1.3.142021-02-25T18:55:55.384669ZDownloadb2b9f171f9a6b548b0374b179945ceb62e203825ba054a0f904acd70452d511e
2.0.02021-03-16T20:13:25.004633ZDownloadc5f052c761255e20595466bfcc7a332149c09e940e11238b4287e3ebdebf7d4c
2.0.12021-04-26T22:10:46.399813ZDownload54f467ce920cfa4c3b6456900824ef018def893f9435d0a7380c96d05bcc6b64
2.0.22021-07-12T23:12:36.129508ZDownload43123ab6841eafaa2776a6da688315a2c2f233f501c3cc629aadd144235dd3b2
2.0.32021-07-22T17:51:36.811336ZDownload4e65f1921774e1126bd4d7cbc8f866b5fc166346b87d42d0c4ca2b874b153b56
2.1.02021-09-09T00:03:08.179611ZDownload4237f3f70a6b544cb31c9e90488ea7e61e1e50d72fe83ec34e8b2833698f7201
2.1.12021-09-22T00:08:04.242021ZDownload7f5b48e6a448c4b46250a6113857a00eaa82821ef5a3d7f42e68eb69d1283fa3
2.2.02021-09-22T00:10:15.389692ZDownload2cac5b2dfcd79df1b57c117934d2d04e03f0420c0c6ea7bbf02836fcd34e131f
2.2.12021-12-16T22:01:37.977554ZDownload6e8086e1d3c2f6bc15056ee248c4ddc48c2bc71287c0961bf801a08633ed4333
2.2.22022-03-03T23:56:12.544817ZDownload959d3de27b5e0713f954643ee38619551da06e61e08088968fe7e1eb0cd720b1
2.2.32022-04-14T20:21:10.293364ZDownload8aff82f9b26fd868992e5430335a9d773bfef01e1d852d7ba71bf4c5d9349351
2.2.42022-09-12T23:00:49.495039ZDownload7a03456c3490394c8e7665890333e91ae8a49be43542b616e414449ac358acd4
2.2.5-dev2023-03-02T21:33:12.577694ZDownload801b8686435899fd48cf460eee3a79814e3023f5f350e2c056532ec2908823dd
2.2.52023-03-02T21:35:56.774218ZDownload5be16bf1707658e4c03078d4a9b90208ded217fb02c163e207d334082412f2fb
2.3.02023-03-13T20:55:50.237830ZDownload6d691edde054969f0e0f26abb1b30834b5138b963793e56f69d3a9a4435e6352
2.3.12023-05-03T22:22:03.384537ZDownloadf4f1f73ab3fd2afcbcca165ee601fe980d966af6a21b5970c6c9376955c528ad
2.3.22023-06-29T16:27:56.651772ZDownload1efa911ca7086affd35f463ca2fc1799584fb6aa89883cf0af8e3664d6a02d55
2.3.32023-09-14T22:00:25.569238ZDownloadabd7625e16f51f554ea244d090292945ec4d4be7bfbaf2ec8cccea568919d334
2.3.42023-11-21T19:26:02.698474ZDownload40ae61a5d43feea6d24bd22c0537a6629db858963b99b4bc1c3db80676f32368
2.3.52024-02-29T00:52:38.032510ZDownload25b4624c231844a7a70a3817a729a6190a751ef1c07ded256e126a3b72261444
2.3.62024-02-29T19:01:29.380531ZDownload99e066ce75c89d6b29903d788a7bb9369cf754f7b24bf70bf4b6d6d6b26853b9
2.3.72024-09-10T00:50:47.370222ZDownload7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab
2.3.82025-01-27T23:52:25.824902ZDownload7306ab8a2359a48d22310ad823521d723acfed60ee1f7e37388e8986853b6820
3.0.02024-12-03T00:41:13.188808ZDownload64b717484993e85315d0c04081b6fca9ef8bac8c2cb794b2e15810250b335913
3.0.12024-12-20T21:36:06.773444ZDownload27eb0ae77836989a3bc541ce55595e8ceee0992807f14511552a898ddd0d88ac
3.1.02025-05-20T17:48:06.301782ZDownload5b236382b47ee411741447c1f1e111459c941ea1b3f2b540dde54c210a3662af
3.1.12025-07-18T17:30:17.067626ZDownload8a0e5fba27e8ee025d2ffb4ee820b4e6e2cf5e4246a6b1a477eb66866947e0bb
3.1.22025-08-07T21:41:13.565344ZDownloadc87dfe3d56f183ffe9106a18aebc6db431fc7c98c31a54b952a77f3d54a85697
3.1.32025-11-13T21:41:29.454449ZDownloada9c30492da18ff84efe2422ba2d319a89942d93e58eb0b73d32abe822ef54b7b
3.1.42026-01-14T17:55:22.526268ZDownload8a0aa2b9bae196552b71575efc94580e447546c26c7120577bb6f81fbd33b52e
3.1.52026-01-29T01:42:35.438753ZDownload15a7db352c8fc6a4d2bc475ba901c25b39fe7157541da4c16eacce6f8be83e49
3.1.62026-02-26T01:25:23.138437ZDownload6f6b30cba0301e7b38f32bdc9a6bdae6f5921a55f0a1eb9450e1e6515645dbb2
3.1.72026-03-07T01:43:31.373694ZDownload29f7ecc274a86d32920b1d9cfc7502fa87220da41ec60b55f329559d5732e2b2
3.1.82026-03-19T05:08:06.424128ZDownloada4c1ccfee44c7e75ed80484071a5c142a385345e658fd8bd7c4b5c97e7198f98
3.1.92026-04-29T15:58:10.284447ZDownload59d53ef8eaed9d288ed9767618e2b31c4fa0383a127db59d5eb2e737a7638a60
3.1.102026-07-08T18:31:53.004354ZDownload0ed2b79a33d65b89bdc548cf81d0bf4bb1fb3615937ac48b54e9daef9575f1fb
3.1.112026-07-09T17:45:13.879671ZDownloadb60b8cb28aa514346eb8f6b005c60484ea65190f213b1986f6e391e0292d18f4
3.1.122026-07-10T20:04:31.115699ZDownload3f88fc9c96c568d631356507355a2d1e983ee000c9ac008bdcb39b5bf53ce777
3.1.132026-08-26T18:47:59.106940ZDownload82ade9fc4273f29ed673e33166944465225b4f7fc5d4aaef48605cc751c18fc1
3.1.142026-10-15T20:49:29.064773ZDownloada0e4f65339b31eb6a9e6a12e14b4682a48d46fbc54a82f4a702396fbdbac63a7

Dependencies

analyzer "\u003e=0.23.0 \u003c0.24.0"

args "\u003e=0.12.1 \u003c0.13.0"

path "\u003e=1.0.0 \u003c2.0.0"

source_span "\u003e=1.0.0 \u003c2.0.0"