-
-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reformat std #8408
Reformat std #8408
Conversation
WeakMap has been renamed by 67d74cd on Mar 15, 2015 with this message:
So I guess it's fine to remove it now? |
@:noCompletion @:from extern inline static function __cast<T>(value:T):Any return cast value; | ||
@:noCompletion extern inline function toString():String return Std.string(this); | ||
@:noCompletion @:to extern inline function __promote<T>():T | ||
return this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be kept as a single line by the formatter.
|
||
#if flash | ||
private static function __init__():Void | ||
untyped { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, untyped should be kept on declaration line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, there's an open issue for this: HaxeCheckstyle/haxe-formatter#362
@:coreType abstract Void { } | ||
#if jvm | ||
@:runtimeValue | ||
#end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should also be kept as single-line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the same as HaxeCheckstyle/haxe-formatter#332.
@:op(A<=B) private static function ltef2(lhs:Float, rhs:UInt):Bool; | ||
abstract UInt to Int from Int { | ||
@:commutative @:op(A + B) private static function addI(lhs:UInt, rhs:Int):UInt; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No newlines when there is consecutive methods with no body seems like a good rule
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. That is normally the logic for externs / interfaces / etc, I think the formatter doesn't account for body-less functions being a thing in externs too yet.
@@ -19,6 +19,7 @@ | |||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |||
* DEALINGS IN THE SOFTWARE. | |||
*/ | |||
package cpp; | |||
|
|||
package cpp; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ? just after the initial (c) block seems fine to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, there's an open issue for this here: HaxeCheckstyle/haxe-formatter#310
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I understand correctly, this is configurable, but the default is currently set to 1 line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sort of... but changing the setting also removes empty lines between multiline comments (HaxeCheckstyle/haxe-formatter#292). I'd want both, which isn't possible yet.
I have added a few comments. Conditional blocks indentation Original: #if hl
return bla();
#elseif sys
return foo();
#else
#if haxe4
return a();
#else
return b();
#end
#end Reformated: #if hl
return bla();
#elseif sys
return foo();
#else
#if haxe4
return a();
#else
return b();
#end
#end I think that we should enforce indentation when into a "block-level" #if Also, I think we should be able to keep the single line Switch cases indentation That's more of a controversial one, that will most likely hurts some's habits. switch (e) {
case Value(x):
return x;
case Add(x,y):
return eval(x) + eval(y);
case Throw(v);
switch( v ) {
case String(str): throw str;
default:
}
} Instead of: switch (e) {
case Value(x):
return x;
case Add(x,y):
return eval(x) + eval(y);
case Throw(v);
switch( v ) {
case String(str): throw str;
default:
}
} Single line should be kept Some single line code should not be transformed into multiple line, for instance the following: if( x == 0 ) continue; Should not be transformed into: if( x == 0 )
continue; And the following: [for( x in 0...MAX ) for( y in 0...MAX ) x * y]; Should not be transformed into: [
for( x in 0...MAX )
for( y in 0...MAX )
x * y
] |
Conditional blocks indentation This style of formatting can be achieved with the following setting: {
"indentation": {
"conditionalPolicy": "alignedIncrease"
}
} However, it does not differentiate between block-level conditionals and others. I guess that would make it more bearable. We might need an additional, separate Still, a bit surprising since it's the opposite of your switch-case indentation preference, where you want to avoid indentation. ;) I was going to say the current formatter default is more in line with the current style in std, but it actually seems to be all over the place and uses at least three different styles for conditional indentation at block level. Switch cases indentation I can definitely see the advantages of this one (recently opened an issue for the formatter to support it, actually: HaxeCheckstyle/haxe-formatter#478). However, I think it's quite rare for code in std / for Haxe code in general to be formatted like this. I have a feeling @Simn might not like it for instance? Single line should be kept I think the formatter already supports this one through a "keep" setting, but I'm not sure if it's a great idea. Everywhere such a "keep" setting is used, the resulting code will be less consistent since it depends on the original formatting of the file instead of enforcing one style. |
Oh, and in general, I'd really like the default settings of the formatter to be the same as the ones used in std. So this is also a discussion about the defaults of the formatter, not just the |
I find the latter example much more readable than the proposed one. Opening curly should always mean additional indentation level. |
@ncannasse I fully agree with all of your suggestions but one:
I've noticed that this is your personal preference and I while I don't share it, I could live with it. That said, I think for one it's not a pragmatic choice (more on that later) and your line of argument is poor. Haxe's syntax is rooted in ECMAScript and since we're discussing concrete syntax, not semantics, if there's any argument to be made about "being true to the roots", then we should follow what's common in ECMAScript and you're proposing quite the opposite. Now, we can go 12 rounds on "which is better" (as Alex proposed 😄), but I think it's quite irrelevant. My perception is that the vast majority of Haxe code is written with indented cases (probably because shocking as it may be the author's background is far more often in AS3 than in OCaml). I know we don't consider majoritarian decision for language design and I understand why, but: this is not language design. We're trying to establish a standard, backed by merely by an opt-in tool to support it. We want the maximum of people to use it (otherwise, why have a standard?), while not forcing them to (I guess the most we can do is pushing for IDE integration by default, so that it's elevated to an opt-out). Assuming the non-indented style is used no more than 20% of the time1 I wonder what the wisdom is in picking it. We'll just fragment the community. Once we have people tweaking one formatting setting, they'll start messing with the others as well, because why not. We'll have accomplished nothing. 1. I'll gladly volunteer to get actual data from GitHub's code search, on the condition that a *clear* majority will conclude this decision. |
It does just that, since the case content is indented. With the current default, you have one brace that produces two levels of indentation : one for the case + one for the case content. That's one too much if you consider curly braces --> indentation. @back2dos I do certainly and respect your point of view regarding existing code, as I am often in defense of the side of keeping in mind all existing code. And of course I think such feature should be customizable by people using formater. Now we're talking about what should be the default behavior. And I think that promoting what I think is the most readable and maps the best the language syntax is good enough to qualify as "design" as justify a change. Please note that our switch syntax differs a lot from EcmaScript already : no breaks, pattern matching, etc. |
OTOH I find that wanting a single level of indentation for actual code (vs "case patterns") is quite consistent ;) |
To me the cases only make sense inside a switch, hence the indentation. |
Ok, I resolved the conflicts; we should merge this now. There are some issues with the formatting, but the output is still better than before (it's consistent at least) and waiting for all the formatter issues would just mean putting this off forever. Once these issues are fixed, we can reformat again: |
Great work, thanks! |
* reformat root std classes * reformat std sys classes * reformat std haxe classes * reformat eval classes * reformat cpp classes * reformat cs classes * reformat hl classes * reformat java classes * reformat js classes * reformat jvm classes * reformat lua classes * reformat neko classes * reformat non-extern flash classes * reformat php classes * reformat python classes * remove cs WeakMap * merge reformat * fix loadLazy format in cpp.Lib * fix Lambda.flatten format * post-merge reformat * fix * fix 2 * fix 3 * fix 4 ... * fix 5 ..... * fix 7 .........
Closes #7404.
std
withhaxelib run formatter
I didn't touch the non
_std
classes instd/flash
, nor the auto-generated externs instd/js
, since those should be addressed separately. Some interesting finds that should maybe be addressed at some point:std/cpp/zip/Compress.hx#L24
-#if (haxe_ver < 9000.0)
- in allcpp.zip
andneko.zip
classes.hx
?Future goals:
--gen-hx-classes
) are generated consistently with the formatPrinter
is consistent with the format