├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── index.js ├── package-lock.json ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.log 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | - '7' 5 | - '6' 6 | - '5' 7 | - '4' 8 | - '0.12' 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ### 0.1.2 4 | 5 | - Update dependencies 6 | 7 | ### 0.1.1 8 | 9 | - Update lodash from ^3 to ^4 10 | 11 | ## 0.1.0 12 | 13 | - Initial experimental release. 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 stylelint 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # stylelint-checkstyle-formatter 2 | 3 | [![Build Status](https://travis-ci.org/davidtheclark/stylelint-checkstyle-formatter.svg?branch=master)](https://travis-ci.org/davidtheclark/stylelint-checkstyle-formatter) 4 | 5 | Output [Checkstyle](http://checkstyle.sourceforge.net/) XML reports of stylelint results, 6 | which might be handy if you use the Jenkins [Checkstyle Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Checkstyle+Plugin), so you can have graphs and be professional. 7 | 8 | ## Usage 9 | 10 | Simply read the [stylelint](https://github.com/stylelint/stylelint) documentation about using formatters and follow those instructions. 11 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var escape = require('lodash/escape'); 2 | var checkstyleVersion = '4.3'; // Why? Because that's what ESLint uses, I suppose 3 | 4 | module.exports = function(stylelintResults) { 5 | var xml = ''; 6 | xml += '\n'; 7 | stylelintResults.forEach(function(stylelintResult) { 8 | xml += '\n '; 9 | if (!stylelintResult.warnings.length) { 10 | xml += ''; 11 | return; 12 | } 13 | stylelintResult.warnings.forEach(function(warning) { 14 | xml += '\n =0.6.0", 296 | "xmlbuilder": "~9.0.1" 297 | } 298 | }, 299 | "xmlbuilder": { 300 | "version": "9.0.4", 301 | "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-9.0.4.tgz", 302 | "integrity": "sha1-UZy0ymhtAFqEINNJbz8MruzKWA8=", 303 | "dev": true 304 | } 305 | } 306 | } 307 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "stylelint-checkstyle-formatter", 3 | "version": "0.1.2", 4 | "description": "Output Checkstyle XML reports of stylelint results", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "tape test.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/stylelint/stylelint-checkstyle-formatter.git" 12 | }, 13 | "keywords": [ 14 | "stylelint", 15 | "checkstyle", 16 | "formatter", 17 | "reporter", 18 | "report" 19 | ], 20 | "author": "David Clark", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/stylelint/stylelint-checkstyle-formatter/issues" 24 | }, 25 | "homepage": "https://github.com/stylelint/stylelint-checkstyle-formatter#readme", 26 | "devDependencies": { 27 | "tape": "^4.9.1", 28 | "xml2js": "^0.4.15" 29 | }, 30 | "dependencies": { 31 | "lodash": "^4.17.10" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var test = require('tape'); 2 | var xml2js = require('xml2js'); 3 | var checkstyleFormatter = require('./index'); 4 | 5 | var mockResults = [ 6 | { 7 | source: 'path/to/fileA.css', 8 | errored: false, 9 | warnings: [ 10 | { 11 | line: 3, 12 | column: 8, 13 | rule: 'block-no-empty', 14 | severity: 'warning', 15 | text: 'No empty block!', 16 | }, 17 | ], 18 | }, 19 | { 20 | source: 'path/to/fileB.css', 21 | errors: true, 22 | warnings: [ 23 | { 24 | line: 1, 25 | column: 2, 26 | rule: 'foo', 27 | severity: 'error', 28 | text: 'foo text', 29 | }, 30 | { 31 | line: 2, 32 | column: 5, 33 | rule: 'bar', 34 | severity: 'error', 35 | text: 'bar text', 36 | }, 37 | ], 38 | }, 39 | { 40 | source: 'path/to/fileC.css', 41 | errors: false, 42 | warnings: [], 43 | }, 44 | ]; 45 | 46 | var expectedXml = '\n' + 47 | '\n' + 48 | ' \n' + 49 | ' \n' + 50 | ' \n' + 51 | ' \n' + 52 | ' \n' + 53 | ' \n' + 54 | ' \n' + 55 | ' \n' + 56 | ''; 57 | 58 | test('output XML string', function(t) { 59 | var output = checkstyleFormatter(mockResults); 60 | t.equal(output, expectedXml, "matches expectation"); 61 | t.doesNotThrow(function() { 62 | xml2js.parseString(output, function(err) { 63 | if (err) throw err; 64 | }); 65 | }, "is valid XML"); 66 | t.end() 67 | }); 68 | --------------------------------------------------------------------------------