@commitlint/format
Advanced tools
Comparing version 7.1.2 to 7.2.0
@@ -6,2 +6,10 @@ # Change Log | ||
<a name="7.2.0"></a> | ||
# [7.2.0](https://github.com/marionebl/commitlint/compare/v7.1.2...v7.2.0) (2018-10-05) | ||
**Note:** Version bump only for package @commitlint/format | ||
<a name="7.1.2"></a> | ||
@@ -8,0 +16,0 @@ ## [7.1.2](https://github.com/marionebl/commitlint/compare/v7.1.1...v7.1.2) (2018-09-04) |
@@ -18,2 +18,37 @@ 'use strict'; | ||
function format(report = {}, options = {}) { | ||
var _report$results = report.results; | ||
const results = _report$results === undefined ? [] : _report$results; | ||
if (results.length > 0) { | ||
return results.map(result => `${formatInput(result, options)}${formatResult(result, options).join('\n')}`).join('\n'); | ||
} | ||
// Output a summary when nothing is found | ||
return formatResult({}, options).join('\n'); | ||
} | ||
function formatInput(result = {}, options = {}) { | ||
var _options$color = options.color; | ||
const enabled = _options$color === undefined ? true : _options$color; | ||
var _result$errors = result.errors; | ||
const errors = _result$errors === undefined ? [] : _result$errors; | ||
var _result$input = result.input; | ||
const input = _result$input === undefined ? '' : _result$input; | ||
if (!input) { | ||
return ''; | ||
} | ||
const sign = '⧗'; | ||
const decoration = enabled ? _chalk2.default.gray(sign) : sign; | ||
const commitText = errors.length > 0 ? `\n${input}\n` : input.split('\n')[0]; | ||
const decoratedInput = enabled ? _chalk2.default.bold(commitText) : commitText; | ||
return `\n${decoration} input: ${decoratedInput}\n`; | ||
} | ||
function formatResult(result = {}, options = {}) { | ||
var _options$signs = options.signs; | ||
@@ -23,8 +58,8 @@ const signs = _options$signs === undefined ? DEFAULT_SIGNS : _options$signs; | ||
const colors = _options$colors === undefined ? DEFAULT_COLORS : _options$colors; | ||
var _options$color = options.color; | ||
const enabled = _options$color === undefined ? true : _options$color; | ||
var _report$errors = report.errors; | ||
const errors = _report$errors === undefined ? [] : _report$errors; | ||
var _report$warnings = report.warnings; | ||
const warnings = _report$warnings === undefined ? [] : _report$warnings; | ||
var _options$color2 = options.color; | ||
const enabled = _options$color2 === undefined ? true : _options$color2; | ||
var _result$errors2 = result.errors; | ||
const errors = _result$errors2 === undefined ? [] : _result$errors2; | ||
var _result$warnings = result.warnings; | ||
const warnings = _result$warnings === undefined ? [] : _result$warnings; | ||
@@ -48,16 +83,16 @@ | ||
function selectSign(report) { | ||
if (report.errors.length > 0) { | ||
function selectSign(result) { | ||
if (result.errors.length > 0) { | ||
return '✖'; | ||
} | ||
return report.warnings.length ? '⚠' : '✔'; | ||
return result.warnings.length ? '⚠' : '✔'; | ||
} | ||
function selectColor(report) { | ||
if (report.errors.length > 0) { | ||
function selectColor(result) { | ||
if (result.errors.length > 0) { | ||
return 'red'; | ||
} | ||
return report.warnings.length ? 'yellow' : 'green'; | ||
return result.warnings.length ? 'yellow' : 'green'; | ||
} | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=index.js.map |
'use strict'; | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _ava = require('ava'); | ||
@@ -29,95 +25,103 @@ | ||
const actual = (0, _2.default)(); | ||
t.deepEqual(actual, [ok]); | ||
t.deepEqual(actual, ok); | ||
}); | ||
(0, _ava2.default)('does nothing without report results', t => { | ||
const actual = (0, _2.default)({ results: [] }); | ||
t.deepEqual(actual, ok); | ||
}); | ||
(0, _ava2.default)('does nothing without .errors and .warnings', t => { | ||
const actual = (0, _2.default)({}); | ||
t.deepEqual(actual, [ok]); | ||
const actual = (0, _2.default)({ results: [{}] }); | ||
t.deepEqual(actual, ok); | ||
}); | ||
(0, _ava2.default)('returns empty summary of problems for empty .errors and .warnings', t => { | ||
var _format = (0, _2.default)({ | ||
errors: [], | ||
warnings: [] | ||
}), | ||
_format2 = (0, _slicedToArray3.default)(_format, 1); | ||
const actual = (0, _2.default)({ | ||
results: [{ | ||
errors: [], | ||
warnings: [] | ||
}] | ||
}); | ||
const msg = _format2[0]; | ||
t.true(msg.includes('0 problems, 0 warnings')); | ||
t.true(actual.includes('0 problems, 0 warnings')); | ||
}); | ||
(0, _ava2.default)('returns a correct of empty .errors and .warnings', t => { | ||
var _format3 = (0, _2.default)({ | ||
errors: [{ | ||
level: 2, | ||
name: 'error-name', | ||
message: 'There was an error' | ||
}], | ||
warnings: [{ | ||
level: 1, | ||
name: 'warning-name', | ||
message: 'There was a problem' | ||
const actualError = (0, _2.default)({ | ||
results: [{ | ||
errors: [{ | ||
level: 2, | ||
name: 'error-name', | ||
message: 'There was an error' | ||
}] | ||
}] | ||
}), | ||
_format4 = (0, _slicedToArray3.default)(_format3, 3); | ||
}); | ||
const err = _format4[0], | ||
prob = _format4[1], | ||
msg = _format4[2]; | ||
const actualWarning = (0, _2.default)({ | ||
results: [{ | ||
warnings: [{ | ||
level: 1, | ||
name: 'warning-name', | ||
message: 'There was a problem' | ||
}] | ||
}] | ||
}); | ||
t.true((0, _lodash2.default)(err, 'There was an error')); | ||
t.true((0, _lodash2.default)(prob, 'There was a problem')); | ||
t.true((0, _lodash2.default)(msg, '1 problems, 1 warnings')); | ||
t.true((0, _lodash2.default)(actualError, 'There was an error')); | ||
t.true((0, _lodash2.default)(actualError, '1 problems, 0 warnings')); | ||
t.true((0, _lodash2.default)(actualWarning, 'There was a problem')); | ||
t.true((0, _lodash2.default)(actualWarning, '0 problems, 1 warnings')); | ||
}); | ||
(0, _ava2.default)('uses appropriate signs by default', t => { | ||
var _format5 = (0, _2.default)({ | ||
errors: [{ | ||
level: 2, | ||
name: 'error-name', | ||
message: 'There was an error' | ||
}], | ||
warnings: [{ | ||
level: 1, | ||
name: 'warning-name', | ||
message: 'There was a problem' | ||
const actualError = (0, _2.default)({ | ||
results: [{ | ||
errors: [{ | ||
level: 2, | ||
name: 'error-name', | ||
message: 'There was an error' | ||
}] | ||
}] | ||
}), | ||
_format6 = (0, _slicedToArray3.default)(_format5, 2); | ||
}); | ||
const err = _format6[0], | ||
warn = _format6[1]; | ||
const actualWarning = (0, _2.default)({ | ||
results: [{ | ||
warnings: [{ | ||
level: 1, | ||
name: 'warning-name', | ||
message: 'There was a problem' | ||
}] | ||
}] | ||
}); | ||
t.true((0, _lodash2.default)(err, '✖')); | ||
t.true((0, _lodash2.default)(warn, '⚠')); | ||
t.true((0, _lodash2.default)(actualError, '✖')); | ||
t.true((0, _lodash2.default)(actualWarning, '⚠')); | ||
}); | ||
(0, _ava2.default)('uses signs as configured', t => { | ||
var _format7 = (0, _2.default)({ | ||
errors: [{ | ||
level: 2, | ||
name: 'error-name', | ||
message: 'There was an error' | ||
}], | ||
warnings: [{ | ||
level: 1, | ||
name: 'warning-name', | ||
message: 'There was a problem' | ||
const options = { signs: ['HNT', 'WRN', 'ERR'] }; | ||
const actualError = (0, _2.default)({ | ||
results: [{ | ||
errors: [{ | ||
level: 2, | ||
name: 'error-name', | ||
message: 'There was an error' | ||
}] | ||
}] | ||
}, { | ||
signs: ['HNT', 'WRN', 'ERR'] | ||
}), | ||
_format8 = (0, _slicedToArray3.default)(_format7, 2); | ||
}, options); | ||
const err = _format8[0], | ||
warn = _format8[1]; | ||
const actualWarning = (0, _2.default)({ | ||
results: [{ | ||
warnings: [{ | ||
level: 1, | ||
name: 'warning-name', | ||
message: 'There was a problem' | ||
}] | ||
}] | ||
}, options); | ||
t.true((0, _lodash2.default)(err, 'ERR')); | ||
t.true((0, _lodash2.default)(warn, 'WRN')); | ||
t.true((0, _lodash2.default)(actualError, 'ERR')); | ||
t.true((0, _lodash2.default)(actualWarning, 'WRN')); | ||
}); | ||
//# sourceMappingURL=index.test.js.map |
{ | ||
"name": "@commitlint/format", | ||
"version": "7.1.2", | ||
"version": "7.2.0", | ||
"description": "Format commitlint reports", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21358
173