diff --git a/Changelog.md b/Changelog.md index 16e3fb5..aa5db56 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,210 +1,213 @@ -CHANGELOG -========= +# CHANGELOG + +## 6.9.0 + +- Turn on tagging + +## 6.8.0 -6.8.0 ------ * Enhancement for allowing the configuration to use "~" which will be expanded out to your home directory. Thanks to [Quentin Dreyer](https://github.com/qkdreyer) for the [patch](https://github.com/benmatselby/sublime-phpcs/pull/169) -6.7.0 ------ +## 6.7.0 + * Enhancement for allowing the definition of a `phpcs.xml` in the root of the project. Thanks to [Jason Madrid](https://github.com/jasonmadrid) for the [patch](https://github.com/benmatselby/sublime-phpcs/pull/161) -6.6.3 ------ +## 6.6.3 + * Fix for [GH-100](https://github.com/benmatselby/sublime-phpcs/issues/100). Issues when opening Sublime Text when the last file was an image -6.6.2 ------ +## 6.6.2 + * Fix for [GH-155](https://github.com/benmatselby/sublime-phpcs/issues/155). --runtime-set not working correctly -6.6.1 ------ +## 6.6.1 + * Fix for [GH-129](https://github.com/benmatselby/sublime-phpcs/issues/129), which is the cbf not showing as enabled. -6.6.0 ------ +## 6.6.0 + * Support for PHP Code Beautifier and Fixer (phpcbf) [GH-127](https://github.com/benmatselby/sublime-phpcs/issues/127) -6.5.3 ------ +## 6.5.3 + * Fix for [GH-120](https://github.com/benmatselby/sublime-phpcs/issues/120). Thanks to [Hermann Herz](https://github.com/Heart1010) for raising this. -6.5.2 ------ +## 6.5.2 + * Fix for [GH-117](https://github.com/benmatselby/sublime-phpcs/issues/117). Thanks to [autumnlansing](https://github.com/autumnlansing) for raising. -6.5.1 ------ +## 6.5.1 + * Fix for [GH-113](https://github.com/benmatselby/sublime-phpcs/issues/113). Thanks to [Rafael Nascimento](https://github.com/Arcane07) for the patch. PHP-CS-Fixer not reporting outcome -6.5.0 ------ +## 6.5.0 + * Stylise the icon color [GH-114](https://github.com/benmatselby/sublime-phpcs/issues/114) -6.4.2 ------ +## 6.4.2 + * Bug fix for switching the coding standard when not using a project. * Set the default coding standard when the plugin is installed to PSR2. -6.4.1 ------ +## 6.4.1 + * Bug fix for switching the coding standard. It does not rely on php-cs-fixer path being set -6.4.0 ------ +## 6.4.0 + * Enhancement [GH-112](https://github.com/benmatselby/sublime-phpcs/issues/112). Ability to toggle the coding standard being used. -6.3.5 ------ +## 6.3.5 + * Enhancement: Always show php-cs-fixer support in context menu in side bar, just not enabled if php-cs-fixer is not configured [GH-103](https://github.com/benmatselby/sublime-phpcs/issues/103) -6.3.4 ------ +## 6.3.4 + * Fix for [GH-98](https://github.com/benmatselby/sublime-phpcs/issues/98) -6.3.3 ------ +## 6.3.3 + * Fix for [GH-93](https://github.com/benmatselby/sublime-phpcs/issues/93). If plugin is off, all sub processes should respect that. * Fix for [GH-94](https://github.com/benmatselby/sublime-phpcs/issues/94). Thanks to [WaveHack](https://github.com/WaveHack) for raising this and proposing a solution * Fix for [GH-91](https://github.com/benmatselby/sublime-phpcs/issues/91). Thanks to [Alex Russell](https://github.com/alexrussell) for proposing a solution * Fix for [GH-85](https://github.com/benmatselby/sublime-phpcs/issues/85). Thanks to [Peter Farsinsen](https://github.com/peterfarsinsen) for this patch -6.3.2 ------ +## 6.3.2 + * Minor enhancement to provide hint with configuration issue [GH-78](https://github.com/benmatselby/sublime-phpcs/issues/78) -6.3.1 ------ +## 6.3.1 + * Fix for ST2 which does not like trailing commas in the json. Fixes [GH-75](https://github.com/benmatselby/sublime-phpcs/pull/75) -6.3 ---- +## 6.3 + * Enhancement to toggle via the context menu or command palette if the plugin should execute on save or not [GH-73](https://github.com/benmatselby/sublime-phpcs/issues/73) * Enhancement to blacklist certain extensions if they form part of the main extensions to execute, the example being twig.php [GH-69](https://github.com/benmatselby/sublime-phpcs/issues/69) -6.2 ---- +## 6.2 + * Enhancement to support per project settings. Thanks to [Handrus Stephan Nogueira](https://github.com/handrus) for the contribution * Enhancement to reload the settings when changed, so you do not have to restart Sublime Text each time. -6.1 ---- +## 6.1 + * Bug fix for users of ST2 and PHP_CodeSniffer1.5.0 (Currently RC1). Essentially we now need to pass cwd so that PHP_CodeSniffer knows where to put the tmp files for its caching mechanism. Fixes [GH-68](https://github.com/benmatselby/sublime-phpcs/issues/68) -6.0.1 ------ +## 6.0.1 + * Missed a s/SCheck/scheck/ conversion -6.0 ---- +## 6.0 + * Add support for [scheck](https://github.com/facebook/pfff/wiki/Main). Thanks to [Darby Payne](https://github.com/dpayne) for this patch -5.1.1 ------ +## 5.1.1 + * Minor patch to scrub the last report so the points and line numbers are correct each time. Fixes GH-67 -5.1 ---- -* Only run commands if the *_run preferences are true. Thanks to [Rys Sommefeldt](https://github.com/rys) for this patch. +## 5.1 + +* Only run commands if the _run preferences_ are true. Thanks to [Rys Sommefeldt](https://github.com/rys) for this patch. + +## 5.0 -5.0 ---- * Support for Sublime Text 3 [GH-60](https://github.com/benmatselby/sublime-phpcs/issues/60) -4.6.3 ------ +## 4.6.3 + * Patch to fix [GH-53](https://github.com/benmatselby/sublime-phpcs/issues/53) which was php-cs-fixer executing on save for non plugin based files (e.g. running for a python file). Thanks to [John Hoffmann](https://github.com/jhoffmann) for the solution. * Minor update to the README to cover off a gotcha on installing php-cs-fixer using Homebrew [GH-52](https://github.com/benmatselby/sublime-phpcs/issues/52) -4.6.2 ------ +## 4.6.2 + * Small patch to fix [GH-51](https://github.com/benmatselby/sublime-phpcs/issues/51). Thanks to [mstaatz](https://github.com/mstaatz) for raising the issue. -4.6.1 ------ +## 4.6.1 + * Provided configuration option "phpcs_commands_to_php_prefix" that allows you to distinguish which commands should have the php path prefixed. Thanks to [Hamrani ahmed](https://github.com/ahamrani) for raising [GH-49](https://github.com/benmatselby/sublime-phpcs/issues/49) -4.6 ---- +## 4.6 + * Fixes for windows based users and the use of phar files. Thanks to [Hamrani ahmed](https://github.com/ahamrani) for raising [GH-47](https://github.com/benmatselby/sublime-phpcs/issues/47) * Moved the options to the end of the php-cs-fixer command as per their documentation examples * Removed reloading settings code, as it seems redundant in latest build of Sublime Text 2 -4.5.1 ------ +## 4.5.1 + * Minor changes to the README to better explain non package control installation. * Minor change to README for naming of the plugin * Minor change to when the "Goto Next Error" context menu is enabled -4.5 ---- +## 4.5 + * Define a setting "php_cs_fixer_show_quick_panel" that stops quick panel displaying for php-cs-fixer. Thanks to [Kevin Perrine](https://github.com/kevinsperrine/) for the pull request -4.4.1 ------ +## 4.4.1 + * Blank out the default setting for php_cs_fixer_executable_path. Thanks to [Eric Lewis](https://github.com/ericandrewlewis/) for the pull request. -4.4 ---- +## 4.4 + * Provide configuration options for each command to execute on save. Thanks to [Jeremy Romey](https://github.com/jeremyFreeAgent) for the [suggestion](https://github.com/benmatselby/sublime-phpcs/issues/36) -4.3 ---- +## 4.3 + * Ehancement for [GH-34](https://github.com/benmatselby/sublime-phpcs/issues/34) which provides a command to "Goto Next Error" which can also have a shortcut key assigned to it. Thanks to [Casey Becking](https://github.com/caseybecking) for raising the feature request * Ability to fun PHP-CS-Fixer on save now. Thanks to [Cedric Lombardot](https://github.com/cedriclombardot) for raising the feature request -4.2 ---- +## 4.2 + * Ability to configure if you want the errors to be highlighted in the editor. Thanks to [Aleksandr Gornostal](https://github.com/gornostal) -4.1.1 ------ +## 4.1.1 + * Small patch to be consistent with the naming of the tools. Thanks to [Beau Simensen](https://github.com/simensen) -4.1 ---- +## 4.1 + * Added support to use php-cs-fixer on a directory in the side bar * Now displays the php-cs-fixer changes in the quick panel -4.0 ---- +## 4.0 + * Added basic support for [php-cs-fixer](https://github.com/fabpot/PHP-CS-Fixer) based on the work by [Jeremy Romey](https://github.com/jeremyFreeAgent/sublime-php-cs-fixer/) -3.13 ----- +## 3.13 + * Setting to configure if phpcs is run when the plugin is invoked [GH-20](https://github.com/benmatselby/sublime-phpcs/issues/20). Thanks to [grEvenX](https://github.com/grEvenX) -3.12 ----- +## 3.12 + * Bug fix for [GH-18](https://github.com/benmatselby/sublime-phpcs/issues/18) which meant the plugin would fail to work when coming across non ascii characters * Added a show_debug setting for console output. Off by default -3.11 ----- +## 3.11 + * Support added to configure the php path [GH-16](https://github.com/benmatselby/sublime-phpcs/issues/16). Thanks to [Dan Previte](https://github.com/dprevite) * Added support for multiple file extensions, rather than using Sublimes syntax checker [GH-15](https://github.com/benmatselby/sublime-phpcs/issues/15) -3.10 ----- +## 3.10 + * Bug fix for [GH-13](https://github.com/benmatselby/sublime-phpcs/issues/13) which seems to be apparent when Sublime cannot find/load the settings file -3.9 ---- +## 3.9 + * Bug fix for [GH-12](https://github.com/benmatselby/sublime-phpcs/issues/12) * Bug fix for incorrectly mismatching sublime line numbers to line numbers from a report *if* there was only one error reported * Updated name of change log -3.8 ---- +## 3.8 + * Support added for running [phpmd](http://phpmd.org/) - Currently off by default -3.7 ---- +## 3.7 + * Updated Main.sublime-menu so we can change the key bindings from within the Preferences panel -3.6 ---- +## 3.6 + * Added the ability to show previous errors without generating the report again. Thanks to [Drarok](https://github.com/Drarok) [GH-9](https://github.com/benmatselby/sublime-phpcs/pull/9) * Put the processing back to being threaded which helps with large files. Thanks to [Drarok](https://github.com/Drarok) [GH-10](https://github.com/benmatselby/sublime-phpcs/pull/10) * Removed Side Bar Menu, as it doesn't make sense to run report against a non-open file @@ -212,50 +215,50 @@ CHANGELOG * Added "Show previous errors" to the context menu to be consistent * Added keymap for Mac OSX, cannot get the keys right when using Virtual Box to define for Windows and Linux, so leaving for the time being -3.5 ---- +## 3.5 + * Ability to show the errors in the status bar (configurable with on/off setting). Thanks to [Drarok](https://github.com/Drarok) * Bug fix with clearing the sniffer marks -3.4 ---- +## 3.4 + * Ability to not show the quick_panel errors on save, (errors shown by default). Thanks to [Drarok](https://github.com/Drarok) -3.3 ---- +## 3.3 + * Allow the user to specify the location of the phpcs application [GH-4](https://github.com/benmatselby/sublime-phpcs/issues/4) * Turned the linter checks on by default -3.2 ---- +## 3.2 + * Added the ability to run the PHP linter alongside the PHP_CodeSniffer * You can specify if you want the linter to run * You can specify the regex of the linter output, as it seems to differ on different systems -3.1 ---- +## 3.1 + * Updated the loading of settings to use static method * Updated the debugging calls to prefix with "Phpcs" * Added a counter of errors in the console log -3.0 ---- +## 3.0 + * Enables the plugin to work on the Windows platform [GH-1](https://github.com/benmatselby/sublime-phpcs/issues/1) * Removed some redundant code -2.0 ---- +## 2.0 + * Changed the way the checkstyle report was parsed. due to [GH-2](https://github.com/benmatselby/sublime-phpcs/issues/2) which means it should now work on Linux machines -1.1 ---- +## 1.1 + * Load the settings into memory if changed using _settings.add_on_change_. This only works on User settings rather than defaults, which is a limitation of the API from what I can see at the moment. * Define the coding standard as PEAR by default. * Introduced this Changelog.md file. * Raised [this feature request](http://sublimetext.userecho.com/topic/96221-gutter-hint-bubles-when-hovered-over/) so I can show tool tips in the gutter for each checkstyle error/warning -1.0 ---- +## 1.0 + * Initial release documented [here](http://soulbroken.co.uk/code/sublimephpcs) * Right click on a php file and generate checkstyle report in the gutter and/or quick panel * Settings to turn the reporting on/off for gutter and quick panel diff --git a/README.md b/README.md index 34eedf2..bd12736 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,202 @@ -sublime-phpcs -============= +# sublime-phpcs -This plugin adds PHP CodeSniffer, PHP Code Beautifier and Fixer, PHP Coding Standards Fixer, the PHP Linter, PHP Mess Detector, Scheck support to Sublime Text. +This is a plugin for Sublime Text which provides checkstyle reports using the following tools (all optional): -For more information about this plugin such as features, installation requirements etc, please click [here](https://benmatselby.dev/sublime-phpcs/#configuration) +- PHP_CodeSniffer (`phpcs`) +- Linter (`php -l`) +- PHP Mess Detector (`phpmd`) +- Scheck (`scheck`, part of Facebook’s pfff toolchain) -Configuration -------------- +You can also configure the plugin to fix the issues using either -**You will need to configure this plugin to work for your setup**, please view the options [here](https://benmatselby.dev/sublime-phpcs/#configuration) +- PHP Coding Standards Fixer (php-cs-fixer) +- PHP Code Beautifier (phpcbf) application +## Requirements -FAQ ---- +Requirements for this plugin, should you want all the options to work: + +- PHP_CodeSniffer 3.5+ (potentially works with lower versions, but this hasn’t been tested) - Install +- PHPMD 2.8+ (potentially works with lower versions, but this hasn’t been tested) - Install +- PHP CS Fixer version 2.6+ (potentially works with lower versions, but this hasn’t been tested) - Install + +This plugin has been tested on: + +- Mac OS X 10.8.2 +- Ubuntu 11.10 +- Windows 7 +- Sublime Text 2 +- Sublime Text 3 +- Sublime Text 4 + +## Installation + +Use Sublime Text’s Package Control (Tools -> Command Palette -> Package Control: Install Package -> Phpcs) to install this plugin. This is the recommended installation path. + +Or + +Simply checkout the git repo into “~/Library/Application Support/Sublime Text/Packages/ or the equivalent folder on Windows or Linux. + +```shell +cd ~/Library/Application\ Support/Sublime\ Text/Packages/ +git clone git://github.com/benmatselby/sublime-phpcs.git Phpcs +``` + +In both cases, you may need to then configure the following with the actual path to the application: + +- “phpcs_php_path” +- “phpcs_executable_path” +- “phpmd_executable_path” +- “php_cs_fixer_executable_path” + +They are optional for the plugin. The path needs to include the application such as `/usr/local/bin/phpcs`. + +In order to get the path of the application (On a Mac/Linux based environment), you can use: + +```shell +which phpcs +which phpmd +which php-cs-fixer +which phpcbf +``` + +## Features + +- Ability to run PHP_CodeSniffer +- Ability to run php -l on the open file +- Ability to run PHP Mess Detector on the open file +- Ability to run Scheck on the open file +- Show cached results from PHP_CodeSniffer in open file +- Show errors in the Quick Panel +- Show errors in the Gutter +- Highlight the errors in the editor +- Show the error for a given line in the status bar +- Ability to specify the regular expression of the linter errors +- Ability to specify the location of the PHP_CodeSniffer application +- Ability to specify the location of the PHP Mess Detector application +- Ability to run the PHP Coding Standards Fixer tool which fixes most issues in your code when you want to follow the PHP coding standards as defined in the PSR-1 and PSR-2 documents +- Ability to run the PHP Code Beautifier tool which fixes most issues in your code when you want to follow PHP coding standards + +Once you have right clicked on a file and selected “PHP CodeSniffer” > “Sniff this file…” you will get the output as shown below (depending on the settings you have defined): + +## Configuration + +You can also define the configuration for the following settings, be it for a project, user settings or the default settings: + +### Plugin + +- `show_debug` – Do you want the debug information to be sent to the console? +- `extensions_to_execute` – Which filetypes do you want the plugin to execute for? +- `extensions_to_blacklist` – Override the extensions_to_execute in case you have a sub extension such as twig.php etc. +- `phpcs_execute_on_save` – Do you want the code sniffer plugin to run on file save for php files? +- `phpcs_show_errors_on_save` – Do you want the errors to be displayed in quick_panel on save? +- `phpcs_show_gutter_marks` – Do you want the errors to be displayed in the gutter? +- `phpcs_outline_for_errors` – Do you want the errors to be highlighted in the editor? +- `phpcs_show_errors_in_status` – Do you want the errors to be displayed in status bar when clicking on the line with error? +- `phpcs_show_quick_panel` – Do you want the errors to be displayed in the quick panel? +- `phpcs_php_prefix_path` – Needed on windows for phar based applications. Also if you cannot make phar executable. Avoid if possible +- `phpcs_commands_to_php_prefix` – List of commands you want the php path to prefix. This would be useful, if you have some commands as a phar that cannot be run without the php prefix, and others using native command. +- `phpcs_icon_scope_color` - What colour to stylise the icon. This needs knowledge of theming of Sublime Test, as it uses scope colours from the theme to “tint” the dot icon. See here + +### PHP_CodeSniffer + +- `phpcs_sniffer_run` – Do you want the PHPCS checker to run? +- `phpcs_command_on_save` – Do you want the command to execute on save? +- `phpcs_executable_path` – The path to the phpcs executable. If empty string, use PATH to find it +- `phpcs_additional_args` – This is the extra information you want to pass to the phpcs command. For example which “standard” you want to run, and if you want to show warnings or not + +### PHP CodeSniffer Fixer + +- `php_cs_fixer_on_save` – Do you want to run the fixer on file save? +- `php_cs_fixer_show_quick_panel` – Do you want the quick panel to display on execution? +- `php_cs_fixer_executable_path` – The path to the php-cs-fixer application. +- `php_cs_fixer_additional_args` – This is the extra information you want to pass to the php-cs-fixer command. For example which “fixers” you want to run + +### PHP Code Beautifier + +- `phpcbf_on_save` – Do you want to run the fixer on file save? +- `phpcbf_show_quick_panel` – Do you want the quick panel to display on execution? +- `phpcbf_executable_path` – The path to the phpcbf application. +- `phpcbf_additional_args` – This is the extra information you want to pass to the phpcbf command. For example which “standard” to use in order to fix the issues + +### PHP Linter + +- `phpcs_linter_run` – Do you want the PHP linter to run? +- `phpcs_linter_command_on_save` – Do you want the command to execute on save? +- `phpcs_php_path` – The path to the PHP executable. If empty string, use PATH to find it +- `phpcs_linter_regex` – The regex for the PHP linter output + +### PHP Mess Detector + +- `phpmd_run` – Do you want the PHPMD to run? Off by default +- `phpmd_command_on_save` – Do you want the command to execute on save? +- `phpmd_executable_path` – The path to the phpmd executable. If empty string, use PATH to find it +- `phpmd_additional_args` – This is the extra information you want to pass to the phpmd command. For example which “rulesets” you want to run + +### Scheck + +- `scheck_run` - Do you want the scheck application to run? Off by default +- `scheck_command_on_save` - Do you want the command to execute on save? +- `scheck_executable_path` - The path to the scheck executable. If empty string, use PATH to find it +- `scheck_additional_args` - This is the extra information you want to pass to the scheck command. + Examples of the settings files can be found here + +### Project Based Settings + +Your .project file should look something like this: + +```json +{ + "folders": [{}], + "settings": { + "phpcs": { + "phpcs_additional_args": { + "--standard": "/path/to/.composer/vendor/drupal/coder/coder_sniffer/Drupal" + } + } + } +} +``` + +Of course this is a example to apply Drupal code sniffer. This could be anything. Whatever you can have on this package settings it can be overwritten under the settings -> phpcs + +## FAQ ### What do I do when I get "OSError: [Errno 8] Exec format error"? -* This seems to be an issue you may get with regards to wrapper scripts. -* Please make sure that the application/script you are referencing has the correct shebang line, as per [GH-79](https://github.com/benmatselby/sublime-phpcs/issues/79) +- This seems to be an issue you may get with regards to wrapper scripts. +- Please make sure that the application/script you are referencing has the correct shebang line, as per [GH-79](https://github.com/benmatselby/sublime-phpcs/issues/79) ### What do I do when I get "OSError: [Error 2] No such file or directory"? -* Well, first of all you need to check that you have PHP_CodeSniffer, and if being used, the phpmd application. -* If you have these applications installed, then it sounds like those applications are not in your PATH, or cannot be found in your PATH by the Python runtime, so configure "phpcs_php_path", "phpcs_executable_path", "phpmd_executable_path" and "php_cs_fixer_executable_path" with the actual paths to those applications +- Well, first of all you need to check that you have PHP_CodeSniffer, and if being used, the phpmd application. +- If you have these applications installed, then it sounds like those applications are not in your PATH, or cannot be found in your PATH by the Python runtime, so configure "phpcs_php_path", "phpcs_executable_path", "phpmd_executable_path" and "php_cs_fixer_executable_path" with the actual paths to those applications ### What do I do when I get "OSError: [Errno 13] Permission denied"? -* It sounds like your path settings are incorrect. -* You need to make sure that when you specifiy the path you include the entire path including the application +- It sounds like your path settings are incorrect. +- You need to make sure that when you specifiy the path you include the entire path including the application -``` +```shell $ which phpcs /usr/local/bin/phpcs ``` -* That entire output is the path you need in your configs. +- That entire output is the path you need in your configs. ### What if I've installed the applications using Homebrew? -If you have installed php-cs-fixer, phpmd or phpcs via homebrew then please make sure that you define the "*_executable_path" option to the .phar application and not the wrapper script that is placed in your bin folder, as this will cause odd behaviour. +If you have installed php-cs-fixer, phpmd or phpcs via homebrew then please make sure that you define the "_\_executable_path_" option to the .phar application and not the wrapper script that is placed in your bin folder, as this will cause odd behaviour. ### What other Key Bindings can I setup? The following is a list of commands that you can bind to a keyboard shortcut: -* phpcs_fix_this_file -* phpcs_clear_sniffer_marks -* phpcs_goto_next_error -* phpcs_show_previous_errors -* phpcs_sniff_this_file +- phpcs_fix_this_file +- phpcs_clear_sniffer_marks +- phpcs_goto_next_error +- phpcs_show_previous_errors +- phpcs_sniff_this_file In order to achieve this you need to add the following to one of your key bindings settings file: