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

Alignment #12

Closed
fredrikekre opened this issue Jun 14, 2024 · 3 comments · Fixed by #44
Closed

Alignment #12

fredrikekre opened this issue Jun 14, 2024 · 3 comments · Fixed by #44
Milestone

Comments

@fredrikekre
Copy link
Owner

Currently Runic destroys alignment because it is very stringent about spacing, for example

a  = 1
ab = 2

will be replaced with

a = 1
ab = 2

Doing this is of course a valid option (and what e.g. gofmt does).

The current rule is a single space around operators, but I wonder if relaxing it to at least a single space around operators would satisfy the "human need" to prettify things with alignment would be a good option. I think this would work in all situations where you typically align things.

@fredrikekre fredrikekre added this to the 1.0.0 milestone Jun 14, 2024
@kaat0
Copy link

kaat0 commented Jul 14, 2024

What about comments? For example:

a  = 1.0 # important float
ab = 2   # fine as integer

@fredrikekre
Copy link
Owner Author

fredrikekre commented Jul 14, 2024

Yea same would apply there -- at least one space before comment.

@fredrikekre
Copy link
Owner Author

Perhaps #41 could be enough to solve this. I think that "useful" alignment is pretty rare but in cases where it is useful you can format it on your own instead. (The example in the OP is IMO a case of aligntment that isn't useful).

It seems very tricky to try to detect existing alignment in the code.

fredrikekre added a commit that referenced this issue Aug 15, 2024
This patch implements `# runic: on` and `# runic: off` toggle comments
that can be included in the source to toggle formatting on/off.

The two comments i) must be placed on their own lines, ii) must be on
the same level in the expression tree, and iii) must come in pairs. An
exception to condition iii) is made for top level toggle comments so
that formatting for a whole file can be disabled by a `# runic: off`
comment at the top without having to add one also at the end of the
file.

For compatibility with JuliaFormatter, `#! format: (on|off)` is also
supported but it is not possible to pair e.g. a `# runic: off` comment
with a `#! format: on` comment.

Closes #12, closes #42.
fredrikekre added a commit that referenced this issue Aug 15, 2024
This patch implements `# runic: on` and `# runic: off` toggle comments
that can be included in the source to toggle formatting on/off.

The two comments i) must be placed on their own lines, ii) must be on
the same level in the expression tree, and iii) must come in pairs. An
exception to condition iii) is made for top level toggle comments so
that formatting for a whole file can be disabled by a `# runic: off`
comment at the top without having to add one also at the end of the
file.

For compatibility with JuliaFormatter, `#! format: (on|off)` is also
supported but it is not possible to pair e.g. a `# runic: off` comment
with a `#! format: on` comment.

Closes #12, closes #41.
fredrikekre added a commit that referenced this issue Aug 15, 2024
This patch implements `# runic: on` and `# runic: off` toggle comments
that can be included in the source to toggle formatting on/off.

The two comments i) must be placed on their own lines, ii) must be on
the same level in the expression tree, and iii) must come in pairs. An
exception to condition iii) is made for top level toggle comments so
that formatting for a whole file can be disabled by a `# runic: off`
comment at the top without having to add one also at the end of the
file.

For compatibility with JuliaFormatter, `#! format: (on|off)` is also
supported but it is not possible to pair e.g. a `# runic: off` comment
with a `#! format: on` comment.

Closes #12, closes #41.
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

Successfully merging a pull request may close this issue.

2 participants