【问题标题】:SublimeLinter: modules phpcs and phpmd not workingSublimeLinter:模块 phpcs 和 phpmd 不工作
【发布时间】:2017-01-10 12:04:14
【问题描述】:

Sublime Text 3 我已经通过Package Manager 安装了以下包:

  • SublimeLinter
  • SublimeLinter-phpmd
  • SublimeLinter-phpcs
  • 以及其他几个..

问题是phpmdphpcs 都不起作用。在 ST3 中打开 php 文件然后单击:ctrl 和 ` 我得到以下调试信息:

SublimeLinter: debug mode: on 
SublimeLinter: temp directory: c:\users\alekspav\appdata\local\temp\SublimeLinter3-alekspav 
SublimeLinter: annotations activated: <builtin> 
SublimeLinter: json activated: <builtin> 
SublimeLinter: WARNING: phpcs deactivated, cannot locate 'phpcs' 
SublimeLinter: annotations activated: <builtin> 
SublimeLinter: WARNING: jshint deactivated, cannot locate 'jshint' 
SublimeLinter: php activated: C:\xampp\php\php.exe 
SublimeLinter: WARNING: phpmd deactivated, cannot locate 'phpmd'
SublimeLinter: WARNING: htmltidy deactivated, cannot locate 'tidy' 
SublimeLinter: WARNING: csslint deactivated, cannot locate 'csslint' 
SublimeLinter: php: submitter.php ['C:\\xampp\\php\\php.exe', '-l', '-n', '-d', 'display_errors=On', '-d', 'log_errors=Off'] 
SublimeLinter: php output:
No syntax errors detected in - 

我对这两行特别感兴趣:

  • SublimeLinter:警告:phpcs 已停用,无法找到“phpcs
  • SublimeLinter:警告:phpmd 已停用,找不到“phpmd

我试图解决这个问题是编辑用户配置文件: Sublime text 3: Preferences -&gt; package settings -&gt; sublime linter-&gt; settings - user

然后添加cmd键如下:

    "phpcs": {
        "@disable": false,
        "args": [],
        "cmd": "C:/xampp/htdocs/web/vendor/bin/phpcs/",
        "excludes": [],
        "standard": "PSR2"
    },
    "phpmd": {
        "@disable": false,
        "args": [],
        "cmd": "C:/xampp/htdocs/web/vendor/bin/phpmd/",
        "excludes": [],
        "rulesets": "cleancode,codesize,controversial,design,naming,unusedcode"
    }

如您所料 - 这并没有解决问题。我还尝试在末尾写不带 / 的路径,并尝试使用 \ 分隔符而不是 /。而且我还尝试直接指定 PFAM 文件。并且还尝试使用 ${project} 变量而不是整个 C:/ 路径。 ST3 重启后我仍然收到警告。

我的另一个问题是 - 如何在调试窗口中输出“${project}”目录?因为我不确定它是否设置正确所以我想测试一下。

更多信息:

Sublime 项目目录为:C:\xampp\htdocs\web\test.sublime-project

这里是phpmdphpcs 安装:

  • “C:\xampp\htdocs\web\vendor\bin\phpcs\phpcbf.phar”
  • “C:\xampp\htdocs\web\vendor\bin\phpcs\phpcs.phar”
  • “C:\xampp\htdocs\web\vendor\bin\phpmd\phpmd.phar”

编辑:

好像我做错了。我在项目目录中添加了composer.json,内容如下:

{
    "require-dev": {
        "squizlabs/php_codesniffer": "2.*",
        "phpmd/phpmd" : "@stable",
        "mongodb/mongodb" : "@dev"
    }
}

使用composer install 命令安装所有内容后 - 我为我创建了vendor 文件夹,其中包含许多目录,包括bin 文件夹。它现在拥有所有必要的文件,但我仍然遇到同样的错误。由于某种原因找不到模块。

【问题讨论】:

    标签: sublimetext3 sublimelinter phpmd phpcs


    【解决方案1】:

    我也很难让 sublimeLinter-phpmd 工作。这是我修复它的方法:

    假设:

    • 你在窗户上
    • 您已安装 sublime-text 3 和 sublimeLinter

    步骤:

    1. 安装梨:http://pear.php.net/manual/en/installation.getting.php
    2. 重要:将 pear 目录添加到 $PATH
    3. 使用 pear 安装 phpmd 在您的 pear 目录下https://github.com/SublimeLinter/SublimeLinter-phpmd
    4. 重启 sublime-text 3.

    对我来说,这是因为我错过了第 2 步,所以 phpmd linter 无法工作。

    无需使用 composer 安装每个项目的 phpmd。并且安装了 SublimeLinter-phpmd 后无需手动修改 SublimeLinter 的设置。

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      好的,

      我不确定这是错误还是功能,但我找到了问题的解决方案。

      1. 首先 - 您必须使用pear 安装phpcsphpmd!没有这个 - 你会看到最初发布的警告。

      phpcs:pear 安装 PHP_CodeSniffer

      phpmd:此处的说明:http://pear.phpmd.org/(我不记得另一个存储库的名称,但在第一次安装期间,您会遇到缺少某些库的错误,并且会提示您添加一个更多存储库的文本缺少 phpmd pear 安装的依赖项。一切都很简单)

      启动ST3 并检查。无需编辑配置。两个模块都应该在Sublime Text 3 中工作!但是我们现在使用pear 模块而不是composer 模块。我最初的想法是使用conmposer。它更容易维护和更新。

      如果您不熟悉它 - 谷歌。在项目目录中,您应该有一个名为 composer.json 的文件,其内容类似于:

      {
          "require-dev": {
              "squizlabs/php_codesniffer":    "2.*",
              "phpmd/phpmd" :                 "@stable"
          }
      }
      

      然后使用Windows command promptcomposer install 命令安装所有模块

      1. 正如最初的帖子中所述 - 在SublimeLinter 的用户配置中使用以下配置:

            "phpcs": {
                "@disable": false,
                "args": [],
                "cmd": "${project}/vendor/bin/phpcs.bat",
                "excludes": [],
                "standard": "${project}/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR2/ruleset.xml"
            },
            "phpmd": {
                "@disable": false,
                "args": [],
                "cmd": "${project}/vendor/bin/phpmd.bat",
                "excludes": [],
                "rulesets": "cleancode,codesize,controversial,design,naming,unusedcode"
            }
        

      现在重启Sublime test 3并打开调试并打开PHP文件。结果是:

      reloading plugin SublimeLinter-phpcs.linter
      SublimeLinter: phpcs linter loaded 
      reloading plugin SublimeLinter-phpmd.linter
      SublimeLinter: phpmd linter loaded 
      ...
      reloading settings Packages/User/SublimeLinter.sublime-settings
      SublimeLinter: phpcs activated: C:\xampp\php\phpcs.bat 
      SublimeLinter: phpmd activated: C:\xampp\php\phpmd.bat 
      ...
      SublimeLinter: phpcs: index.php ['C:/xampp/htdocs/web/vendor/bin/phpcs.bat', '--report=checkstyle', '--standard=C:/xampp/htdocs/web/vendor/squizlabs/php_codesniffer/CodeSniffer/Standards/PSR2/ruleset.xml'] 
      SublimeLinter: phpcs output:
      .. errors in PHP file listed
      Package Control: Skipping automatic upgrade, last run at 2016-09-05 17:12:20, next run at 2016-09-05 18:12:20 or after
      ...
      SublimeLinter: phpmd: index.php ['C:/xampp/htdocs/web/vendor/bin/phpmd.bat', '@', 'text', 'cleancode,codesize,controversial,design,naming,unusedcode'] 
      SublimeLinter: phpmd output:
      .. errors in PHP file listed
      

      如您所见 - SublimeLinter 首先将pear bats 加载到PHP 目录中!但是在提交PHP 文件进行分析时 - 它正在使用项目目录中的新bats。

      我的解释是 SublimeLinter 在使用 composer 等效项之前始终需要安装 pear phpcsphpmd。如果您问我,这很愚蠢..但我找不到任何其他解决方案。

      【讨论】:

      • 好吧,我认为如果您将BIN 文件夹路径添加到PATH 环境变量中,问题将得到解决。这个想法是SublimeLinter 不是在寻找“cmd”第一次启动时的参数。它无法在PHP 目录中找到bat 文件,因为没有pear 安装phpcsphpmd - 将没有这样的文件。所以如果你告诉他“嘿,看看这个文件夹” - 它应该识别BIN 文件夹中的文件。无论如何,我对我的第一个方法很满意,不想破坏任何东西:)
      • 奇怪的是我不能编辑自己的帖子。无论如何,我认为这个问题也可以通过创建一个指向PHP 文件夹的符号链接来解决。我的意思是 bat 的 shortcutPHP 目录..但当然没有经过测试。
      猜你喜欢
      • 2014-08-02
      • 2017-10-20
      • 2014-06-21
      • 2017-01-31
      • 2015-10-22
      • 2014-06-12
      • 2016-01-06
      • 2016-06-06
      • 2017-08-05
      相关资源
      最近更新 更多