3 nitpretty - pretty print Nit code from Nit source files.
7 nitpretty [*options*]... FILE
12 Working directory (default is '.nitpretty')
15 Output name (default is pretty.nit)
18 Show diff between source and output
21 Show diff between source and output using meld
24 Check format of Nit source files
26 This option creates a temporary pretty printed file then checks if the output
27 of the diff command on the source file and the pretty printed one is empty.
30 Break too long string literals
33 Force do keyword on the same line as the method signature
36 Force formatting of empty lines
38 By default empty lines are kept as they were typed in the file.
39 When enabling this option, `nitpretty` will decide where to break lines and
40 will put empty lines to separate properties and code blocks.
44 The specification of the pretty printing is described here.
46 * Default indentation level is one `'\t'` character and is increased by one for
47 each indentation level.
48 * Default line max-size is 80.
52 There is many categories of comments:
54 `Licence comments` are attached to the top of the file no blank line before,
58 # This is a licence comment
60 # Documentation for module `foo`
64 `ADoc` are documentation comments attached to a `AModule`, `AClassdef`, `APropdef`.
66 They are printed before the definition with a blank line before and no after
67 at the same indentation level than the definition.
70 # Documentation for module `foo`
73 # Documentation for class `Bar`
75 # Documentation for method `baz`
80 `Block comments` are comments composed of one or more line rattached to nothing.
81 They are displayed with one blank line before and after at current indent level.
90 `Attached comments` are comments attached to a production.
91 They are printed as this.
94 fun foo do # attached comment
98 `nitpretty` automatically remove multiple blanks between comments:
109 Productions are automatically inlined when possible.
113 * The production must be syntactically inlinable
114 * The inlined production length is less than `PrettyPrinterVisitor::max-size`
115 * The production do not contains any comments
119 * There is a blank between the module declaration and its imports
120 * There is no blank between imports and only one after
121 * There is a blank between each extern block definition
122 * There is a blank between each class definition
123 * There is no blank line at the end of the module
126 # Documentation for module `foo`
133 # Documentation for class `Bar`
136 class Baz end # not a `ADoc` comment
141 * There is no blank between the class definition and its super-classes declarations
142 * There is no blank between two inlined property definition
143 * There is a blank between each block definition
144 * There no blank line at the end of the class definition
147 # Documentation for class `Bar`
162 Generic types have no space after or before brackets and are separated by a comma and a space:
165 class A[E: Type1, F: Type1] end
170 * Inlined productions have no blank lines between them
171 * Block productions have a blank before and after
185 ### CALLS AND BINARY OPS
187 Arguments are always printed separated with a comma and a space:
193 Binary ops are always printed wrapped with spaces:
199 Calls and binary ops can be splitted to fit the `max-size` constraint.
200 Breaking priority is given to arguments declaration after the comma.
203 return foo("aaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb",
204 "cccccccccccccccccccccccccc")
207 Binary ops can also be broken to fit the `max-size` limit:
210 return "aaaaaaaaaaaaaaaaaaaaaaaaaa" + "bbbbbbbbbbbbbbbbbbbbbbbbbbb" +
211 "cccccccccccccccccccccccccc"
216 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>