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

Implement hmph code formatter #226

Open
jasone opened this issue Jan 9, 2022 · 1 comment
Open

Implement hmph code formatter #226

jasone opened this issue Jan 9, 2022 · 1 comment

Comments

@jasone
Copy link
Contributor

jasone commented Jan 9, 2022

Hemlock's syntax makes hmph's job simple relative to most languages, but there are still a few things a Hemlock code formatter should do to files as a whole:

  • Replace multi-space/line separation between tokens with single spaces/lines, respectively.
  • Strip spaces from line ends.
  • Strip leading/trailing blank lines from each block. In the case of the outermost block this includes stripping \n from the end of the file.
  • Densely rewrap lines that exceed 100 columns, but make no effort to split tokens which exceed 100 columns even when placed alone on a line.

Additionally, hmph should be capable of operating on ranges of lines rather than whole files. Differences to whole-file mode include:

  • Leave up to one leading/trailing blank line intact, since there is inadequate context to analyze whether whitespace should be stripped altogether.
  • Optionally rewrap comments as if they are Markdown-formatted, similarly to bar strings, but with * /# preceding each line rather than |. This must be optional because comments are not required to conform to Markdown formatting.

Naturally, hmph should do minimal (and only recoverable) harm to malformed code. This means at least:

  • Never drop non-whitespace tokens.
  • Do not reindent incorrectly indented code, since intent cannot always be determined.
@jasone jasone changed the title Implement hmfmt code formatter Implement hmfmt code formatter Jan 21, 2022
@jasone
Copy link
Contributor Author

jasone commented Jan 25, 2022

Bar string syntax is going away, so hmph's job is further simplified. It would be possible to treat strings which are contextually known to be docstrings as Markdown and rewrap, but it's probably best to just leave strings alone.

@jasone jasone changed the title Implement hmfmt code formatter Implement hmph code formatter Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant