Trailing whitespaces in generated code

Have not found this topic so bring it up here.
Cursor tends to generate trailing whitespaces in its generated code, even if I instruction it to “avoid trailing whitespaces” in system prompts.

Any idea how to fix this issue? My system prompt is in Chinese, maybe someone has better prompts for this?

Or does Cursor support calling some extra tool to “trim white spaces” in generated code?

Thanks for any help!

3 Likes

Same here.
(Wow, this is the exact reason why I made account for this forum.)

Hey, are you also using a Chinese prompt like the original poster?

I’ve not seen many reports of this, but you may be able to configure a format-on-save step that removes the whitespace, but doesn’t actually format the code, as a workaround.

Best way to test this is to run cursor --disable-extensions to turn all the linters off and use just Cursor’s raw AI features.

1 Like

Hi I’m also having this issue. All English prompts. I also have a rule asking it to not include trailing whitespaces. But it ignores that.

This is an issue that should really be solved programmatically anyway. It should be a setting that filters them from the LLM output. We shouldn’t count on the LLM behaving.

I think the issue is not cursor specific, but it is correct that the LLM response too often contains trailing whitespace or forgets to add a new line in the end of the file. Would be great to at least have the option to add some kind of after edit hook that cleans up the stuff right after editing either by applying a simple regex replace or linter autocorrection.

1 Like