83 lines
1.9 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
Many assertions compare two objects or properties of these objects. Passing twice the same argument is likely to be a bug due to developer's carelessness.
2021-02-02 15:02:10 +01:00
This rule raises an issue when a Chai assertion is given twice the same argument.
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,javascript]
----
const assert = require('chai').assert;
describe("test the same object", function() {
it("uses chai 'assert'", function() {
const expected = '1'
const actual = (1).toString()
assert.equal(actual, actual); // Noncompliant
});
});
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[source,javascript]
----
const assert = require('chai').assert;
describe("test the same object", function() {
it("uses chai 'assert'", function() {
const expected = '1'
const actual = (1).toString()
assert.equal(actual, expected);
});
});
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Replace this argument or its duplicate at position [X].
=== Highlighting
If the same argument is passed twice to the same function
* Primary: the first expression occurence
message: 'Refactor this assertion to not pass the same argument twice.'
* Secondary: the second expression occurence
message: 'Argument [POSITION] has the same value.'
If the assertion is of the form ``++expect(obj).a(obj, other1)++``
* Primary: the duplicate argument.
message: 'Refactor this assertion to not pass the same value as in "expect()".'
* Secondary: the argument of "expect".
If the assertion is of the form ``++obj.should.be.closeTo(obj, other1, other2)++``
* Primary: the duplicate argument.
message: Refactor this assertion to not use the same value as the one asserted by "should".
* Secondary: the variable on which "should" is called.
no message
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]