如何使用phpcs在sublime学习编码标准? [英] How do I use phpcs in sublime to learn coding standards?

查看:240
本文介绍了如何使用phpcs在sublime学习编码标准?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习将PHP编码为标准。我发现这篇文章和(在其建议)安装phpcs在崇高的文本2。如果我去工具 - > phpcode sniffer - >嗅这个文件,它会发现语法错误,但不编码标准偏差。 (这里是我试图嗅探,我认为有许多偏离标准的代码 http ://codereview.stackexchange.com/questions/57045/simple-wrapper-for-an-api )。



文件表示将phpcs配置为通过 phpcs_additional_args 使用编码标准。如果我去sublimetext2-> preferences-> package settings-> phpcode sniffer-> settings用户我看到下面的代码:

  phpcs_additional_args:{
--standard:PSR2,
-n:
},

这是我的完整配置文件



我有工作流程吗?如果是这样,为什么不是找到我的错误?我如何使用phpcs教自己的编码标准?

解决方案

基于您的配置文件,有一些必须修复的事情:



以下说明适用于linux(ubuntu)或mac


  1. 确保您已安装 PEAR

  2. 安装php代码嗅探器



    pear install PHP_CodeSniffer



    重新加载您的bash或zsh然后执行命令,如果你不知道该怎么做,终端应用程式



    which phpcs



    并将粘贴到phpcs_executable_path: at phpcs config



    < phpcs_executable_path:
    到php,而不是phpcs,这就是为什么它不工作


  3. 安装php mess检测器



    pear channel-discover pear.phpmd.org
    pear channel-discover pear.pdepend.org
    pear install pdepend / PHP_Depend
    pear install --alldeps phpmd / PHP_PMD



    像上面的phpcs一样



    reload enviroment并执行 which phpmd ,然后在phpcs config

    填写phpmd_executable_path:

  4. 安装php-cs-fixer



    sudo wget 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



    更改php_cs_fixer_executable_path:至php_cs_fixer_executable_path: usr / local / bin / php-cs-fixer


  5. 安装scheck


    $ b b

    cd / opt /
    git clone --depth = 1 https://github.com/facebook/pfff.git
    cd pfff /
    。 / configure
    make depends
    make
    make opt



    更改scheck_executable_path scheck_executable_path:/ opt / pfff / scheck


注意:您可以使用 sudo pear ... 代替 pear ...


I want to learn to code PHP to standard. I found this article and (on its advice) installed phpcs in sublime text 2. If I go to tools -->phpcode sniffer -->sniff this file it will find syntax errors but not coding standard deviations. (Here is the code I am trying to sniff, which I think has many deviations from standard http://codereview.stackexchange.com/questions/57045/simple-wrapper-for-an-api).

The docs say to configure phpcs to use a coding standard via phpcs_additional_args. If I go to sublimetext2->preferences->package settings->phpcode sniffer->settings user I see the following code:

   "phpcs_additional_args": {
        "--standard": "PSR2",
        "-n": ""
    },

Here is my full config file.

Do I have the workflow right? If so, why isn't it finding my mistakes? How do I use phpcs to teach myself coding standards? Even knowing that I am doing the correct steps but the plugin is not outputting the coding standard marks would be helpful.

解决方案

Based on your configuration file, there are some things you must fix:

Following instructions are for linux (ubuntu), or mac

  1. Ensure you have installed PEAR
  2. Install php code sniffer

    pear install PHP_CodeSniffer

    reload your bash or zsh and then execute command, if you don't know how to do this, just restart your terminal app

    which phpcs

    copy the output and paste to "phpcs_executable_path": at phpcs config

    currently, you're pointing "phpcs_executable_path": to php, not phpcs, so thats why its doesn't work

  3. Install php mess detector

    pear channel-discover pear.phpmd.org pear channel-discover pear.pdepend.org pear install pdepend/PHP_Depend pear install --alldeps phpmd/PHP_PMD

    do like phpcs above

    reload enviroment and execute which phpmd, then fill "phpmd_executable_path": "" at phpcs config

  4. install php-cs-fixer

    sudo wget 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

    change "php_cs_fixer_executable_path": "" to "php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer"

  5. install scheck

    cd /opt/ git clone --depth=1 https://github.com/facebook/pfff.git cd pfff/ ./configure make depend make make opt

    change "scheck_executable_path" to "scheck_executable_path": "/opt/pfff/scheck"

Note: you may use sudo pear ... instead pear ...

这篇关于如何使用phpcs在sublime学习编码标准?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