From 744a9310e0f4eec0c0d2c2416e985ca211bd671a Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 16 Aug 2016 16:22:23 -0700 Subject: [PATCH 1/2] assert: remove code that is never reached The internal function `truncate()` is only called with the first argument being the output of `util.inspect()`. `util.inspect()` calls its own internal `formatValue()` which is guaranteed to return a string. Therefore, we can remove the check in `truncate()` that the first argument is a string as well as code to handle the case where it is not a string. --- lib/assert.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 8a316ffa793d19..b01898e17ac7ff 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -61,11 +61,7 @@ assert.AssertionError = function AssertionError(options) { util.inherits(assert.AssertionError, Error); function truncate(s, n) { - if (typeof s === 'string') { - return s.length < n ? s : s.slice(0, n); - } else { - return s; - } + return s.length < n ? s : s.slice(0, n); } function getMessage(self) { From 510c80ab10a65a3a05ad1146691a6018cd4cb06d Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Wed, 17 Aug 2016 09:13:45 -0700 Subject: [PATCH 2/2] squash: remove ternary --- lib/assert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assert.js b/lib/assert.js index b01898e17ac7ff..9378631d2763bd 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -61,7 +61,7 @@ assert.AssertionError = function AssertionError(options) { util.inherits(assert.AssertionError, Error); function truncate(s, n) { - return s.length < n ? s : s.slice(0, n); + return s.slice(0, n); } function getMessage(self) {