5 nitpretty - pretty print Nit code from Nit source files.
9 nitpretty [*options*]... FILE
14 : Working directory (default is '.nitpretty')
17 : Output name (default is pretty.nit)
20 : Show diff between source and output
23 : Show diff between source and output using meld
26 : Check format of Nit source files
28 This option creates a temporary pretty printed file then checks if the output
29 of the diff command on the source file and the pretty printed one is empty.
32 : Break too long string literals
35 : Force do keyword on the same line as the method signature
38 : Force formatting of empty lines
40 By default empty lines are kept as they were typed in the file.
41 When enabling this option, `nitpretty` will decide where to break lines and
42 will put empty lines to separate properties and code blocks.
46 The specification of the pretty printing is described here.
48 * Default indentation level is one `'\t'` character and is increased by one for
49 each indentation level.
50 * Default line max-size is 80.
54 There is many categories of comments:
56 `Licence comments` are attached to the top of the file no blank line before,
60 # This is a licence comment
62 # Documentation for module `foo`
66 `ADoc` are documentation comments attached to a `AModule`, `AClassdef`, `APropdef`.
68 They are printed before the definition with a blank line before and no after
69 at the same indentation level than the definition.
72 # Documentation for module `foo`
75 # Documentation for class `Bar`
77 # Documentation for method `baz`
82 `Block comments` are comments composed of one or more line rattached to nothing.
83 They are displayed with one blank line before and after at current indent level.
92 `Attached comments` are comments attached to a production.
93 They are printed as this.
96 fun foo do # attached comment
100 `nitpretty` automatically remove multiple blanks between comments:
111 Productions are automatically inlined when possible.
115 * The production must be syntactically inlinable
116 * The inlined production length is less than `PrettyPrinterVisitor::max-size`
117 * The production do not contains any comments
121 * There is a blank between the module declaration and its imports
122 * There is no blank between imports and only one after
123 * There is a blank between each extern block definition
124 * There is a blank between each class definition
125 * There is no blank line at the end of the module
128 # Documentation for module `foo`
135 # Documentation for class `Bar`
138 class Baz end # not a `ADoc` comment
143 * There is no blank between the class definition and its super-classes declarations
144 * There is no blank between two inlined property definition
145 * There is a blank between each block definition
146 * There no blank line at the end of the class definition
149 # Documentation for class `Bar`
164 Generic types have no space after or before brackets and are separated by a comma and a space:
167 class A[E: Type1, F: Type1] end
172 * Inlined productions have no blank lines between them
173 * Block productions have a blank before and after
187 ### CALLS AND BINARY OPS
189 Arguments are always printed separated with a comma and a space:
195 Binary ops are always printed wrapped with spaces:
201 Calls and binary ops can be splitted to fit the `max-size` constraint.
202 Breaking priority is given to arguments declaration after the comma.
205 return foo("aaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb",
206 "cccccccccccccccccccccccccc")
209 Binary ops can also be broken to fit the `max-size` limit:
212 return "aaaaaaaaaaaaaaaaaaaaaaaaaa" + "bbbbbbbbbbbbbbbbbbbbbbbbbbb" +
213 "cccccccccccccccccccccccccc"
218 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>