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

Support dprint-ignore for a region #411

Open
jakebailey opened this issue Sep 4, 2022 · 4 comments
Open

Support dprint-ignore for a region #411

jakebailey opened this issue Sep 4, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@jakebailey
Copy link
Contributor

jakebailey commented Sep 4, 2022

I have a piece of code that is formatted to look like a table: https://github.com/microsoft/TypeScript/blob/7910c509c4545517489d6264571bb6c05248fb4a/src/testRunner/unittests/tsserver/projectReferences.ts#L1573

I can // dprint-ignore the entire function (the describe), but that disables formatting for code I do want formatted. Or, I can wrap the code in a block like:

// dprint-ignore
{
    // Some comemnt
    baselineDisableReferencedProjectLoad(...)
    baselineDisableReferencedProjectLoad(...)
    baselineDisableReferencedProjectLoad(...)
}

But, it would be nice to instead do something like eslint where I can have:

/* dprint-ignore-start */
// my special code
/* dprint-ignore-end */

I'm not sure how possible that is; it seems like the existing ignore feature puts comments on nodes for a reason, probably because the info is stored in the AST rather than using locations?

Prettier sort of has this for regions: https://prettier.io/docs/en/ignore.html#range-ignore (But, does the same as dprint in that its other ignore comment is AST based)

@dsherret dsherret added the enhancement New feature or request label Sep 5, 2022
@dsherret
Copy link
Member

dsherret commented Sep 5, 2022

dprint-plugin-markdown also has this for regions. It wouldn't be too difficult to add this. Essentially, detect one of these comments, then increment a count in the context, then format all nodes as ignore until a dprint-ignore-end comment is found.

@jakebailey
Copy link
Contributor Author

I realized that I sent this to the TS plugin repo unintentionally, but I'm assuming this would be something that would need to be implemented in each plugin separately.

@dsherret
Copy link
Member

dsherret commented Sep 5, 2022

This is the right place to ask this. It needs to be done per plugin. The CLI to plugin interface is really simple and is essentially just "here's a file path and here's some text, please format it"

@jakebailey
Copy link
Contributor Author

Makes sense!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants