为了跟团队保持开发规范的一致性,需要安装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)

我用了下面的步骤安装:

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

2)

brew install phpmd
sudo curl http://get.sensiolabs.org/php-cs-fixer.phar -o /usr/local/bin/php-cs-fixer
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

{
// Plugin settings // Turn the debug output on/off
"show_debug": false, // Which file types (file extensions), do you want the plugin to
// execute for
"extensions_to_execute": ["php"], // Do we need to blacklist any sub extensions from extensions_to_execute
// An example would be ["twig.php"]
"extensions_to_blacklist": [], // Execute the sniffer on file save
"phpcs_execute_on_save": true, // Show the error list after save.
"phpcs_show_errors_on_save": true, // Show the errors in the gutter
"phpcs_show_gutter_marks": true, // Show outline for errors
"phpcs_outline_for_errors": true, // Show the errors in the status bar
"phpcs_show_errors_in_status": true, // Show the errors in the quick panel so you can then goto line
"phpcs_show_quick_panel": true, // The path to the php executable.
// Needed for windows, or anyone who doesn't/can't make phars
// executable. Avoid setting this if at all possible
"phpcs_php_prefix_path": "", // Options include:
// - Sniffer
// - Fixer
// - Mess Detector
//
// This will prepend the application with the path to php
// Needed for windows, or anyone who doesn't/can't make phars
// executable. Avoid setting this if at all possible
"phpcs_commands_to_php_prefix": [], // What color to stylise the icon
// https://www.sublimetext.com/docs/3/api_reference.html#sublime.View
// add_regsions
"phpcs_icon_scope_color": "comment", // PHP_CodeSniffer settings // Do you want to run the phpcs checker?
"phpcs_sniffer_run": true, // Execute the sniffer on file save
"phpcs_command_on_save": true, // It seems python/sublime cannot always find the phpcs application
// If empty, then use PATH version of phpcs, else use the set value
"phpcs_executable_path": "/usr/local/PHP_CodeSniffer/scripts/phpcs", // Additional arguments you can specify into the application
//
// Example:
// {
// "--standard": "PEAR",
// "-n"
// }
"phpcs_additional_args": {
"--standard": "PSR2",
"-n": ""
}, // PHP-CS-Fixer settings // Fix the issues on save
"php_cs_fixer_on_save": false, // Show the quick panel
"php_cs_fixer_show_quick_panel": false, // Path to where you have the php-cs-fixer installed
"php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer", // Additional arguments you can specify into the application
"php_cs_fixer_additional_args": { }, // phpcbf settings // Fix the issues on save
"phpcbf_on_save": true, // Show the quick panel
"phpcbf_show_quick_panel": false, // Path to where you have the phpcbf installed
"phpcbf_executable_path": "/usr/local/PHP_CodeSniffer/scripts/phpcbf", // Additional arguments you can specify into the application
//
// Example:
// {
// "--level": "all"
// }
"phpcbf_additional_args": {
"--standard": "PSR2",
"-n": ""
}, // PHP Linter settings // Are we going to run php -l over the file?
"phpcs_linter_run": true, // Execute the linter on file save
"phpcs_linter_command_on_save": true, // It seems python/sublime cannot always find the php application
// If empty, then use PATH version of php, else use the set value
"phpcs_php_path": "/usr/local/PHP_CodeSniffer/scripts/phpcs", // What is the regex for the linter? Has to provide a named match for 'message' and 'line'
"phpcs_linter_regex": "(?P<message>.*) on line (?P<line>\\d+)", // PHP Mess Detector settings // Execute phpmd
"phpmd_run": false, // Execute the phpmd on file save
"phpmd_command_on_save": true, // It seems python/sublime cannot always find the phpmd application
// If empty, then use PATH version of phpmd, else use the set value
"phpmd_executable_path": "", // Additional arguments you can specify into the application
//
// Example:
// {
// "codesize,unusedcode"
// }
"phpmd_additional_args": {
"codesize,unusedcode,naming": ""
}, // PHP Scheck settings // Execute scheck
"scheck_run": false, // Execute the scheck on file save
"scheck_command_on_save": false, // It seems python/sublime cannot always find the scheck application
// If empty, then use PATH version of scheck, else use the set value
"scheck_executable_path": "", // Additional arguments you can specify into the application
//
//Example:
//{
// "-php_stdlib" : "/path/to/pfff",
// "-strict" : ""
//}
"scheck_additional_args": {
"-strict" : ""
}
}
  • 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. Chrome浏览器如何不让它缓存?

    chrome对js和图片的缓存,导致调试的程序不是最新的,有时F5刷新了都没用. 此时应: Ctrl+F5 或 Shift+F5 重新载入当前网页,忽略缓存的内容.

  2. 【Java】K-means算法Java实现以及图像切割

    1.K-means算法简述以及代码原型 数据挖掘中一个重要算法是K-means.我这里就不做具体介绍.假设感兴趣的话能够移步陈皓的博客: http://www.csdn.net/article/201 ...

  3. dpkg卸载deb包

    一.背景: 一个脚本安装mysql,结果提示缺少依赖库,安装失败. 二.查询: 此时查询deb文件已经安装的情况,得到这个结果: root@debian:~# dpkg -l |grep mysql- ...

  4. Javascript MVC 学习笔记(一) 模型和数据

    写在前面 近期在看<MVC的Javascript富应用开发>一书.本来是抱着一口气读完的想法去看的.结果才看了一点就傻眼了:太多不懂的地方了. 仅仅好看一点查一点,一点一点往下看吧,进度虽 ...

  5. 【解决】网站运行一段时间后就无法访问,重启Tomcat才能恢复

    [背景]重新部署了网站,运行环境是Linux(centOS6.5)+Tomcat7+mysql5,作了相关安全配置和系统优化工作: [问题]运行几天后,出现了网站无法访问的现象,具体是进入网站首页时页 ...

  6. kafka 配置文件注释

    文章转载自:http://liyonghui160com.iteye.com/blog/2163899 server.properties配置: server.properties中所有配置参数说明( ...

  7. 【Linux运维-集群技术进阶】Nginx+Keepalived+Tomcat搭建高可用/负载均衡/动静分离的Webserver集群

    额.博客名字有点长.. . 前言 最终到这篇文章了,心情是有点激动的. 由于这篇文章会集中曾经博客讲到的全部Nginx功能点.包含主要的负载均衡,还有动静分离技术再加上这篇文章的重点.通过Keepal ...

  8. ITOO高校云平台V3.1--项目总结(二)

    自身责任要明白 心态要明白 布置任务要有反馈 总结 今天下午.举办了一场ITOO高校云平台3.1总结大会,针对3.1开发的过程中统计上来的问题进行讨论. 通过讨论统计上来的问题,映射到自身,看看自己还 ...

  9. centos 7安装cppman

    cppman是一个在命令行查询c和c++语法及标准库函数的工具,非常好用,python3编写,记录一下安装过程: yum update yum install python34 yum install ...

  10. SonarQube学习入门指南

    1. 什么是SonarQube? SonarQube 官网:https://www.sonarqube.org/ SonarQube®是一种自动代码审查工具,用于检测代码中的错误,漏洞和代码异味.它可 ...