为了跟团队保持开发规范的一致性,需要安装sublime Text2的php code sniffer插件,之前是用的phpfmt插件,发现两个规范还是有点不一样,需要再安装php code sniffer.

参考网址: http://blog.chinaunix.net/uid-26374858-id-5039120.html

http://fengzheng369.blog.163.com/blog/static/7522097920155342169

https://github.com/squizlabs/sublime-PHP_CodeSniffer

安装步骤:

1) 下载php code sniffer (https://github.com/squizlabs/PHP_CodeSniffer)

我用了下面的步骤安装:

  1. cd /usr/local
    git clone git://github.com/squizlabs/PHP_CodeSniffer.git
  2. cd PHP_CodeSniffer
  3. php scripts/phpcs -h
  4. php scripts/phpcbf -h

2)

  1. brew install phpmd
  1. sudo curl http://get.sensiolabs.org/php-cs-fixer.phar -o /usr/local/bin/php-cs-fixer
  2. sudo chmod a+x /usr/local/bin/php-cs-fixer

3) 安装sublime phpcs插件

安装方法(Ctrl+Shift+P->pi(package install)->phpcs,安装成功后右键即可看到PHP Code Sniffer选项).刚刚安装好的插件,sniff this file 显示的是灰色的,修改下配置文件(这是 Sublime 2的配置)

preferences->package settings->php code sniffer->setting-default

  1. {
  2. // Plugin settings
  3.  
  4. // Turn the debug output on/off
  5. "show_debug": false,
  6.  
  7. // Which file types (file extensions), do you want the plugin to
  8. // execute for
  9. "extensions_to_execute": ["php"],
  10.  
  11. // Do we need to blacklist any sub extensions from extensions_to_execute
  12. // An example would be ["twig.php"]
  13. "extensions_to_blacklist": [],
  14.  
  15. // Execute the sniffer on file save
  16. "phpcs_execute_on_save": true,
  17.  
  18. // Show the error list after save.
  19. "phpcs_show_errors_on_save": true,
  20.  
  21. // Show the errors in the gutter
  22. "phpcs_show_gutter_marks": true,
  23.  
  24. // Show outline for errors
  25. "phpcs_outline_for_errors": true,
  26.  
  27. // Show the errors in the status bar
  28. "phpcs_show_errors_in_status": true,
  29.  
  30. // Show the errors in the quick panel so you can then goto line
  31. "phpcs_show_quick_panel": true,
  32.  
  33. // The path to the php executable.
  34. // Needed for windows, or anyone who doesn't/can't make phars
  35. // executable. Avoid setting this if at all possible
  36. "phpcs_php_prefix_path": "",
  37.  
  38. // Options include:
  39. // - Sniffer
  40. // - Fixer
  41. // - Mess Detector
  42. //
  43. // This will prepend the application with the path to php
  44. // Needed for windows, or anyone who doesn't/can't make phars
  45. // executable. Avoid setting this if at all possible
  46. "phpcs_commands_to_php_prefix": [],
  47.  
  48. // What color to stylise the icon
  49. // https://www.sublimetext.com/docs/3/api_reference.html#sublime.View
  50. // add_regsions
  51. "phpcs_icon_scope_color": "comment",
  52.  
  53. // PHP_CodeSniffer settings
  54.  
  55. // Do you want to run the phpcs checker?
  56. "phpcs_sniffer_run": true,
  57.  
  58. // Execute the sniffer on file save
  59. "phpcs_command_on_save": true,
  60.  
  61. // It seems python/sublime cannot always find the phpcs application
  62. // If empty, then use PATH version of phpcs, else use the set value
  63. "phpcs_executable_path": "/usr/local/PHP_CodeSniffer/scripts/phpcs",
  64.  
  65. // Additional arguments you can specify into the application
  66. //
  67. // Example:
  68. // {
  69. // "--standard": "PEAR",
  70. // "-n"
  71. // }
  72. "phpcs_additional_args": {
  73. "--standard": "PSR2",
  74. "-n": ""
  75. },
  76.  
  77. // PHP-CS-Fixer settings
  78.  
  79. // Fix the issues on save
  80. "php_cs_fixer_on_save": false,
  81.  
  82. // Show the quick panel
  83. "php_cs_fixer_show_quick_panel": false,
  84.  
  85. // Path to where you have the php-cs-fixer installed
  86. "php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer",
  87.  
  88. // Additional arguments you can specify into the application
  89. "php_cs_fixer_additional_args": {
  90.  
  91. },
  92.  
  93. // phpcbf settings
  94.  
  95. // Fix the issues on save
  96. "phpcbf_on_save": true,
  97.  
  98. // Show the quick panel
  99. "phpcbf_show_quick_panel": false,
  100.  
  101. // Path to where you have the phpcbf installed
  102. "phpcbf_executable_path": "/usr/local/PHP_CodeSniffer/scripts/phpcbf",
  103.  
  104. // Additional arguments you can specify into the application
  105. //
  106. // Example:
  107. // {
  108. // "--level": "all"
  109. // }
  110. "phpcbf_additional_args": {
  111. "--standard": "PSR2",
  112. "-n": ""
  113. },
  114.  
  115. // PHP Linter settings
  116.  
  117. // Are we going to run php -l over the file?
  118. "phpcs_linter_run": true,
  119.  
  120. // Execute the linter on file save
  121. "phpcs_linter_command_on_save": true,
  122.  
  123. // It seems python/sublime cannot always find the php application
  124. // If empty, then use PATH version of php, else use the set value
  125. "phpcs_php_path": "/usr/local/PHP_CodeSniffer/scripts/phpcs",
  126.  
  127. // What is the regex for the linter? Has to provide a named match for 'message' and 'line'
  128. "phpcs_linter_regex": "(?P<message>.*) on line (?P<line>\\d+)",
  129.  
  130. // PHP Mess Detector settings
  131.  
  132. // Execute phpmd
  133. "phpmd_run": false,
  134.  
  135. // Execute the phpmd on file save
  136. "phpmd_command_on_save": true,
  137.  
  138. // It seems python/sublime cannot always find the phpmd application
  139. // If empty, then use PATH version of phpmd, else use the set value
  140. "phpmd_executable_path": "",
  141.  
  142. // Additional arguments you can specify into the application
  143. //
  144. // Example:
  145. // {
  146. // "codesize,unusedcode"
  147. // }
  148. "phpmd_additional_args": {
  149. "codesize,unusedcode,naming": ""
  150. },
  151.  
  152. // PHP Scheck settings
  153.  
  154. // Execute scheck
  155. "scheck_run": false,
  156.  
  157. // Execute the scheck on file save
  158. "scheck_command_on_save": false,
  159.  
  160. // It seems python/sublime cannot always find the scheck application
  161. // If empty, then use PATH version of scheck, else use the set value
  162. "scheck_executable_path": "",
  163.  
  164. // Additional arguments you can specify into the application
  165. //
  166. //Example:
  167. //{
  168. // "-php_stdlib" : "/path/to/pfff",
  169. // "-strict" : ""
  170. //}
  171. "scheck_additional_args": {
  172. "-strict" : ""
  173. }
  174. }
  • ALT + S: Runs PHPCS command for the open buffer.
  • ALT + SHIFT + S: Runs PHPCBF command for the open buffer.

sublime Text2下安装php code sniffer插件的更多相关文章

  1. sublime text下安装插件autoprefixer

    有时候在写css样式的时候,分不清哪些属性需要前缀,哪些不需要,总是爱搞混淆了,于是autoprefixer这款插件便应运而生了.虽然在使用webpack的时候,我们可以很方便的使用这个,但是,如果项 ...

  2. Sublime Text 2 安装Package Control和插件的两种方法

    缘起 前几天系统刚刚还原了,重装完Sublime Text2再安装插件的时候可能是由于公司的网络环境的问题,各种报错,将解决方法记录下来.系统环境:Win7 x64 + Sublime Text2. ...

  3. Sublime Text3—软件安装、package control插件管理

    一.简介 市面上的编辑器纷繁复杂各有优点,好用的编辑器能让你工作事半功倍,先简单介绍下本文主角Sublime Text编辑器,下面简称Sublime. 1.可用于 Windows.Mac OS X 和 ...

  4. 在sublime text2上安装xdebug

    目录 安装Xdebug extension 设定php.ini 安装Xdebug plugin for Sublime Text2 1.安装Xdebug extension 先从安装Xdebug开始, ...

  5. sublime text2下配置c++

    今天安装了sublime text2,真是编辑神器,不再用notepad了. 笔记本上没有c++运行环境,用编辑器既轻巧,又方便,VS太臃肿了. 要在sublime text2 下运行c++程序,需要 ...

  6. 哪些个在 Sublime Text 下,"任性的" 好插件!

    我在sublime里面安装了以下有利于项目开发高效的插件: 1:SVN             源代码版本控制 2:LiveReload   浏览器实时刷新 3:jsMinifier     压缩 j ...

  7. Kali Linux Web渗透测试手册(第二版) - 1.1 - Firefox浏览器下安装一些常用的插件

    一.配置KALI Linux和渗透测试环境 在这一章,我们将覆盖以下内容: l  在Windows和Linux上安装VirtualBox l  创建一个Kali Linux虚拟机 l  更新和升级Ka ...

  8. Sublime Text2 中Emmet(之前叫Zencoding)插件安装以及使用

    一.添加插件之前先 下载Package Control 按 Ctrl+`(就是~这个键) 复制下面的代码 确认 重新启动sublime text2 import urllib2,os;pf='Pack ...

  9. Ubuntu解决Sublime Text 2安装GBK Encoding Support插件仍然乱码

    Ubuntu 12.04 32位下,为Sublime Text 2安装Package Control: 1. 用Ctrl+~打开控制台,输入 import urllib2,os; pf='Packag ...

随机推荐

  1. SQL临时表

    临时表就是那些名称以井号 (#) 开头的表.如果当用户断开连接时没有除去临时表,SQL Server 将自动除去临时表.临时表不存储在当前数据库内,而是存储在系统数据库 tempdb 内.  临时表有 ...

  2. .Net Core ORM选择之路,哪个才适合你 通用查询类封装之Mongodb篇 Snowflake(雪花算法)的JavaScript实现 【开发记录】如何在B/S项目中使用中国天气的实时天气功能 【开发记录】微信小游戏开发入门——俄罗斯方块

    .Net Core ORM选择之路,哪个才适合你   因为老板的一句话公司项目需要迁移到.Net Core ,但是以前同事用的ORM不支持.Net Core 开发过程也遇到了各种坑,插入条数多了也特别 ...

  3. label 赋值 , 隐藏 , 显示

    <label name='by_stages_number' id='by_stages_number'></label> document.getElementById(&q ...

  4. 8个实用而有趣Bash命令提示行

    很多人都对过命令行提示的重要性不屑一顾,甚至是一点都不关心.但是我却一点都不这么认为,一个好的命令行提示可以改变你使用命令的方式.为此,我在internet上找到一些非常实用,优秀,并有趣的bash的 ...

  5. Maven for Eclipse 第三章 ——创建和导入 Maven 项目

    这一章主要介绍 Maven 项目的结构,它的构建的架构,主要涵盖了必需的主题,最后将学习如何创建一个简单的 Maven 项目.这章主要包括以下部分. Maven 项目的结构 POM 文件(Projec ...

  6. MySQL 两个数据库表中合并数据

    两个数据库表中合并数据 如果有  t1  和 t2 两个数据库表格,它们两个对应的字段是相同的.如何将 t2 的数据插入到t1中去呢? insert into t1 select * from t2 ...

  7. Yii2 使用 faker 生成假数据(转)

    测试过程中有时候需要生成大量的假数据,faker 是一个生成假数据的类库,可以生成姓名,电话,IP地址,密码,ISBN等等你能想到的或者你想不到的各种类型的假数据. Yii2.0已经集成该类库,不用再 ...

  8. 使用 sqlyog 导入导出数据显示 lost connection to mysql server during query

    mysql中经常需要备份数据,在使用 sqlyog 进行备份数据库为转储文件,然后在其他数据库中导入发生 lost connection 经过查询大量资料是数据库配置的 max_allowed_pac ...

  9. webstorm 设置js或者html文件自动缩进为4个空格不生效

    设置 tab 和自动缩进为4个空格不生效,解决办法如下 设置代码缩进 1. 依次打开files —- settings —- Editor —- Code Style —- JavaScript 2. ...

  10. ELK 中的elasticsearch 集群的部署

    本文内容 背景 ES集群中第一个master节点 ES slave节点 本文总结 Elasticsearch(以下简称ES)搭建集群的经验.以 Elasticsearch-rtf-2.2.1 版本为例 ...