sublime使用 sublime-phpcs 插件

linux版本sublime使用 sublime-phpcs 插件

sublime-phpcs 插件手动安装
官网
github

# [浏览插件]打开插件目录
cd Sublime_Text/Packages/
# 在目录里面下载sublime-phpcs
git clone git://github.com/benmatselby/sublime-phpcs.git Phpcs

phar环境配置
官网

# 前提已经安装php,下载
wget http://pear.php.net/go-pear.phar
# 初始化
php go-pear.phar
# 提示
Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.

 1. Installation base ($prefix)                   : /home/lxx/pear
 2. Temporary directory for processing            : /tmp/pear/install
 3. Temporary directory for downloads             : /tmp/pear/install
 4. Binaries directory                            : /home/lxx/pear/bin
 5. PHP code directory ($php_dir)                 : /home/lxx/pear/share/pear
 6. Documentation directory                       : /home/lxx/pear/docs
 7. Data directory                                : /home/lxx/pear/data
 8. User-modifiable configuration files directory : /home/lxx/pear/cfg
 9. Public Web Files directory                    : /home/lxx/pear/www
10. System manual pages directory                 : /home/lxx/pear/man
11. Tests directory                               : /home/lxx/pear/tests
12. Name of configuration file                    : /home/lxx/.pearrc

1-12, 'all' or Enter to continue: 

# 全回车,提示安装到用户lxx名目录
/home/lxx/pear/share/pear
# 修改了php.ini文件
/etc/php/php.ini
# 使用
/home/lxx/pear/bin/pear
# 软链接
sudo ln -s /home/lxx/pear/bin/pear /bin/pear
# 可以直接使用
pear

phar插件安装

# 统一下载配置到/home/lxx/pear/bin/文件夹,国外原因,可能有点缓慢

# 1.PHP_CodeSniffer
# info:http://pear.php.net/package/PHP_CodeSniffer/download
#      http://pear.php.net/manual/en/package.php.php-codesniffer.php
# 说明:该包的作用是用指定的代码规范(默认使用PEAR规范,可指定使用PSR1,PSR2或自己制定的规范)来检查代码是否符合规范。
pear install PHP_CodeSniffer-3.3.2

# 2.PHP Mess Detector (phpmd)
# info:https://phpmd.org/documentation/index.html
# 说明:检查PHP代码存在的问题,潜在的BUG,定义但未使用的变量、方法、属性等
cd /home/lxx/pear/bin/
wget -c http://static.phpmd.org/php/latest/phpmd.phar -O phpmd
sudo chmod 777 phpmd

# 3. PHP Coding Standards Fixer(php-cs-fixer)
# 可以忽略
# info:https://github.com/FriendsOfPHP/PHP-CS-Fixer
# 说明:该包可以修复PHP代码中的规范问题。
cd /home/lxx/pear/bin/
wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer
# wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.13.1/php-cs-fixer.phar -O php-cs-fixer
sudo chmod 777 php-cs-fixer

配置

# 查看php位置
which php
# 其他插件的位置我们下载到了
/home/lxx/pear/bin/
# 首选项Preferences -> 插件设置Package Setting -> PHP Code Sniffer -> Setting – User对插件进行配置
{
    "phpcs_php_path": "/usr/bin/php",
    "phpcs_executable_path": "/home/lxx/pear/bin/phpcs",
    "phpmd_executable_path": "/home/lxx/pear/bin/phpmd",
    "phpcbf_executable_path": "/home/lxx/pear/bin/phpcbf",
    "php_cs_fixer_executable_path": "/home/lxx/pear/bin/php-cs-fixer",
    // 开启phpmd
    "phpmd_run": true
}
# phpcbf配置,使用PSR-2来格式化代码
"phpcs_additional_args": {
    "--standard": "PSR2",
    "-n": ""
},
"phpcbf_additional_args": {
    "--standard": "PSR2",
    "-n": ""
},
# 保存时就格式化代码
"phpcbf_on_save": true

使用

# sublime-phpcs默认在保存时执行检查,自动弹窗
# 可根据提示自行修改,或点击右键,按照插件选项对格式问题进行自动修复(phpmd检测出的代码问题等需要手动修复)

猜你喜欢

转载自blog.csdn.net/HD2killers/article/details/83747589