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

Avoid de-denting comments that align #410

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

Avoid de-denting comments that align #410

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

Comments

@jakebailey
Copy link
Contributor

In TS we have enums with comments aligned like so:

export const enum TypeFacts {
    None = 0,
    TypeofEQString = 1 << 0,      // typeof x === "string"
    TypeofEQNumber = 1 << 1,      // typeof x === "number"
    TypeofEQBigInt = 1 << 2,      // typeof x === "bigint"
    TypeofEQBoolean = 1 << 3,     // typeof x === "boolean"
    TypeofEQSymbol = 1 << 4,      // typeof x === "symbol"
    TypeofEQObject = 1 << 5,      // typeof x === "object"
    TypeofEQFunction = 1 << 6,    // typeof x === "function"
    TypeofEQHostObject = 1 << 7,  // typeof x === "xxx"
    TypeofNEString = 1 << 8,      // typeof x !== "string"
    TypeofNENumber = 1 << 9,      // typeof x !== "number"
    TypeofNEBigInt = 1 << 10,     // typeof x !== "bigint"
    TypeofNEBoolean = 1 << 11,    // typeof x !== "boolean"
    TypeofNESymbol = 1 << 12,     // typeof x !== "symbol"
    TypeofNEObject = 1 << 13,     // typeof x !== "object"
    TypeofNEFunction = 1 << 14,   // typeof x !== "function"
    TypeofNEHostObject = 1 << 15, // typeof x !== "xxx"
    EQUndefined = 1 << 16,        // x === undefined
    EQNull = 1 << 17,             // x === null
    EQUndefinedOrNull = 1 << 18,  // x === undefined / x === null
}

But, dprint reformats this like:

export const enum TypeFacts {
    None = 0,
    TypeofEQString = 1 << 0, // typeof x === "string"
    TypeofEQNumber = 1 << 1, // typeof x === "number"
    TypeofEQBigInt = 1 << 2, // typeof x === "bigint"
    TypeofEQBoolean = 1 << 3, // typeof x === "boolean"
    TypeofEQSymbol = 1 << 4, // typeof x === "symbol"
    TypeofEQObject = 1 << 5, // typeof x === "object"
    TypeofEQFunction = 1 << 6, // typeof x === "function"
    TypeofEQHostObject = 1 << 7, // typeof x === "xxx"
    TypeofNEString = 1 << 8, // typeof x !== "string"
    TypeofNENumber = 1 << 9, // typeof x !== "number"
    TypeofNEBigInt = 1 << 10, // typeof x !== "bigint"
    TypeofNEBoolean = 1 << 11, // typeof x !== "boolean"
    TypeofNESymbol = 1 << 12, // typeof x !== "symbol"
    TypeofNEObject = 1 << 13, // typeof x !== "object"
    TypeofNEFunction = 1 << 14, // typeof x !== "function"
    TypeofNEHostObject = 1 << 15, // typeof x !== "xxx"
    EQUndefined = 1 << 16, // x === undefined
    EQNull = 1 << 17, // x === null
    EQUndefinedOrNull = 1 << 18, // x === undefined / x === null
}

Maybe it makes more sense for these comments to be JSDoc or something, but I think a lot of these comments are intended to be internal and not visible in d.ts files. I'd have to find more examples where it matters, though.

Likely, an ignore comment could be used when it matters to keep formatting (we have some cases where it matters), but this is visually pleasing. As a comparison, go fmt will format aligned comments in situations similar to the above, so it's not unprecedented overall, but prettier does format things like dprint currently does.

@dsherret dsherret added the enhancement New feature or request label Sep 5, 2022
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