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

literal-compare-order complains about two literal values being in the wrong order #168

Open
Krinkle opened this issue Apr 5, 2021 · 1 comment

Comments

@Krinkle
Copy link
Contributor

Krinkle commented Apr 5, 2021

If I understand our code correctly, it is currently limited to literal primitives in terms of recognising "literal" values, so when both values are literals but one is using an array or object, it is (imho wrongly) expressing a warning to swap them around.

	assert.equal( "foo", "foo" );
	assert.equal( "foo", [ "foo" ] );
	assert.equal( "foo", { toString: function() { return "foo"; } } );
	assert.equal( 0, [ 0 ] );
   74:16  error  Expected value "foo" should be specified after actual value [ "foo" ]                                   qunit/literal-compare-order
   75:16  error  Expected value "foo" should be specified after actual value { toString: function() { return "foo"; } }  qunit/literal-compare-order
   76:16  error  Expected value 0 should be specified after actual value [ 0 ]                                           qunit/literal-compare-order
   94:25  error  Expected value "foo" should be specified after actual value [ "foo" ]                                   qunit/literal-compare-order
   96:25  error  Expected value "foo" should be specified after actual value { toString: function() { return "foo"; } }  qunit/literal-compare-order
  524:19  error  Expected value "foo" should be specified after actual value [ "foo" ]                                   qunit/literal-compare-order
  525:19  error  Expected value "foo" should be specified after actual value { toString: function() { return "foo"; } }  qunit/literal-compare-order
  526:19  error  Expected value 0 should be specified after actual value [ 0 ]                                           qunit/literal-compare-order
  532:22  error  Expected value "foo" should be specified after actual value [ "foo" ]                                   qunit/literal-compare-order
  534:22  error  Expected value "foo" should be specified after actual value { toString: function() { return "foo"; } }  qunit/literal-compare-order

From https://github.com/qunitjs/qunit/blob/86fc89b3e443ccae5dedb5782412765c85a07a5e/test/main/assert.js#L523-L534

@platinumazure
Copy link
Owner

I agree that the rule should only fire if at least one value is an expression with at least one identifier, so I'll mark this as a bug.

I'm not sure if it's better to have a larger list of "literal" types, or if we should instead have a list of "non-literal" types to check against, or if we should have a recursive check that looks for identifiers... Thoughts and/or PRs appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants