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

Specify encoding #34

Open
weirdan opened this issue Feb 11, 2017 · 5 comments
Open

Specify encoding #34

weirdan opened this issue Feb 11, 2017 · 5 comments
Labels

Comments

@weirdan
Copy link

weirdan commented Feb 11, 2017

By default, PHPCS assumes file encoding to be encoded in ISO-8859-1. Nowadays people generally use UTF-8, but some may use other multibyte charsets as well.

Not specifying encoding when running PHPCS on multibyte (including UTF-8, when using non-ascii characters) encoded files causes it to report wrong character offsets, and also causes character-width sensitive sniffs fail where they shouldn't. For example, this code trigger failures of line-length sniff (from PSR2 ruleset):

<?php
$q = "ЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖЖ";

even though it only contains 68 characters (and PSR2 requires line lengths to be under 120 chars).

See AtomLinter/linter-phpcs#228 and AtomLinter/linter-phpcs#233 for possible fix. Those PRs got eventually reverted, since Atom's linter feeds the text to PHPCS via stdin, but they are are relevant for your project because you pass file paths to PHPCS.

@ikappas
Copy link
Owner

ikappas commented Feb 11, 2017

@weirdan Thank you for reporting this issue. I am trying to find a way to access the document encoding from vscode but have not found a solution yet. I will open a ticket with the language server guys and hope to resolve the issue.

@weirdan
Copy link
Author

weirdan commented Feb 11, 2017

And you're not alone, it seems: microsoft/vscode#824

@ikappas
Copy link
Owner

ikappas commented Feb 11, 2017

It seems that this can not go forward unless microsoft/vscode#824 is fixed.

@josenicomaia
Copy link

josenicomaia commented Aug 1, 2017

@ikappas Could not we just send an extra flag to phpcs? Something like:

settings.json

{
    ...
    "phpcs.encoding": "windows-1252"
    ...
}

command
phpcs --encoding=$ENCODING ...

@josenicomaia
Copy link

I added an PR to solve it.

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

No branches or pull requests

3 participants