-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update plugin to new Validator Interface
With the new plugin structure from Xulieta 1.0 we can write just the Validator so we don't have to handle file parsers details. Co-Authored-by: Jefersson Nathan <malukenho.dev@gmail.com> Signed-off-by: Alexandre Eher <alexandre@eher.com.br>
- Loading branch information
Showing
10 changed files
with
129 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<xulieta xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/codelicia/xulieta/xulieta.xsd"> | ||
<plugin>Codelicia\XulietaJson\Plugin</plugin> | ||
<plugin>Codelicia\XulietaJson\Plugin</plugin> | ||
<validator>Codelicia\XulietaJson\JsonValidator</validator> | ||
<validator>Codelicia\XulietaJson\JsonValidator</validator> | ||
</xulieta> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0"?> | ||
<phpunit | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
beStrictAboutResourceUsageDuringSmallTests="true" | ||
beStrictAboutChangesToGlobalState="true" | ||
beStrictAboutOutputDuringTests="true" | ||
bootstrap="./vendor/autoload.php" | ||
verbose="true" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="functional"> | ||
<directory suffix=".phpt">./tests/functional</directory> | ||
</testsuite> | ||
</testsuites> | ||
<coverage> | ||
<include> | ||
<directory suffix=".php">src</directory> | ||
</include> | ||
</coverage> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codelicia\XulietaJson; | ||
|
||
use Codelicia\Xulieta\Validator\Validator; | ||
use Codelicia\Xulieta\ValueObject\SampleCode; | ||
use Codelicia\Xulieta\ValueObject\Violation; | ||
use LogicException; | ||
use Throwable; | ||
|
||
use function json_decode; | ||
|
||
use const JSON_THROW_ON_ERROR; | ||
|
||
final class JsonValidator implements Validator | ||
{ | ||
public function supports(SampleCode $sampleCode): bool | ||
{ | ||
return $sampleCode->language() === 'json'; | ||
} | ||
|
||
public function hasViolation(SampleCode $sampleCode): bool | ||
{ | ||
try { | ||
json_decode($sampleCode->code(), true, 512, JSON_THROW_ON_ERROR); | ||
} catch (Throwable $ex) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function getViolation(SampleCode $sampleCode): Violation | ||
{ | ||
try { | ||
json_decode($sampleCode->code(), true, 512, JSON_THROW_ON_ERROR); | ||
} catch (Throwable $ex) { | ||
return new Violation($sampleCode, $ex->getMessage(), 0); | ||
} | ||
|
||
throw new LogicException(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# File containing json with good syntax | ||
|
||
This should be fine | ||
|
||
```json | ||
{ | ||
"good": "", | ||
"so": "good" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
return static function (string $params) : void { | ||
$basePath = dirname(__DIR__, 2); | ||
|
||
system("php $basePath/vendor/bin/xulieta check:erromeu $params"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--TEST-- | ||
Report error when invalid json is detected | ||
--FILE-- | ||
<?php | ||
|
||
$checkRunner = require __DIR__ . '/init.php'; | ||
|
||
$checkRunner('tests/assets/invalid-json.md'); | ||
|
||
--EXPECTF-- | ||
Finding documentation files on tests/assets/invalid-json.md | ||
|
||
--> tests/assets/invalid-json.md | ||
1 | { | ||
2 | "nosso": "", | ||
3 | "erro": " | ||
4 | } | ||
| | | ||
= note: Control character error, possibly incorrectly encoded | ||
|
||
|
||
Operation failed! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Report success with a valid json | ||
--FILE-- | ||
<?php | ||
|
||
$checkRunner = require __DIR__ . '/init.php'; | ||
|
||
$checkRunner('tests/assets/valid-json.md'); | ||
|
||
--EXPECTF-- | ||
Finding documentation files on tests/assets/valid-json.md | ||
|
||
|
||
Everything is OK! |