Bug 14055 - StartsWith inspection gives wrong hints
Summary: StartsWith inspection gives wrong hints
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: C# Binding ()
Version: 4.0.12
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: master
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-08-17 09:38 UTC by Neal
Modified: 2013-08-19 03:42 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Neal 2013-08-17 09:38:06 UTC
Hello,

I'd like to see a refactor like I have available in DevExpress CodeRush (VS 2012) where I can select a class and refactor "Move Class to File" and a new file is created in the same folder as this file and the file name is that of the class name, and the code is moved into this class.

Some programmers put multiple classes into a single file which is sometimes not the best idea or good coding practice (one file, multiple classes) and as CodeRush does it suggests moving these to their own files.  It would help us if Xam Studio could include this type of refactoring and start assisting with good programming practices as DevExprsss has a system in CodeRush called "Code Issues" that helps with this.  Another thing it does is grays out unused methods so you know when you have a method no longer in use, if you want to consider that as well.  Maybe you unwire an event subscription and the "Handles..." method becomes dead code.

Just a few ideas...

Thanks.
Comment 1 Mike Krüger 2013-08-17 12:54:41 UTC
We already have that btw.
Comment 2 Mike Krüger 2013-08-17 12:56:41 UTC
btw. we've a code issue system as well - you need to turn it on.

It's a bit hidden - search for 'Source Analysis' in the text editor options.

I think the move type to file refactoring is bound to this option as well ...
Comment 3 Neal 2013-08-17 13:06:10 UTC
Found it, turned it on, works great!  Thanks Mike
Comment 4 Mike Krüger 2013-08-17 13:14:17 UTC
I hope we'll add more actions & issues in the future :)

I'm currenly adding a ton and we've 2 gsoc students writing issues and actions.
Comment 5 Mike Krüger 2013-08-17 14:55:44 UTC
btw. if you find gaps in our code actions & code issues let me know.

Internally we've much more than on the 4.0.12 release - we got tons of new stuff the last month - but we need input & ideas.
Comment 6 Neal 2013-08-17 16:02:49 UTC
I would suggest that if a class resides in a file and the class name and file name don't match, offer these options like CodeRush:

1) Rename file to match type
2) Rename type to match file

If there are multiple classes in a file and there is one that exists that matches the file name and others that do not, suggest that those others are moved to their own file.

Is there a way to find suggestions suppressed so they can be turned back on?

Another option is a "Code Analysis Window" that you open and it analyzes the entire project or solution and lists the issues in a window that you can see from a higher level view of the entire work as to what needs to be fixed.

I suggest a replacement like I suggested for "braces" but for asyncifying methods.  For example a surround with "Task.Run".  Help people transition to async.

If I think of anything else I'll let you know.
Comment 7 Mikayla Hutchinson [MSFT] 2013-08-17 20:13:03 UTC
You can re-enable inspections using Preferences -> Source Code -> C# -> Code Inspections

There's no inspection for suggesting moving classes to their own files, there's only a context action to do the actual move.

There's a code analysis pad, though it's only enabled on master. We have a Summer of Code student working on it (these experimental source analysis features are side project for the core MD team, not official, so it's useful to have students working full time on them..).
Comment 8 Neal 2013-08-18 11:52:32 UTC
I think there is a problem with the .StartsWith inspection.  I have code that has something like:

if (Foo.StartsWith("Xam")...

I get a yellow underline telling me I'm supposed to be providing a StringComparison argument
Comment 9 Mike Krüger 2013-08-18 12:30:53 UTC
It's not a bug - you should provide a string comparison argument :)
Comment 10 Neal 2013-08-18 13:49:45 UTC
There are no overloads in this method.  Look at the assembly browser on StartsWith in this use:

UIDevice.CurrentDevice.SystemVersion.StartsWith("3");

It shows:

public bool StartsWith(string value)
{
	if (value == null)
	{
		throw new ArgumentNullException("value");
	}
	return CultureInfo.CurrentCulture.CompareInfo.IsPrefix(this, value, CompareOptions.None);
}
Comment 11 Mike Krüger 2013-08-18 14:25:55 UTC
I'll look at this code issue - seems it doesn't check the right method then.

(string.StartsWith () is the thing it should warn about)
Comment 12 Neal 2013-08-18 14:34:45 UTC
Another one of my favorite features in Coderush is "tab to next reference".  Click into a field or method name then everytime you tab it takes you to the next reference as if you did a find all references, tab takes you to each of those references.
Comment 13 Mike Krüger 2013-08-19 03:42:01 UTC
SystemVersion is a string - therefore StartsWith is correct.

There are overloads that take a StringComparison argument.

btw the next/prev reference thing is cmd+shift up/down (but you need to enable highlight referenced items first in the options)