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

Harshil alignment of inputs and outputs #71

Open
edmundmiller opened this issue Nov 18, 2024 · 3 comments
Open

Harshil alignment of inputs and outputs #71

edmundmiller opened this issue Nov 18, 2024 · 3 comments
Labels
formatting Related to automatic code formatting

Comments

@edmundmiller
Copy link

edmundmiller commented Nov 18, 2024

The Harshil Alignment expects the inputs and outputs to be aligned based on the , 🙃

This is what currently happens:
nf-core/modules@d134e78#diff-1ecd6f34cd082ae715c3861cfc6109fb379ff397cbb125dfe3cc7baa4ad22f59L15-R17

Docs: https://nf-co.re/docs/contributing/code_editors_and_styling/harshil_alignment#comma-example

@bentsherman
Copy link
Member

That rule looks like a nightmare to implement. I hope to introduce a better syntax for process inputs/outputs as part of static types, that should make this formatting rule irrelevant, but that could take a while.

Others are welcome to try:

if( node.inputs instanceof BlockStatement ) {
fmt.appendIndent();
fmt.append("input:\n");
visitDirectives(node.inputs);
fmt.appendNewLine();
}
if( node.outputs instanceof BlockStatement ) {
fmt.appendIndent();
fmt.append("output:\n");
visitDirectives(node.outputs);
fmt.appendNewLine();
}

@edmundmiller
Copy link
Author

That's what I was afraid of.

@maxulysse pointed out that he'd rather the "space come after the comma"

    output:
-   tuple val(meta), path("*.bam") , emit: bam
+   tuple val(meta), path("*.bam"),  emit: bam
    tuple val(meta), path("*.bais"), emit: bai
+   path "versions.yml",             emit: versions
-   path "versions.yml"            , emit: versions

So just align on the emits, and make the comma come directly after.

I think that sounds easier to implement. Idk how the VS Code users have been doing it, but there's an Emacs function for it, and I think a Vim function, at least this plugin might give some ideas https://github.com/junegunn/vim-easy-align

@bentsherman
Copy link
Member

Spaces before comma is probably slightly easier

I think the algorithm would be:

  • compute the text for each output declaration (without options)
  • compute the text for each output option for each declaration
  • add padding to each output declaration based on max width
  • add padding to each output option based on max width (for emit, optional, etc)
  • concatenate everything at the end

@ewels ewels added the formatting Related to automatic code formatting label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatting Related to automatic code formatting
Projects
None yet
Development

No branches or pull requests

3 participants