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

mint format some_file.mint should return code 0 if no syntax error regardless if some_file.mint if changed. #548

Closed
zw963 opened this issue Jul 1, 2022 · 7 comments · Fixed by #586
Labels
question Further information is requested
Milestone

Comments

@zw963
Copy link

zw963 commented Jul 1, 2022

Please check following WIP discuss.

lassik/emacs-format-all-the-code#198

Also following PR:

lassik/emacs-format-all-the-code#200 (comment)

@gdotdesign
Copy link
Member

I'm not sure what changes are requested here.

The format only returns 1 if there is an error while formatting, this for example returns 0 for valid input:

➜  app-desktop git:(master) ✗ echo 'module X {const A = ""}' | mint format --stdin
module X {
  const A = ""
}

➜  app-desktop git:(master) ✗ echo $?
0

This returns 1 for invalid input:

➜  app-desktop git:(master) ✗ echo 'module x {const A = ""}' | mint format --stdin
Unhandled exception: ░ SYNTAX ERROR ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

I was looking for the name of a module but found "x" instead. 

The name of a module must start with an uppercase letter and only contain 
lowercase, uppercase letters and numbers. 

Here is the relevant code snippet: 

┌─┬ stdin.mint:1:8 ────────────────────────────────────────────────────────────┐
│1│ module x {const A = ""}                                                    │
└─┴────────────────────────────────────────────────────────────────────────────┘

 (Mint::Parser::ModuleExpectedName)
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'
➜  app-desktop git:(master) ✗ echo $?
1

It should catch the exception but still should return 1


If you like to have formatting, I recommend using the mint language server itself, it has a command for formatting code and also format files when saved.

@gdotdesign gdotdesign added the question Further information is requested label Jul 1, 2022
@lassik
Copy link

lassik commented Jul 1, 2022

Sorry about the false alarm.

The format only returns 1 if there is an error while formatting, this for example returns 0 for valid input:

That is The Right Thing To Do (TM).

$ echo '{}' >mint.json

$ echo 'module X {const A = ""}' >example.mint

$ mint format --stdin <example.mint >example2.mint; echo $?
0

$ mint format --stdin <example2.mint >/dev/null; echo $?
0

The above is exactly what we need.

@gdotdesign
Copy link
Member

👍 Can I close this issue then?

@lassik
Copy link

lassik commented Jul 1, 2022

Yes.

@zw963
Copy link
Author

zw963 commented Jul 1, 2022

I'm not sure what changes are requested here.

Okay, thanks for reply, in fact, the --stdin is really what we want i think.

Though, i don't understood why mint format some_file.mint will return 1 when some_file.mint
content get changes. in the purpose is used in CI, should we use like mint format --check some_file.mint instead?

If you like to have formatting, I recommend using the mint language server itself, it has a command for formatting code and also format files when saved.

What you said is LSP server?


UPDATED: okay, i saw the mint ls command, it really cool and unbelievable, because mint write use crystal, even crystal no official language server for now.

@lassik
Copy link

lassik commented Jul 1, 2022

Though, i don't understood why mint format some_file.mint will return 1 when some_file.mint
content get changes.

That's right - I can reproduce this behavior. It seems different from the --stdin behavior.

@gdotdesign
Copy link
Member

Yep that's a bug, reopening the issue then :)

@gdotdesign gdotdesign reopened this Jul 1, 2022
@zw963 zw963 changed the title Try to add mint format functionality to some famous emacs package, and some feedback. mint format some_file.mint should return code 0 if no syntax error regardless if some_file.mint if changed. Jul 1, 2022
@gdotdesign gdotdesign linked a pull request Apr 26, 2023 that will close this issue
@gdotdesign gdotdesign added this to the 0.18.0 milestone May 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

Successfully merging a pull request may close this issue.

3 participants