Skip to content

Conversation

@Meir017
Copy link
Member

@Meir017 Meir017 commented Jul 5, 2018

closes #63

@Meir017
Copy link
Member Author

Meir017 commented Jul 5, 2018

@jnyrup with this fix the CollectionShouldNotBeNullOrEmptyAnalyzer will not report statements that have a method call between the NotBeNull & NotBeEmpty

var actual = new[] { "text1", "text2" };
actual
  .Should().NotBeNull()
  .And.HaveCount(2)
  .And.NotBeEmpty();

@jnyrup
Copy link
Member

jnyrup commented Jul 5, 2018

I guess one can always write arbitrarily obfuscated code that will hinder an analyzer in detecting patterns.

E.g. this valid but weird code

list.Should().NotBeEmpty().And.Should().NotBeNull();

is with 0.11.2 transformed into the uncompilable:

list.Should().NotBeNullOrEmpty().And.NotBeNull;

I have previously blindly trusted analyzers as "knowing the truth" and just applied its suggestions to e.g. an entire project, only to later find out that the applied code fixes had semantically changes, that broke the code.
I guess for somebody false positives could be a blocker for their adaption of the analyzer.
Roslynator e.g. chose to remove some analyzers, as their correctness could not be guaranteed and hence to could lead to invalid code.

@Meir017
Copy link
Member Author

Meir017 commented Jul 5, 2018

this case is related to the same issue that the analyzers used to look for the method in sequence but allowed method calls to exists between them, now they have to be one after another

@jnyrup
Copy link
Member

jnyrup commented Jul 5, 2018

And just to answer your question: I think it's fine to sacrifice functionality over correctness.

@Meir017 Meir017 merged commit 0a478e0 into master Jul 5, 2018
@Meir017 Meir017 deleted the bugfix/issue63 branch July 5, 2018 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CollectionShouldOnlyHaveUniqueItemsByComparer gives invalid code

3 participants