Skip to content
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

Remaining formatter issues #1192

Open
18 tasks
sophiajt opened this issue Sep 20, 2022 · 1 comment
Open
18 tasks

Remaining formatter issues #1192

sophiajt opened this issue Sep 20, 2022 · 1 comment

Comments

@sophiajt
Copy link
Collaborator

sophiajt commented Sep 20, 2022

We're close to being able to turn on the formatter as part of CI and part of the Jakt workflow. There are a few remaining issues we should fix before we do that. I'm making a list with checkboxes. If someone wants to work on one, comment below and we can put your name in. Once finished, we'll check it off the list:

  • 1) If you miss the dot in the method call instead of a function, you get “wrong number of args” should say add dot

  • 2) Move ) to newline:

        let main_result = interpreter.execute(
            function_to_run_id: main_function_id!
            namespace_
            this_argument: None
            arguments
            call_span)

Similar/same:

function is_return_allowed(
    anon allowed_control_exits: AllowedControlExits) -> bool => not allowed_control_exits is Nothing
  • 3) Drop semicolon when not needed:
            println(
                "{{\"start\": {}, \"end\": {}, \"file\": \"{}\"}}"
                result.start
                result.end
                escape_for_quotes(file_path!.path)
            );
  • 4) Move blocks to spread out more when the line is long. For example, the long line in this example feels squashed:
function main() {
        for (_, function_id) in scope.functions.iterator() {
            if function_.linkage is External or function_.type is ImplicitConstructor or function_.type is ImplicitEnumConstructor { continue }

            output += .codegen_function(function_)
            output += "\n"
        }    
}
  • 5) Bad indent:
            if not (
                    type_module.is_root or type_module.id.equals(ModuleId(id: 0)) or checked_struct.definition_linkage is External
                ) {
                output += type_module.name
                output += "::"
            }

Related:

            yield match .execute(
                    call.function_id!
                    namespace_: Some(call.namespace_)
                    this_argument
                    arguments
                    call_span: span
                    invocation_scope: InterpreterScope::create(
                        type_bindings
                    )
                ) {
                Return(value) => StatementResult::JustValue(value)
                Throw(value) => StatementResult::Throw(value)
            }
  • 6) Bad spacing:
	else => (.index as! i64+offset-1) as! usize

Also bad space:

	let value = .input[.index]-offset
  • 7) Weird newline in long expressions, for example:
                let number: f64 = u64_to_float<f64>(
                    total
                ) + u64_to_float<f64>(fraction_nominator) / u64_to_float<f64>(fraction_denominator)
  • 8) Related: bad spacing in long expressions with a function call:
                guard lhs_variant_names.size(

                    ) == rhs_variant_names.size() and lhs_variant_arguments.size() == rhs_variant_arguments.size() else {
  • 9) This return needs more indentation:
        return .name == rhs_parsed_varible.name and
        .parsed_type.equals(rhs_parsed_varible.parsed_type) and
        .is_mutable == rhs_parsed_varible.is_mutable
  • 10) Unnecessary splitting of short lines, for example:
                .error("Expected 'c' or path after `import extern`"
                    .current().span())
  • 11) Some long lines are never split, for example:
        mut this, partial_enum: ParsedRecord, definition_linkage: DefinitionLinkage, is_boxed: bool) throws -> ([SumEnumVariant], [ParsedMethod]) {
  • 12) Bad spacing for some calls inside other calls:
                                        .error(
                                            format(
                                            "Enum variant '{}' in enum '{}' has a non-constant value: {}"
                                            variant.name
                                            enum_.name
                                            value_expression
                                            )
                                            variant.span
                                        )
  • 13) Missing space at the end:
	LessThan => { open_angles += 1}
  • 14) Not idempotent (multiple formatting calls do not give you the same output):
            Typed(name, span: variant_span) => {
                if variant_span.contains(span) {
                    return Some(
                        Usage::EnumVariant(
                        span: variant_span
                        name
                        type_id: checked_enum.type_id
                        variants: enum_variant_fields(program, checked_enum_variant: variant)
                        number_constant: None
                    ))

                }
            }
  • 15) Weird spacing (2 after yield and none inside of {} :
                                    yield  {format("else ({})", program.type_name(type_id))}
  • 16) Interpreter - bad reflow (shouldn't split across the match like this):
    CInt(
        x
    ) => CheckedExpression::NumericConstant(
        val: CheckedNumericConstant::I32(x as! i32)
        span: this_value.span
        type_id: builtin(BuiltinType::CInt)
    )

Should be:

    CInt(x) => 
        CheckedExpression::NumericConstant(
            val: CheckedNumericConstant::I32(x as! i32)
            span: this_value.span
            type_id: builtin(BuiltinType::CInt)
        )
  • 17) Sometimes this has a space sometimes it doesn’t:
