Skip to content

Fix extents of UseSingularNoun and UseApprovedVerbs #495

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

Merged
merged 2 commits into from
Apr 7, 2016

Conversation

kapilmb
Copy link

@kapilmb kapilmb commented Apr 6, 2016

Fixes search logic to find the function name in a function definition.

Prior to the fix, if the function definition started on the first line of a script, the extent would include the entire function definition. This commit fixes that bug.

Fixes #492


This change is Reviewable

Fixes search logic to find the function name in a function definition.

Prior to the fix, if the function definition started on the first line of a script, the extent would include the entire function definition. This commit fixes that bug.
var funcNameToken = Tokens.Where(
token => ContainsExtent(functionDefinitionAst.Extent, token.Extent)
&& token.Text.Equals(functionDefinitionAst.Name));
if (funcNameToken.Any())
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simplify this a little bit by using funcNameToken.FirstOrDefault() which will return null if the enumerable has no items. Your logic is perfectly fine though, no need to change it. Just pointing out that this saves you from enumerating over the first item twice :)

Copy link
Author

Choose a reason for hiding this comment

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

We return the extent property of the first element and not the first element itself. Assuming all the tokens are non-null, If we just use FirstOrDefault we still need to check for null (if no token was found) before getting the Extent property.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, you'd need to check for null. The point is that FirstOrDefault saves you from two enumerations (which invoke a few methods internally). Any() causes one enumeration to see if there is a first item and First() causes another enumeration to get the first item. Like I said before, it's a very minor concern, I was just relaying a tip I've learned about IEnumerable over time.

Copy link
Author

Choose a reason for hiding this comment

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

Ahh...now I see your point clearly. This is helpful to know. Thanks.

@daviwil
Copy link
Contributor

daviwil commented Apr 7, 2016

Thanks for the fast response to this bug!

@daviwil
Copy link
Contributor

daviwil commented Apr 7, 2016

:lgtm:


Reviewed 2 of 3 files at r1, 1 of 1 files at r2.
Review status: all files reviewed at latest revision, 1 unresolved discussion.


Comments from Reviewable

@raghushantha
Copy link
Member

:lgtm:


Comments from Reviewable

@kapilmb
Copy link
Author

kapilmb commented Apr 7, 2016

Review status: all files reviewed at latest revision, 1 unresolved discussion.


Engine/Helper.cs, line 663 [r1] (raw file):
Done.


Comments from Reviewable

@kapilmb kapilmb merged commit cfe5cd4 into development Apr 7, 2016
@kapilmb kapilmb deleted the FixUseApprovedVerbsExtent branch April 11, 2016 20:12
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.

PSUseApprovedVerbs rule marks whole function at beginning of file
4 participants