webignition/node-jslint-output-parser

reid / node-jslint输出解析器,获取错误列表、错误计数、扫描内容百分比、小兔子等漂亮的东西。

2.0 2018-04-03 18:09 UTC

This package is auto-updated.

Last update: 2024-09-05 18:28:31 UTC


README

概述

PHP解析器,用于reid/node-jslint的输出,可以获取错误列表、错误计数、扫描内容百分比、小兔子等。

  • 错误列表
  • 错误计数
  • 扫描内容百分比
  • 小兔子

如果你正在构建一个基于PHP的应用程序,该程序通过node-jslint进行程序性接口,那么这个工具适合你。

用法

"Hello World"示例

通过node-jslint从命令行运行JSLint,可以得到一些错误信息供处理。

node jslint.js --json /home/jon/www/gears.simplytestable.com/src/SimplyTestable/WebClientBundle/Resources/public/js/app.js

[
   "/home/jon/www/gears.simplytestable.com/src/SimplyTestable/WebClientBundle/Resources/public/js/app.js",
   [
      {
         "id":"(error)",
         "raw":"Missing 'use strict' statement.",
         "evidence":"    var nextTaskIdCollection = [];",
         "line":6,
         "character":5,
         "a":"var",
         "reason":"Missing 'use strict' statement."
      },
      {
         "id":"(error)",
         "raw":"Unexpected '{a}'.",
         "evidence":"    ",
         "line":7,
         "character":1,
         "a":"(space)",
         "reason":"Unexpected '(space)'."
      },

让我们在单元测试中解析这些信息,看看我们能得到什么。

<?php
$parser = new webignition\NodeJslintOutput\Parser();

$parser->parse($rawOutputString);
$nodeJsLintOutput = $parser->getNodeJsLintOutput();
        
$this->assertNotNull($nodeJsLintOutput);
$this->assertEquals(7, $nodeJsLintOutput->getEntryCount());
$this->assertEquals(4, $nodeJsLintOutput->getPercentScanned());

$outputEntries = $nodeJsLintOutput->getEntries();
foreach ($outputEntries as $outputEntry) {
    /* @var $outputEntry \webignition\NodeJslintOutput\Entry\Entry */    
    echo $outputEntry->getReason() . "\n";
    echo $outputEntry->getEvidence() . "\n";    
}

看?很有用。我们可以看到输出中有多少条记录,记录的内容以及扫描了多少百分比的内容。

查看JSLint停止扫描的原因

I LINT YOU. Y U NO SCAN ALL CODE

有时JSLint遇到太多错误,有时如果代码质量不够,它可能会停止扫描。

看到扫描停止的原因很令人高兴。

<?php
$parser = new webignition\NodeJslintOutput\Parser();

$parser->parse($rawOutputString);
$nodeJsLintOutput = $parser->getNodeJsLintOutput();
        
$this->assertTrue($nodeJsLintOutput->wasStopped());
$this->assertFalse($nodeJsLintOutput->hasTooManyErrors());

构建

作为项目中的库使用

如果作为其他项目的依赖项使用,请更新该项目的composer.json并更新您的依赖项。

"require": {
    "webignition/node-jslint-output-parser": "*"      
}

开发

此项目使用composer管理外部依赖。首先获取并安装它。

# Make a suitable project directory
mkdir ~/node-jslint-output-parser && cd ~/node-jslint-output-parser

# Clone repository
git clone git@github.com:webignition/node-jslint-output-parser.git.

# Retrieve/update dependencies
composer.phar install

测试

请查看travis上的项目以获取最新的构建状态,或者亲自运行测试。

cd ~/node-jslint-output-parser
phpunit