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

Stop adding newline to end of file #138

Open
Dekadinious opened this issue Sep 23, 2024 · 7 comments · May be fixed by #142
Open

Stop adding newline to end of file #138

Dekadinious opened this issue Sep 23, 2024 · 7 comments · May be fixed by #142

Comments

@Dekadinious
Copy link

I came from the wongjn extension recently, and I can't seem to get this extension to stop adding a new line at the end of my files.

I have turned "Files: Insert Final Newline" in VSCode off. I also have this in my ruleset:

<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="FL" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">

	<rule ref="WordPress">
		<exclude name="WordPress.PHP.YodaConditions.NotYoda"/>
		<exclude name="WordPress.Files.FileName.InvalidClassFileName"/>
		<exclude name="WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase"/>
		<exclude name="Universal.Operators.DisallowShortTernary.Found"/>
		<exclude name="PSR2.Files.EndFileNewline.NoneFound"/>
		<exclude name="Generic.Files.EndFileNewline"/>
		<exclude name="WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder"/>
	</rule>

</ruleset>

When running phpcbf manually, no newlines are added and no fixes are available on the file. When I save the file and the formatter runs, a newline is added. If I disable phpcbf from this extension, no newline is added. If I run the exact phpcbf command this extension runs, no fixes are available and no newlines are added.

The only time a newline is added is if I save the file or run formatting on it, or run F1 -> PHPCBF: Fix this file.

How can I make it stop?

@jonathanbossenger
Copy link
Collaborator

Can I ask what your output looks like when you run phpcs in the terminal against your file?

phpcs plugin-file.php

@Dekadinious
Copy link
Author

Yes, it just states: "No fixable errors were found" if I ensure to have the file saved without a newline at the end and no other errors. If I add other errors, it will list and fix them, but not add the newline. So I am a bit stumped as to where it comes from when formatting through the extension and how to log that. 😅

@jonathanbossenger
Copy link
Collaborator

Yeah, it is weird, because I don't see anything adding a newline in the extension code either.

I've never noticed this because I don't exclude the PSR2.Files.EndFileNewline.NoneFound rule, but I am able to replicate the issue using your phpcs.xml file, so I will keep digging.

@jonathanbossenger
Copy link
Collaborator

@Dekadinious I found the problem, and opened a PR to fix it in #142

Are you able to test the PR to confirm it resolves the issue?

@Dekadinious
Copy link
Author

@jonathanbossenger That's great, and I would love that. But how do I test a specific PR? 😅

@jonathanbossenger
Copy link
Collaborator

@Dekadinious, essentially you use the same steps to run the development version listed here

  1. Clone this repo git clone https://github.com/valeryan/vscode-phpsab.git
  2. Switch to the specific branch with the changes cd vscode-phpsab git checkout 138-fix-newline-error
  3. Open the extension in VS Code and run the Debug/Development version as detailed in the steps above

This will open a new VS code instance running the code from that branch, which you can use to test.

@Dekadinious
Copy link
Author

@jonathanbossenger Thank you for the guidance!

I can confirm that it works, and I also tested #139 and can confirm that both spaces and special characters no longer trigger the error :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants