1.简介

Package Control Messages

PHP_CodeSniffer是PEAEscort中的贰个用PHP5写的用来检查和嗅探PHP代码是不是有违背一组预先安装好的编码标准的一个包,它是保险您的代码简洁一致的必备的开垦工具,乃至还是能够扶助技术员减弱一些语义错误。

========================

PHP_CodeSniffer中的编码标准是一组嗅探文件的集合,每三个嗅探文件只检查一部分编码规范。一回安装就能够落成四个不等类别的编码规范的自我斟酌。PHP_CodeSniffer使用的暗中同意的编码标准是
PEAMurano编码典型。

CodeFormatter

2.安装


高效安装(需求先安装php和pear)

  Thanks for installing Sublime CodeFormatter! Below are some quick
notes to get you

pear install PHP_CodeSniffer

  started with the plugin.

行使sublime
text的同桌可以直接设置插件phpcs,安装格局(Ctrl+Shift+P->pi(package
install)->phpcs,安装成功后右键就能够看到PHP Code Sniffer选项)
Pyrus安装

  CodeFormatter

php pyrus.phar install pear/PHP_CodeSniffer

  =============

3.查看安装

  CodeFormatter is a Sublime Text 2/3 plugin that supports format
(beautify) source code.

[root@vb002 ~]# /usr/local/php/bin/phpcs -i
The installed coding standards are PSR1, Squiz, PHPCS, MySource, PEAR,
Zend and PSR2

  CodeFormatter has support for the following languages:

4.检查代码

  * PHP – By phpfmt

[root@vb002 ~]# /usr/local/php/bin/phpcs
/root/.jenkins/jobs/zentaotest/workspace/src/Money.php

  * JavaScript/JSON – By JSBeautifier

FILE: /root/.jenkins/jobs/zentaotest/workspace/src/Money.php

  * HTML – By JSBeautifier

FOUND 6 ERRORS AFFECTING 6 LINES

  2 | ERROR | Missing file doc comment
  3 | ERROR | Missing class doc comment
  5 | ERROR | Private member variable “amount” must be prefixed with
    |       | an underscore
  7 | ERROR | Missing function doc comment
 12 | ERROR | Missing function doc comment

  * CSS – By JSBeautifier

 17 | ERROR | Missing function doc comment

Time: 29ms; Memory: 3Mb

5.卸载安装

[root@vb002 ~]# pear uninstall PHP_CodeSniffer-2.3.3

6.选用示例

想要检查有些文件是不是适合PEA汉兰达编码标准, 只需求钦赐文件的路子就可以:

使用PHP_CodeSniffer检查文件

$ phpcs /path/to/code/myfile.php

FILE: /path/to/code/myfile.php


FOUND 5 ERROR(S) AFFECTING 2 LINE(S)


2 | ERROR | Missing file doc comment

20 | ERROR | PHP keywords must be lowercase; expected “false” but found
“FALSE”

47 | ERROR | Line not indented correctly; expected 4 spaces but found
1

51 | ERROR | Missing function doc comment

88 | ERROR | Line not indented correctly; expected 9 spaces but found
6


或然,假诺你想要检查整个目录,你能够钦赐目录路线实际不是文件路线:

使用PHP_CodeSniffer检查目录

$ phpcs /path/to/code

FILE: /path/to/code/myfile.php


FOUND 5 ERROR(S) AFFECTING 5 LINE(S)


2 | ERROR | Missing file doc comment

20 | ERROR | PHP keywords must be lowercase; expected “false” but found
“FALSE”

47 | ERROR | Line not indented correctly; expected 4 spaces but found
1

51 | ERROR | Missing function doc comment

88 | ERROR | Line not indented correctly; expected 9 spaces but found
6


FILE: /path/to/code/yourfile.php


FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)


21 | ERROR   | PHP keywords must be lowercase; expected “false” but
found

|         | “FALSE”

21 | WARNING | Equals sign not aligned with surrounding assignments


  * SCSS – By Nishutosh Sharma

  * Python – By PythonTidy (only ST2)

  * Visual Basic/VBScript

  Sponsors

  —–

  No sponsors yet.. 🙁

  If you like the software, don’t forget to donate to further
development of it!

  [![PayPal donate
button](
to Sublime Text – CodeFormatter&item_number=1&no_shipping=1 “Donate to
this project using Paypal”)

  Installing

  ———-

  **With the Package Control plugin:** The easiest way to install
CodeFormatter is through Package Control, which can be found at this
site:

  Once you install Package Control, restart Sublime Text and bring up
the Command Palette (`Command+Shift+P` on OS X, `Control+Shift+P` on
Linux/Windows). Select “Package Control: Install Package”, wait while
Package Control fetches the latest package list, then select
CodeFormatter when the list appears. The advantage of using this method
is that Package Control will automatically keep CodeFormatter up to date
with the latest version.

  **Without Git:** Download the latest source from
[GitHub]() and
copy the CodeFormatter folder to your Sublime Text “Packages” directory.

  **With Git:** Clone the repository in your Sublime Text “Packages”
directory:

      git clone

CodeFormatter

  The “Packages” directory is located at:

  * OS X:

          ST2: ~/Library/Application Support/Sublime Text 2/Packages/

          ST3: ~/Library/Application Support/Sublime Text 3/Packages/

  * Linux:

          ST2: ~/.config/sublime-text-2/Packages/

          ST3: ~/.config/sublime-text-3/Packages/

  * Windows:

          ST2: %APPDATA%/Sublime Text 2/Packages/

          ST3: %APPDATA%/Sublime Text 3/Packages/

  ## Formatter-specific notes

  Following are notes specific to individual formatters that you should
be aware of:

  ### PHP

  PHP – Used phpfmt () by Carlos Cirello
and Shaked Klein Orbach.

  Getting and installing PHP –

  You must install 5.6 or above

  On Linux/OSx after installation of package, you must set chmod +x to
file fmt.phar in folder
%PACKAGESDIR%/CodeFormatter/codeformatter/lib/phpbeautifier

  You can list all available transformations from Command Palette:
CodeFormatter: Show PHP Transformations

  Language specific options:

  “`js

    “codeformatter_php_options”:

      {

          “syntaxes”: “php”, // Syntax names which must process PHP
formatter

          “php_path”: “”, // Path for PHP executable, e.g.
“/usr/lib/php” or “C:/Program Files/PHP/php.exe”. If empty, uses command
“php” from system environments

          “format_on_save”: false, // Format on save

          “psr1”: false, // Activate PSR1 style

          “psr1_naming”: false, // Activate PSR1 style – Section 3 and
4.3 – Class and method names case

          “psr2”: true, // Activate PSR2 style

          “indent_with_space”: 4, // Use spaces instead of tabs for
indentation

          “enable_auto_align”: true, // Enable auto align of = and
=>

          “visibility_order”: true, // Fixes visibiliy order for method
in classes – PSR-2 4.2

          “smart_linebreak_after_curly”: true, // Convert
multistatement blocks into multiline blocks

          // Enable specific transformations. Example:
[“ConvertOpenTagWithEcho”, “PrettyPrintDocBlocks”]

          // You can list all available transformations from command
palette: CodeFormatter: Show PHP Transformations

          “passes”: [],

          // Disable specific transformations

          “exclude”: []

      }

  “`

  ### Javascript/JSON

  Javascript/JSON – used [JSBeautifier] () by
Einar Lielmanis

  Language specific options:

  “`js

      “codeformatter_js_options”:

      {

          “syntaxes”: “javascript,json”, // Syntax names which must
process JS formatter

          “format_on_save”: false, // Format on save

          “indent_size”: 4, // indentation size

          “indent_char”: ” “, // Indent character

          “indent_with_tabs”: false, // Indent with one tab (overrides
indent_size and indent_char options)

          “eol”: “\n”, // EOL symbol

          “preserve_newlines”: false, // whether existing line breaks
should be preserved,

          “max_preserve_newlines”: 10, // maximum number of line
breaks to be preserved in one chunk

          “space_in_paren”: false, // Add padding spaces within paren,
ie. f( a, b )

          “space_in_empty_paren”: false, // Add padding spaces within
paren if parent empty, ie. f(  )

          “e4x”: false, // Pass E4X xml literals through untouched

          “jslint_happy”: false, // if true, then jslint-stricter mode
is enforced. Example function () vs function()

          “brace_style”: “collapse”, // “collapse” | “expand” |
“end-expand”. put braces on the same line as control statements
(default), or put braces on own line (Allman / ANSI style), or just put
end braces on own line.

          “keep_array_indentation”: false, // keep array identation.

          “keep_function_indentation”: false, // keep function
identation.

          “eval_code”: false, // eval code

          “unescape_strings”: false, // Decode printable characters
encoded in xNN notation

          “wrap_line_length”: 0, // Wrap lines at next opportunity
after N characters

          “break_chained_methods”: false, // Break chained method
calls across subsequent lines

          “end_with_newline”: false, // Add new line at end of file

          “comma_first”: false // Add comma first

      }

  “`

  ### HTML

  HTML – used custom python port, please use it with caution, feature in
early beta

  Language specific options:

  “`js

      “codeformatter_html_options”:

      {

          “syntaxes”: “html,asp,xml”, // Syntax names which must process
HTML formatter

          “format_on_save”: false, // Format on save

          “indent_size”: 4, // indentation size

          “indent_char”: ” “, // Indentation character

          “indent_with_tabs”: false, // Indent with one tab (overrides
indent_size and indent_char options)

          “preserve_newlines”: false, // Preserve existing line-breaks

          “max_preserve_newlines”: 10, // Maximum number of
line-breaks to be preserved in one chunk

          “indent_tags”:
“html|head|body|div|nav|ul|ol|dl|li|table|thead|tbody|tr|th|td|blockquote|select|form|option|optgroup|fieldset|legend|label|header|section|aside|footer|figure|video|datalist|keygen|audio|embed|source|track|output|article|bdi|details|dialog|figcaption|main|mark|menuitem|meter|nav|progress|rp|rt|ruby|summary|time|wbr”
// List of tags (defaults to indent) that should be reformatted. Example
“div|p|li|table”

      }

  “`

  ### CSS

  CSS – used [JSBeautifier] () by Einar
Lielmanis and Style Css by Harutyun Amirjanyan

  Language specific options:

  “`js

      “codeformatter_css_options”:

      {

          “syntaxes”: “css,less”, // Syntax names which must process CSS
formatter

网站地图xml地图