bindings: [String:Value] = [:]
  • 18) Comma or no comma:
                            .error(
                                format(
                                    "Prelude function `File::read_all` expects a `File` as its this argument, but got {}"
                                    this_argument!.impl
                                ),
                                call_span
                            )
@robryanx
Copy link
Contributor

robryanx commented Sep 23, 2022

This a list of issues found from the samples directory.

  • 19) Spacing after as! i64

eg. In samples/basics/bubble_sort.jakt

while i < values.size() as! i64-1 {

Should be:

while i < values.size() as! i64 - 1 {
  • 20) Garbage Tokens
    eg. In samples/basics/error.jakt
    I think garbage tokens should store the raw values they have consumed and these should just be reproduced as is with no rules applied by the formatter.

  • 21) If boolean spacing
    eg. In samples/basics/opening_curly_brace_on_newline.jakt

iftrue

Should be:

if true
  • 22) Extra space after parent class
    eg. In samples/classes/inheritance.jakt
class Child: Parent  {

Should be:

class Child: Parent {
  • 23) Various function expression issues, probably all related to the FunctionTypeContext
    No space after function expressions
function ()

Should be:

function()

Spacing around fat arrow

function()=>"PASS"

Should be:

function() => "PASS"

Function expression throws spacing

function ()  throws  -> String

Should be:

function() throws -> String
function (a: i64)=>a==5

Should be:

function (a: i64) => a == 5
letcb2:function() -> String = function ()=>"PASS"

Should be

let cb2: function() -> String = function() => "PASS"

eg. In samples/closures/function_as_variable.jakt
In that case it is still in the function context from the previous cb function when formatting let cb2:

  • 24) Function spacing
    eg. In samples/closures/no_returning_functions.jakt
    functionmain(){}
    Should be
    function main() {}

  • 25) Enum spacing
    eg. In samples/enums/one_line_declaration.jakt

enum Apple {GrannySmith}

Should be

enum Apple { GrannySmith }

I think it looks better with the spaces.

  • 26) Enum with underlying types
    eg. In samples/enums/parse.jakt
enum IntegralWithUnderlyingType: i32  {

Should be:

enum IntegralWithUnderlyingType: i32 {
One=2

Should be

One = 2
  • 27) Reference spacing
    eg. In samples/functions/implicit_argument_label_on_dereference.jakt
println("{}", foo( & a))

Should be:

println("{}", foo(&a))
  • 28) Dereference spacing
    eg. In samples/references/basic.jakt
    Import spacing
import foo asbaz

Should be

import foo as baz
import foo asbaz {Bar, bar}

Should be:

import foo as baz { Bar, bar }
  • 29) Match case or spacing
Baz |  else => "FAIL"

Should be:

Baz | else => "FAIL"
  • 30) Negative number spacing
let x: i64 =  - 100

Should be:

let x: i64 = -100
  • 31) Set spacing
let set = { 1, 2, 3, 4}

Should be:

let set = { 1, 2, 3, 4 }
  • 32) Weak spacing
mut foo: weakFoo? = None

Should be:

mut foo: weak Foo? = None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants