-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 prettier-ignore-start/end for other languages (not only Markdown) #5287
Comments
I have scripts that autogenerate chunks of class property type declarations for Sequelize classes like the following, really need this feature to make things more convenient: /* prettier-ignore-start */
static Users: Association.BelongsToMany<OrganizationAttributes, OrganizationInitAttributes, Organization, UserAttributes, UserInitAttributes, User, OrganizationMemberAttributes, OrganizationMember> = (null: any);
getUsers: BelongsToManyGetMany<User>;
setUsers: BelongsToManySetMany<User, number, OrganizationMemberThroughInitAttributes>;
addUsers: BelongsToManyAddMany<User, number, OrganizationMemberThroughInitAttributes>;
addUser: BelongsToManyAddOne<User, number, OrganizationMemberThroughInitAttributes>;
createUser: BelongsToManyCreateOne<UserInitAttributes, User, OrganizationMemberThroughInitAttributes>;
removeUser: BelongsToManyRemoveOne<User, number>;
removeUsers: BelongsToManyRemoveMany<User, number>;
hasUser: BelongsToManyHasOne<User, number>;
hasUsers: BelongsToManyHasMany<User, number>;
countUsers: BelongsToManyCount;
/* prettier-ignore-end */ |
Would be very useful for
I would also add
|
@muuvmuuv There’s already |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The |
@adelriosantiago That's correct, that's what this issue is about. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I would like a |
@basickarl It's recommended to use |
@lydell I see! Thanks, I'll use this instead. |
In javascript prettier-ignore ignores the next block, so what I did was just make the next few lines a block. Before:
After
Please mind some block scoped statements like |
I'm interested in this as well. When trying to use descriptive names with React hooks this can quickly muddy up variable declarations I have at the top of a component. Being able to ignore a block would allow these variable names to remain description, but also keep them single-line which helps keep the code readable. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I'm running into a really difficult situation with Prettier in Typescript – type MyType = typeof someFunc<unknown>; while this is valid Typescript, it throws [error] > 6 | type MyType = typeof someFunc<unknown>;
[error] | ^ |
New verison of typescript in main (with fixed your problem), but not release yet, please wait a new release |
Prettier can't ignore fragement in your code, we parser a whole file, so if something is not supported by parser, you will get an error, ignoring is not help here |
@bfaulk96 what does that have to do with this issue (5287)? |
You're right. I overlooked that. I'll probably delete my comments since they don't contribute anything useful... |
Prettier is a tool for enforcing consistency. The support for |
@wesleyboar That implies |
I was exasperated by Prettier in general. I shouldn't have let that fester into a comment here. Sorry. |
Not a good solution, but
This allows ESLint comments to be used. /* eslint-disable prettier/prettier */
...
/* eslint-enable prettier/prettier */ Vue template<!-- eslint-disable prettier/prettier -->
...
<!-- eslint-enable prettier/prettier --> In VS Code,Need to disallow the use of the Prettier plugin because of unintended formatting. |
Thank you for that @k-utsumi A little update you have to use block comments instead of // to make it work.
|
What about cases where Prettier is wrong and it breaks things? I have a few React components in TS that are generic, and prettier insists on deleting the generic syntax. The only option available to me now is to turn off formatting for the entire component rather than just telling prettier it's wrong about one comma. Ex: export const MyWhatever = <TItem>({
someProp
}: IMyWhateverProps<TItem>) => {
// stuff that needs to know what TItem is
} |
Does someone has any updates on this issue? I am currently using Django templates and prettier is really bad at formatting those, so I constantly use in my code to stop it from formatting my code, but I am not able to do that in certain cases like this:
As the template tags are inside the html tag itself, I cannot use the as it creates error, and prettier automatically formats this such that {%if is on first line and the rest of the block comes on second line, creating a Django parser error. I am at a dead end at this point, if anyone has any solution then please share. |
you can put your code between two comment of
|
that is not how it currently works, which is precisely why this issue exists. this comment is not only incorrect, but dangerously misleading (think of an AI scraping this comment now, which may just tell people "yes it does support that, just use...."). |
What is the problem with implementation? This issue is already 2 years old |
@AndreiSoroka Nobody has bothered to implement it. 🤷♂️ Note that nobody has an obligation to. Sad but true. |
Bump |
As someone who tried to implement a fix a very while ago, this problem is not as easy as you'd think, and may not make sense with Prettier's implementation. Here's my (probably poor, probably dated) understanding of it: Prettier walks down the AST and formats things as it goes. This is important, since a parent node (like a function declaration) can impact its children (the indentation of a variable declared inside the function). For it to stop and start formatting at arbitrary points, it would have to break that abstraction. What would it mean to stop formatting before a function is declared, but then to start formatting again midway through the body? In most cases, I believe people probably want to keep the formatting of a specific constant (like a string or a weird object) which, thankfully, prettier already supports. If that's not the case, it seems like a lot of work to reconcile Prettier's implementation with this feature request. |
P.s. I think your understanding is not poor or dated. I tried too, but it suddenly started eating up all my time. Need to be involved in the project a bit more than just contribution from some guy from second house |
Oh, how? |
I'm referring to things like this comment specifically |
I would like to disable particular things like print-width only. For example: // Print width demo: -------------------------------------|
this.doSomething(AnotherOne.BlahBlah,AnotherTwo.Blah);
this.doSomething(AnotherOne.BlahBlah1, AnotherTwo.Blah1);
this.doSomething(AnotherOne.BlahBlah10, AnotherTwo.Blah10);
this.doSomething(AnotherOne.BlahBlah2, AnotherTwo.Blah2); Currently formatted to: // Print width demo: -----------------------------------|
this.doSomething(AnotherOne.BlahBlah, AnotherTwo.Blah);
this.doSomething(AnotherOne.BlahBlah1, AnotherTwo.Blah1);
this.doSomething(
AnotherOne.BlahBlah10,
AnotherTwo.Blah10
);
this.doSomething(AnotherOne.BlahBlah2, AnotherTwo.Blah2); But expected / wanted: // prettier-ignore-start print-width
this.doSomething(AnotherOne.BlahBlah, AnotherTwo.Blah);
this.doSomething(AnotherOne.BlahBlah1, AnotherTwo.Blah1);
this.doSomething(AnotherOne.BlahBlah10, AnotherTwo.Blah10);
this.doSomething(AnotherOne.BlahBlah2, AnotherTwo.Blah2);
// prettier-ignore-end I want Prettier enabled here to format/fix the other things. In this case I only want to disable the print-width. Either disable or override value by e.g. See #16662 |
It seems this feature was added only for markdown (#4202 cc @ikatyang), but it's actually useful for other languages as well. It is not working on typescript files on my tests.
Related: facebook/create-react-app#5543
Environments:
Steps to reproduce:
Create a
index.d.ts
file with the following content:Expected behavior:
Actual behavior:
The text was updated successfully, but these errors were encountered: