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

Cannot use tilde (~) to refer to user home #353

Closed
antonioribeiro opened this issue Dec 9, 2014 · 8 comments
Closed

Cannot use tilde (~) to refer to user home #353

antonioribeiro opened this issue Dec 9, 2014 · 8 comments

Comments

@antonioribeiro
Copy link

You cannot run it this way:

phpcs -v --standard=~/.composer/vendor/pragmarx/laravelcs/Standards/Laravel ~/.composer/vendor/pragmarx/laravelcs/Standards/TestFiles/Filesystem.php

You have to do

phpcs -v --standard=$HOME/.composer/vendor/pragmarx/laravelcs/Standards/Laravel ~/.composer/vendor/pragmarx/laravelcs/Standards/TestFiles/Filesystem.php

Or

phpcs -v --standard=/home/antoniocarlos/.composer/vendor/pragmarx/laravelcs/Standards/Laravel ~/.composer/vendor/pragmarx/laravelcs/Standards/TestFiles/Filesystem.php
@aik099
Copy link
Contributor

aik099 commented Dec 9, 2014

Yes, using $HOME is right was to do it. I'm not sure in which cases Bash does expand ~ into HOME environment variable value.

This post explains in detail: http://stackoverflow.com/questions/3963716/how-to-manually-expand-a-special-variable-ex-tilde-in-bash

@gsherwood
Copy link
Member

I don't think home directory expansion is something PHP_CodeSniffer should be doing. It's something the shell should be doing, which actually works fine in my shell already.

@antonioribeiro
Copy link
Author

PHP_CodeSniffer is making use of realpath(), so it's already doing directory expansion, sir. And you might not be using the most used unix shell in the world: bash. But, of course, I respect your decision. Thank you.

@gsherwood
Copy link
Member

Comparing the use of realpath() and a custom tilde expansion isn't at all fair. If PHP had built-in cross-platform support for expanding ~ in the same way it expands . and .. then I'd be using it.

The thing I don't want to do is support custom expansions.

@gsherwood
Copy link
Member

I changed my mind after thinking about this a bit more. I think I was confusing the use of the '~' in the file path and the --standard argument, which is why it was working in bash for me. Sorry for closing this idea prematurely.

I've committed a change for this now and would love to know if it works for you. I've tested it both with standard paths passed on the command line and also in standards referenced from other rulesets. Any standard path in there that start with ~/ have the home dir added to them.

@aik099
Copy link
Contributor

aik099 commented Dec 10, 2014

Unfortunately on Windows the home folder detection is different. This method in Gush deals with OS inconsistencies: https://github.com/gushphp/gush/blob/59c0c913ab634b39f51438a9b850ec51605131d5/src/Factory.php#L25-L50

@antonioribeiro
Copy link
Author

@gsherwood master branch is working fine for me in an Ubuntu 14.04 using bash & zsh.

In my opinion, Windows should not be a concern in the tilde case, because that particular character means nothing on it. Those are tests using MSDOS and 4NT done here:

C:\>dir ~
 Volume in drive C is Windows 8
 Volume Serial Number is 927B-B925

 Directory of C:\

File Not Found
[D:\]dir ~

 Volume in drive D is Data           Serial number is EE01:B222
4NT: (Sys) The system cannot find the file specified.
 "D:\~"

@gsherwood
Copy link
Member

Yeah, I didn't expect the home dir expansion to mean anything in Windows and wasn't adding that feature for Windows users. Of course, Windows users could set a HOME env var if they wanted to.

Thanks for testing it @antonioribeiro

jrfnl pushed a commit to jrfnl/PHP_CodeSniffer that referenced this issue Jul 29, 2024
* Docs: add documentation for Squiz.WhiteSpace.ScopeClosingBrace

* Docs: improve documentation for Squiz.WhiteSpace.ScopeClosingBrace

- Fixup CDATA indentation
- Improve wording in code examples
- Add more varied code examples

* Docs: clarify wording and code samples for Squiz.WhiteSpace.ScopeClosingBrace

* Docs: combine code examples in Squiz.WhiteSpace.ScopeClosingBrace

Better illustrates that statements can be indented,
and that their closing braces still should align
with the start of the statement.

* Docs: improve examples for Squiz.WhiteSpace.ScopeClosingBrace

- Reduces wordiness
- Adds an example of too little whitespace

* Docs: add missing emphasis in Squiz.WhiteSpace.ScopeClosingBrace

* Docs: improve code examples for Squiz.WhiteSpace.ScopeClosingBrace

- Combine too little with too much whitespace
- Adjust emphasis on example containing PHP tags
- Change example paragraph to span for better HTML formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants