-
Notifications
You must be signed in to change notification settings - Fork 56
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
adding phpcbf support #28
Comments
@sataris I haven't considered adding Our team uses it frequently from the command line before pushing code to the repository potentially fixing simple issues that we neglected. We've actually incorporated "scripts": {
"run-phpcs": [
"@run-phpcs:stack",
"@run-phpcs:plugin",
"@run-phpcs:theme"
],
"run-phpcs:stack": [
"\"vendor/bin/phpcs\" --standard=ruleset.xml --extensions=php -p -n -s --colors ."
],
"run-phpcs:plugin": [
"\"vendor/bin/phpcs\" --standard=./web/app/plugins/demo/ruleset.xml --extensions=php -p -n -s --colors ./web/app/plugins/demo/"
],
"run-phpcs:theme": [
"\"vendor/bin/phpcs\" --standard=./web/app/themes/demo/ruleset.xml --extensions=php -p -n -s --colors ./web/app/themes/demo/"
],
"fix-phpcs": [
"@fix-phpcs:stack",
"@fix-phpcs:plugin",
"@fix-phpcs:theme"
],
"fix-phpcs:stack": [
"\"vendor/bin/phpcbf\" --standard=ruleset.xml --extensions=php -n ."
],
"fix-phpcs:plugin": [
"\"vendor/bin/phpcbf\" --standard=./web/app/plugins/demo/ruleset.xml --extensions=php -n ./web/app/plugins/demo/"
],
"fix-phpcs:theme": [
"\"vendor/bin/phpcbf\" --standard=./web/app/themes/demo/ruleset.xml --extensions=php -n ./web/app/themes/demo/"
]
}, So we can also easily run these tasks in the command line like: $ composer fix-phpcs:plugin But I've come across many cases where it failed to parse files so I don't know if implementing this in vs code would be consistent. How do you use |
@ikappas in fact, i hope we can use phpcbf to fix the page i just edit, because sometime we found a page have many issues to fix, and i have to open terminal and copy the path to fix it, i think it's complex sometime, so i hope i can type some command like format code, and it can auto fix this page or this project problem. |
+1 for phpcbf support. The way I would like to see it supported is that the plugin would run phpcbf on the currently open file in vscode when I save the file. That way it could quickly fix simple formatting errors I missed and then still review the changes. |
I was hoping that VSCode's "Format Document" command would simply respect the phpcs settings for a php file. That'd be incredible. If it's not possible or desirable to hook into that command, perhaps a simple new command that would attempt phpcbf on the current file, named "Format Document with PHPCS" or some such. |
A quick snippet for
Of course the feature request here would be the nicety of pulling |
I just released vscode-phpcbf |
The extension by @soderlind works well! It's a working example of having the command fix the current file, and registering a formatter to hook into vscode's formatOnSave and right-click "format file" options. It'd be nice to see that folded into this extension, so that the work of finding the executable, and setting configurations etc, could be shared work. |
@soderlind Now that 1.0.0 is out we can merge phpcbf support in. What do you think? |
@ikappas I you mean adding support for phpcbf in your plugin, please do. I'll discontinue my plugin if you add phpcbf to vscode-phpcs :) |
@soderlind Care to do an MR? |
@WraithKenny Care to do it ? I'm very busy atm. |
@soderlind Yes, I'm pretty busy too, but I can take a stab at this I think! (Probably over the next weekend or two.) |
@WraithKenny Any progress in this feature? |
No, it kinda fell off my radar. Sorry about not that |
@soderlind sadly phpcbf extension doesn't work for me. |
The following VS Code extension has both the linter (phpcs) and the fixer (phpcbf): The fixer is run every time you use the "Format document" and "Format selection" commands. Cheers |
@WraithKenny I took the burden on me (that was no fun at all) and brew something like this: {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Check PHP 7.3 compatibility",
"type": "process",
"linux": {
"options": {
"env": {
"LANG": "C"
}
}
},
"group": "build",
"presentation": {
"revealProblems": "onProblem",
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "shared",
"showReuseMessage": false,
"clear": true
},
"command": "./vendor/bin/phpcs",
"args": [
"--standard=PHPCompatibilityWP",
"--runtime-set",
"testVersion",
"7.3",
"--report=checkstyle",
"${file}"
],
"isBackground": false,
"problemMatcher": [
{
"owner": "php",
"fileLocation": "absolute",
"severity": "error",
"pattern": [
{
"regexp": "^<file name=\"(.*)\">$",
"file": 1
},
{
"regexp": "<error line=\"(\\d*)\" column=\"(\\d*)\" severity=\"(error)\" message=\"(.*)\" source=\"(.*)(\"\\/>+)$",
"line": 1,
"column": 2,
"severity": 3,
"message": 4,
"code": 5,
"loop": true
}
]
},
{
"owner": "php",
"fileLocation": "absolute",
"severity": "warning",
"pattern": [{
"regexp": "^<file name=\"(.*)\">$",
"file": 1
},
{
"regexp": "<error line=\"(\\d*)\" column=\"(\\d*)\" severity=\"(warning)\" message=\"(.*)\" source=\"(.*)(\"\\/>+)$",
"line": 1,
"column": 2,
"severity": 3,
"message": 4,
"code": 5,
"loop": true
}
]
}
]
}
]
} The most important part is argument I wrote this {
"require-dev": {
"squizlabs/php_codesniffer": "^3.4",
"wp-coding-standards/wpcs": "^2.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"phpcompatibility/phpcompatibility-wp": "*"
}
} |
Shouldn't you be able to use this?
|
Are there any plans to implement phpcbf support?
The text was updated successfully, but these errors were encountered: