Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused variables #3061

Merged
merged 3 commits into from Oct 27, 2017
Merged

Remove unused variables #3061

merged 3 commits into from Oct 27, 2017

Conversation

38elements
Copy link
Contributor

@38elements 38elements commented Oct 8, 2017

Requirements

The escape argument for inlineDiff() and unifiedDiff() in Base.list() is always false.
inlineDiff() and unifiedDiff() are only used in Base.list() .
I think the escape argument is unnecessary.

mocha/lib/reporters/base.js

Lines 188 to 220 in 9f204ba

var escape = true;
if (index === -1) {
msg = message;
} else {
index += message.length;
msg = stack.slice(0, index);
// remove msg from stack
stack = stack.slice(index + 1);
}
// uncaught
if (err.uncaught) {
msg = 'Uncaught ' + msg;
}
// explicitly show diff
if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) {
escape = false;
if (!(utils.isString(actual) && utils.isString(expected))) {
err.actual = actual = utils.stringify(actual);
err.expected = expected = utils.stringify(expected);
}
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
msg = '\n ' + color('error message', match ? match[1] : msg);
if (exports.inlineDiffs) {
msg += inlineDiff(err, escape);
} else {
msg += unifiedDiff(err, escape);
}
}

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 89.868% when pulling f8a26f1 on 38elements:patch-3 into 9f204ba on mochajs:master.

Copy link
Member

@boneskull boneskull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Since errorDiff is only called with false for the escape value, why not just remove the parameter entirely and do this?

function errorDiff(err, type) {
  var actual = escapeInvisibles(err.actual);
  var expected = escapeInvisibles(err.expected);
  /* ... */
}

@boneskull
Copy link
Member

good catch btw--it looks like this variable became useless somewhere around when inline diffs were added

@38elements
Copy link
Contributor Author

38elements commented Oct 9, 2017

Thank you for reviewing.
Since errorDiff() is only used in inlineDiff(), I removed not only escape but also type arguments.
The existing code is as follows.
Since Existing code uses err.actual and err.expected, I used err.actual and err.expected.

mocha/lib/reporters/base.js

Lines 447 to 459 in 9f204ba

function errorDiff (err, type, escape) {
var actual = escape ? escapeInvisibles(err.actual) : err.actual;
var expected = escape ? escapeInvisibles(err.expected) : err.expected;
return diff['diff' + type](actual, expected).map(function (str) {
if (str.added) {
return colorLines('diff added', str.value);
}
if (str.removed) {
return colorLines('diff removed', str.value);
}
return str.value;
}).join('');
}

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 89.859% when pulling 6862867 on 38elements:patch-3 into 9f204ba on mochajs:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 89.9% when pulling eee2fec on 38elements:patch-3 into 9f204ba on mochajs:master.

@boneskull
Copy link
Member

@38elements thanks!

@boneskull boneskull added the semver-patch implementation requires increase of "patch" version number; "bug fixes" label Oct 27, 2017
@boneskull boneskull merged commit 1bb6b39 into mochajs:master Oct 27, 2017
@boneskull boneskull added this to the v4.1.0 milestone Dec 29, 2017
@boneskull boneskull added type: cleanup a refactor and removed type: cleanup a refactor area: reporters involving a specific reporter labels Dec 29, 2017
sgilroy pushed a commit to TwineHealth/mocha that referenced this pull request Feb 27, 2019
* Remove unused variables

* Change errorDiff()

* Remove escapeInvisibles()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes" type: cleanup a refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants