Nova

Extensions


Readme

PHP_CodeSniffer

PHP_CodeSniffer automatically lints all open PHP files using phpcs, then reports errors and warnings in Nova's Issues sidebar and the editor gutter.

PHP_CodeSniffer can fix issues discovered by phpcs automatically using phpcbf.

Screenshots

Requirements

PHP_CodeSniffer requires the following tools to be installed on your Mac:

The extension will do its best to find an installation of PHP_CodeSniffer on your system in the following order:

  1. Using the path you define in the extension's configuration
  2. Path to the default Composer installation; vendor/bin/phpcs and vendor/bin/phpcbf.
  3. Path to the default Phive installation; tools/bin/phpcs and tools/bin/phpcbf.
  4. Global installation; phpcs and phpcbf.

If the extension doesn't find an installation it will fall back to the version of PHP_CodeSniffer bundled with the extension. The bundled phpcs and phpcbf are currently at version 3.6.1.

The bundled PHP_CodeSniffer will not know how to locate any rulesets installed via Composer or Phive, so if you need to use phpcs rulesets installed via Composer or Phive make sure you use the same method to install PHP_CodeSniffer.

If you have a custom ruleset for phpcs somewhere that you'd like to use, you can choose to use that "standard" by setting the path in Project → Project Settings → PHP_CodeSniffer.

Since macOS Monterey PHP is no longer included in macOS. The easiest way I've found to install PHP is by using Homebrew.

Configuration

To configure global preferences, open Extensions → Extension Library → PHP_CodeSniffer then select PHP_CodeSniffer's Preferences tab.

You can also configure preferences on a per-project basis in Project → Project Settings → PHP_CodeSniffer.


Changelog

Version 1.4.1 - September 27, 2022

  • Fix - Format on save no longer misses changes when documents are saved.

Version 1.4.0 - September 26, 2022

  • Tweak - Update bundled phpcs version to v3.7.1.
  • Tweak - Update bundled phpcbf version to v3.7.1.
  • Add - Format on save.
  • Add - Available standards in workspace settings are now derived from the phpcs executable used.
  • Fix - Switching between running phpcs on save vs. on change now works without deactivating and then reactivating the extension.

Version 1.3.2 - September 12, 2022

  • Fix - PHPCBF config path is now retrieved using the right key.

Version 1.3.1 - November 24, 2021

  • Add - Donation link for Liberapay account.

Version 1.3.0 - November 23, 2021

  • Add - The extension will now underline the word where an issue is reported.
  • Add - The option to turn on debug logging. Very excessive, significantly slows down the extension.
  • Tweak - Updated the screenshot.

Version 1.2.4 - November 17, 2021

  • Fix - Handle an unhandled exception when an empty path is passed to the isFile helper function.
  • Tweak - Update extension README.
  • Add - An example screenshot to README.

Version 1.2.3 - November 9, 2021

  • Tweak - Update bundled phpcs version to v3.6.1.
  • Tweak - Update bundled phpcbf version to v3.6.1.
  • Tweak - Update extension description.
  • Tweak - Update readme.

Version 1.2.2 - April 26, 2021

  • Fix - Fallback path to phpcs now correctly falls back to phpcs instead of phpcbf.

Version 1.2.1 - March 17, 2021

  • Tweak - Update readme to reflect the changes introduced in v1.2.0.
  • Tweak - Update the description of some extension settings.
  • Tweak - Use the same default standard PHP_CodeSniffer uses, instead of defaulting to the WordPress standard.

Version 1.2.0 - March 17, 2021

  • Add - Bundle phpcs and phpcbf phar files with extension.
  • Tweak - Fall back to bundled phar files when no global/composer/phive installation detected.

Version 1.1.1 - March 12, 2021

  • Add - Link to mailing list for bug reports instead of my personal email.

Version 1.1.0 - March 11, 2021

  • Tweak - Provide free-form input for custom ruleset.
  • Fix - Issues are now indicated at the right column when indenting with tabs.
  • Add - Command for fixing issues with phpcbf.

Version 1.0.5 - February 24, 2021

  • Add - Support for a phpcs.xml.dist file for defining code sniffing rules.
  • Add - An error notification if phpcs fails to run.

Version 1.0.4

  • Add - Support for the Advanced PHP syntax extension.

Version 1.0.3

  • Fix - Progress and verbose output from phpcs is now suppressed correctly to prevent JSON parsing issues.

Version 1.0.2

  • Fix - List of available PHPCS styles not showing up in project preferences.

Version 1.0.1

  • Add option to choose whether to run phpcs on save or on change.

Version 1.0.0

Initial release.


License

MIT License

Copyright (c) 2020 Kristófer Reykjalín Þorláksson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.