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.
43 Maximum length of lines (use 0 to disable automatic line breaks).
46 Disable automatic one-liners.
50 The specification of the pretty printing is described here.
52 * Default indentation level is one `'\t'` character and is increased by one for
53 each indentation level.
54 * Default line max-size is 80.
58 There is many categories of comments:
60 `Licence comments` are attached to the top of the file no blank line before,
64 # This is a licence comment
66 # Documentation for module `foo`
70 `ADoc` are documentation comments attached to a `AModule`, `AClassdef`, `APropdef`.
72 They are printed before the definition with a blank line before and no after
73 at the same indentation level than the definition.
76 # Documentation for module `foo`
79 # Documentation for class `Bar`
81 # Documentation for method `baz`
86 `Block comments` are comments composed of one or more line rattached to nothing.
87 They are displayed with one blank line before and after at current indent level.
96 `Attached comments` are comments attached to a production.
97 They are printed as this.
100 fun foo do # attached comment
104 `nitpretty` automatically remove multiple blanks between comments:
115 Productions are automatically inlined when possible.
119 * The production must be syntactically inlinable
120 * The inlined production length is less than `PrettyPrinterVisitor::max-size`
121 * The production do not contains any comments
125 * There is a blank between the module declaration and its imports
126 * There is no blank between imports and only one after
127 * There is a blank between each extern block definition
128 * There is a blank between each class definition
129 * There is no blank line at the end of the module
132 # Documentation for module `foo`
139 # Documentation for class `Bar`
142 class Baz end # not a `ADoc` comment
147 * There is no blank between the class definition and its super-classes declarations
148 * There is no blank between two inlined property definition
149 * There is a blank between each block definition
150 * There no blank line at the end of the class definition
153 # Documentation for class `Bar`
168 Generic types have no space after or before brackets and are separated by a comma and a space:
171 class A[E: Type1, F: Type1] end
176 * Inlined productions have no blank lines between them
177 * Block productions have a blank before and after
191 ### CALLS AND BINARY OPS
193 Arguments are always printed separated with a comma and a space:
199 Binary ops are always printed wrapped with spaces:
205 Calls and binary ops can be splitted to fit the `max-size` constraint.
206 Breaking priority is given to arguments declaration after the comma.
209 return foo("aaaaaaaaaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbbbbbbbb",
210 "cccccccccccccccccccccccccc")
213 Binary ops can also be broken to fit the `max-size` limit:
216 return "aaaaaaaaaaaaaaaaaaaaaaaaaa" + "bbbbbbbbbbbbbbbbbbbbbbbbbbb" +
217 "cccccccccccccccccccccccccc"
222 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>