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

Wrap lines based on presence of trailing comma #74

Closed
ewels opened this issue Nov 25, 2024 · 0 comments
Closed

Wrap lines based on presence of trailing comma #74

ewels opened this issue Nov 25, 2024 · 0 comments
Labels
formatting Related to automatic code formatting

Comments

@ewels
Copy link
Member

ewels commented Nov 25, 2024

Several popular code formatters (ok I'm mostly thinking Black for Python) have the ability to customise wrapping of long lines of code based on the presence of a trailing comma. In Black this is called the magic comma

The magic trailing comma
Black in general does not take existing formatting into account.

However, there are cases where you put a short collection or function call in your code but you anticipate it will grow in the future.

For example:

TRANSLATIONS = {
    "en_us": "English (US)",
    "pl_pl": "polski",
}

Early versions of Black used to ruthlessly collapse those into one line (it fits!). Now, you can communicate that you don’t want that by putting a trailing comma in the collection yourself. When you do, Black will know to always explode your collection into one item per line.

How do you make it stop? Just delete that trailing comma and Black will collapse your collection into one line if it fits.

I think that this is a great pattern that we could also use in Nextflow. Both commas for things like maps and lists, but also semi-colons for things like consecutive imports.

@ewels ewels added the formatting Related to automatic code formatting label Nov 25, 2024
bentsherman added a commit that referenced this issue Dec 13, 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

1 participant