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

Working with project dependencies #1

Closed
swashata opened this issue Jan 7, 2019 · 7 comments
Closed

Working with project dependencies #1

swashata opened this issue Jan 7, 2019 · 7 comments

Comments

@swashata
Copy link

swashata commented Jan 7, 2019

Hello,

First of all, thank you very much for this extension. I really appreciate the time and effort you've put behind this. Kudos.

So I am trying to switch over from vscode-phpcs extension. I have phpcs installed as my project dependency. My composer.json is something like this

{
	"require": {},
	"require-dev": {
		"squizlabs/php_codesniffer": "3.3.1",
		"wp-coding-standards/wpcs": "1.0.0",
		"wimg/php-compatibility": "8.2.0",
		"dealerdirect/phpcodesniffer-composer-installer": "0.4.4",
		"giacocorsiglia/wordpress-stubs": "^4.9"
  }
}

And I have a phpcs.xml file in the root of my project/repo.

<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">
	<description>Generally-applicable sniffs for WordPress plugins</description>

	<rule ref="WordPress-Core">
		<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase"/>
		<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned"/>
		<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning"/>
		<exclude name="WordPress.PHP.YodaConditions"/>
	</rule>

	<rule ref="WordPress.WP.I18n">
		<properties>
			<property name="text_domain" type="array" value="ipt_fsqm" />
		</properties>
	</rule>
	<rule ref="WordPress.Files.FileName">
		<properties>
			<property name="strict_class_file_names" value="false" />
		</properties>
	</rule>
	<rule ref="WordPress.NamingConventions.ValidVariableName">
		<properties>
			<property name="customPropertiesWhitelist" type="array" value="myMixedCasePropery,AnotherMixedCaseProperty" />
		</properties>
	</rule>
	<rule ref="WordPress.Arrays.MultipleStatementAlignment">
		<properties>
			<property name="exact" value="false" />
		</properties>
	</rule>
	<rule ref="Generic.Formatting.MultipleStatementAlignment">
		<properties>
			<property name="maxPadding" value="10" />
		</properties>
	</rule>

	<rule ref="WordPress-Docs">
		<exclude name="Squiz.Commenting.InlineComment.InvalidEndChar"/>
		<exclude name="Squiz.PHP.CommentedOutCode"/>
		<exclude-pattern>*/tests/phpunit/*</exclude-pattern>
	</rule>

	<rule ref="WordPress-Docs">
		<exclude name="Squiz.Commenting.FileComment.Missing"/>
		<exclude name="Squiz.Commenting.FunctionComment.Missing"/>
		<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop"/>
	</rule>


	<!-- Check all PHP files in directory tree by default. -->
	<arg name="extensions" value="php"/>
	<file>.</file>

	<!-- Show sniff codes in all reports -->
	<arg value="s"/>

	<!-- PHPCompatibility -->
	<config name="testVersion" value="5.6-7.2"/>
	<rule ref="PHPCompatibility"/>

	<exclude-pattern>*/node_modules/*</exclude-pattern>
	<exclude-pattern>*/vendor/*</exclude-pattern>
	<exclude-pattern>*/bower_components/*</exclude-pattern>
	<exclude-pattern>*/dist/*</exclude-pattern>
</ruleset>

Within vscode preference, I have set the following to tell the extension about phpcs path.

{
    "phpSniffer.executablesFolder": "${workspaceFolder}/vendor/bin/"
}

PS: I do have the trailing slash added, but still nothing really happens.

But nothing really happens. I am not sure how the extension is supposed to work. I assumed, it would show lint errors when I open a file? I can confirm phpcs itself works because if I run

./vendor/bin/phpcs somefile.php

It works just fine. Am I missing something? Please let me know.

@swashata
Copy link
Author

swashata commented Jan 7, 2019

I also realize that ${workspaceFolder} may not work for vscode settings. So I have set the following, yet no result :(

{
  "phpSniffer.executablesFolder": "./vendor/bin/",
  "phpSniffer.standard": "./phpcs.xml"
}

@swashata
Copy link
Author

swashata commented Jan 7, 2019

Ok, it looks like both the above settings require absolute path. So when I changed

{
  "phpSniffer.executablesFolder": "/Volumes/Development/vagrant/www/eform/public_html/wp-content/plugins/wp-fsqm-pro/vendor/bin/",
  "phpSniffer.standard": "/Volumes/Development/vagrant/www/eform/public_html/wp-content/plugins/wp-fsqm-pro/phpcs.xml"
}

It started working. Maybe you can consider this a feature request? I will try to add this in a fork and get back to you.

@wongjn
Copy link
Owner

wongjn commented Jan 7, 2019

I think passing the workspace folder as the CWD to the command execution might work.

@swashata
Copy link
Author

swashata commented Jan 7, 2019

Yes, that should definitely do. If someone is passing in absolute path, then the CWD wouldn't matter anyway.

@wongjn wongjn closed this as completed in ec9c723 Jan 8, 2019
@elvishp2006
Copy link

I'm having the same problem, but my php is running inside a docker container, I have a /usr/bin/php that looks like this:

#!/bin/bash

docker exec \
    -it \
    -u $(id -u) \
    -w "$PWD" \
    php7 \
    php "$@"

@wongjn
Copy link
Owner

wongjn commented Jan 10, 2019

Are you running the latest version of the extension?
What is the command to run phpcs with PHP in docker?
Could you provide the settings you are using?

@elvishp2006
Copy link

Yes, I'm using the latest version of the extension.
I got a script on my composer.json:

  "scripts": {
    "lint": "phpcs",
    "lint:fix": "phpcbf"
  }

I just need to run composer lint to run my phpcs.

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

No branches or pull requests

3 participants