From e2142c16c82b13774745d14ecaae2fde942cf916 Mon Sep 17 00:00:00 2001 From: John Fitzpatrick Date: Tue, 1 Mar 2016 20:15:42 +1100 Subject: [PATCH] Initial commit --- .editorconfig | 15 +++++ .gitattributes | 8 +++ .gitignore | 2 + .scrutinizer.yml | 4 ++ CHANGELOG.md | 18 +++++ LICENSE | 21 ++++++ README.md | 55 ++++++++++++++++ bin/yaml-lint | 13 ++++ composer.json | 27 ++++++++ composer.lock | 68 +++++++++++++++++++ src/yaml-lint.php | 164 ++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 395 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .scrutinizer.yml create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100755 bin/yaml-lint create mode 100644 composer.json create mode 100644 composer.lock create mode 100755 src/yaml-lint.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..cd8eb86 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at http://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..7340d8e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.scrutinizer.yml export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c36e38 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +vendor/ diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..cbe90f2 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,4 @@ +checks: + php: + code_rating: true + duplication: true diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..41c07bc --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog + +## [1.0.0] - 2016-03-02 + +### Added +- Initial release + +### Deprecated +- Nothing + +### Fixed +- Nothing + +### Removed +- Nothing + +### Security +- Nothing diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2ff917f --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 John Fitzpatrick + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c6c5fad --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# yaml-lint + +[![Latest Version on Packagist][ico-version]][link-packagist] +[![Software License][ico-license]](LICENSE.md) +[![Coverage Status][ico-scrutinizer]][link-scrutinizer] +[![Quality Score][ico-code-quality]][link-code-quality] +[![Total Downloads][ico-downloads]][link-downloads] + +Command line utility for checking YAML file syntax. Uses the parsing facility of the [Symfony Yaml Component](https://github.com/symfony/yaml). + +## Install + +Via Composer: + +``` bash +$ composer require j13k/yaml-lint +``` + +## Usage + +``` bash +usage: yaml-lint [] + + -q, --quiet Restrict output to syntax errors + -h, --help Display this help +``` + +## Change log + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## Credits + +- [John Fitzpatrick][link-author] +- [Symfony Yaml contributors](https://github.com/symfony/yaml/graphs/contributors) +- [yaml-lint contributors][link-contributors] + +## License + +The MIT License (MIT). Please see [LICENCE](LICENSE) for more information. + +[ico-version]: https://img.shields.io/packagist/v/j13k/yaml-lint.svg?style=flat-square +[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square +[ico-travis]: https://img.shields.io/travis/j13k/yaml-lint/master.svg?style=flat-square +[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/j13k/yaml-lint.svg?style=flat-square +[ico-code-quality]: https://img.shields.io/scrutinizer/g/j13k/yaml-lint.svg?style=flat-square +[ico-downloads]: https://img.shields.io/packagist/dt/j13k/yaml-lint.svg?style=flat-square + +[link-packagist]: https://packagist.org/packages/j13k/yaml-lint +[link-travis]: https://travis-ci.org/j13k/yaml-lint +[link-scrutinizer]: https://scrutinizer-ci.com/g/j13k/yaml-lint/code-structure +[link-code-quality]: https://scrutinizer-ci.com/g/j13k/yaml-lint +[link-downloads]: https://packagist.org/packages/j13k/yaml-lint +[link-author]: https://github.com/j13k +[link-contributors]: ../../contributors diff --git a/bin/yaml-lint b/bin/yaml-lint new file mode 100755 index 0000000..4633335 --- /dev/null +++ b/bin/yaml-lint @@ -0,0 +1,13 @@ +#!/usr/bin/env php +=5.3.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.8-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Yaml Component", + "homepage": "https://symfony.com", + "time": "2016-02-23 07:41:20" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/src/yaml-lint.php b/src/yaml-lint.php new file mode 100755 index 0000000..65f4e26 --- /dev/null +++ b/src/yaml-lint.php @@ -0,0 +1,164 @@ +getMessage()) { + fwrite(STDERR, sprintf("%s\n\n", _ansify($e->getMessage(), ANSI_RED))); + } + print _msg('usage'); + exit($e->getCode()); + +} catch (ParseException $e) { + + // Syntax exception + if ($argQuiet) { // If argQuiet filtered earlier message, output it now + fwrite(STDERR, $appStr . ' Parsing ' . $argPath); + } + fwrite(STDERR, sprintf(" [ %s ]\n", _ansify('ERROR', ANSI_RED))); + fwrite(STDERR, "\n" . $e->getMessage() . "\n\n"); + exit(1); + +} catch (\Exception $e) { + + // The rest + fwrite(STDERR, $appStr); + fwrite(STDERR, sprintf("\n\n%s\n\n", _ansify($e->getMessage(), ANSI_RED))); + exit(1); + +} + +/** + * Helper to wrap input string in ANSI colour code + * + * @param string $str + * @param int $colourCode + * + * @return string + */ +function _ansify($str, $colourCode) +{ + $colourCode = max(0, $colourCode); + $colourCode = min(255, $colourCode); + + return sprintf("\033[38;5;%dm%s\033[0m", $colourCode, $str); +} + +/** + * Wrapper for heredoc messages + * + * @param string $str + * + * @return string + */ +function _msg($str) +{ + switch ($str) { + case 'composer': + return <<] + + -q, --quiet Restrict output to syntax errors + -h, --help Display this help + + +EOD; + break; + default: + } + + return ''; +} + +/** + * Runtime exception for triggering usage message + * + * @property int $code Exception code is passed through as script exit code + */ +class UsageException extends \RuntimeException {}