Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add check for Emacs UTF-8 file header #77

Merged
merged 2 commits into from
Nov 17, 2023
Merged

Add check for Emacs UTF-8 file header #77

merged 2 commits into from
Nov 17, 2023

Conversation

antonioeatgoat
Copy link
Contributor

This actually prevents the usage of that declaration in every comment, not only on the same line of PHP tag opening.

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added/updated (for bug fixes/features)

What kind of change does this PR introduce?
New Feature

What is the current behavior?
The declaration can be used -*- coding: utf-8 -*- everywhere without any prevention.

What is the new behavior?
The new custom sniff raises a warning if the declaration -*- coding: utf-8 -*- is found in a comment.

Note: Since the declaration would be removed from the first line anyway by PSR12.Files.OpenTag.NotAlone, this new sniff actually search for it in every comment in the file.

If found, phpcbf will get rid of the whole comment line. I think it is safe enough to assume that there won't be anything else in the same comment.

Does this PR introduce a breaking change?
No

Other information:
As usual, any suggestion to improve the sniff name or the error message are more than welcome 👂

This actually prevents the usage of that definition in every comment, not only on the same line of PHP tag opening.
@antonioeatgoat antonioeatgoat linked an issue Oct 27, 2023 that may be closed by this pull request
@gmazzap
Copy link
Contributor

gmazzap commented Nov 15, 2023

@antonioeatgoat Just a confirmation before I merge: did you test the "fix" in different scenarios?

@antonioeatgoat
Copy link
Contributor Author

@gmazzap do you mean if I tested it outside of the unit tests? If so, then yes, I tried the new sniff in a package a was developing where I put those headers and both detection and automatic-fix looked to work well for me.

@gmazzap
Copy link
Contributor

gmazzap commented Nov 17, 2023

Thanks @antonioeatgoat I see unit tests are there for error detecting, but not for fixing. If you also tested fixing, then we can merge,

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add check for Emacs UTF-8 file header
2 participants