Create a gist now

Instantly share code, notes, and snippets.

anonymous /aspnet_mvc_dups.rb
Created Dec 13, 2010

Finds dups of the form if(argumentName == null) {throw new ArgumentNullException("argmentName")}
def find_null_argument_check file_path
found = []
line_num = 0
last_line_null_check = false
variable_name = ''
File.open(file_path, 'r').each_line do |line|
line_num += 1
line_stripped = line.strip
if(last_line_null_check && variable_name)
if line_stripped =~ /throw\s*new\s*ArgumentNullException\(\"#{variable_name}\"\)/
found += "File\t#{file_path}\tLine\t#{line_num}".to_a
end
end
line_stripped.gsub! /\s*/, ''
matches = /if\((\w*)==null\)/.match line_stripped
if matches && matches[1]
variable_name = matches[1].to_s
last_line_null_check = true
else
variable_name = ''
last_line_null_check = false
end
end
found
end
def visit(dir)
total_found = []
Dir.entries(dir).reject{|d| d == '.' || d == '..'}.each do |entry|
entry_path = File.join(Dir.new(dir).path, entry)
if File.file?(entry_path)
if entry_path =~ /.cs$/
total_found += find_null_argument_check(entry_path)
end
else
total_found += visit(entry_path) unless File.file?(entry)
end
end
total_found
end
root_dir = File.join(File.dirname(__FILE__))
total_found = visit(root_dir) do |entry_path|
find_null_argument_check(entry_path)
end
puts "Total #{total_found.length} dups found"
total_found.each{|found| puts found}
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file
Total 161 dups found
File Line
BridgeContext.cs 9
BridgeModule.cs 10
BridgeRequest.cs 29
XmlBridgeTransformer.cs 14
DynamicDataSearchSiteMapProvider.cs 34
DynamicDataSearchSiteMapProvider.cs 224
WindowsLiveSearchProvider.cs 75
DataAdapterAttribute.cs 17
DataAdapterAttribute.cs 26
DataService.cs 380
DiagnosticsHandler.cs 17
DlrView.cs 37
AdvancedFieldGenerator.cs 35
QueryExtensions.cs 11
MapScaffoldRouteExtensions.cs 24
IQueryableExtensions.cs 11
ExpressionHelper.cs 12
AcceptAjaxAttribute.cs 11
AsyncController.cs 29
AsyncControllerActionInvoker.cs 51
AsyncManager.cs 43
AsyncManager.cs 56
AsyncResultWrapper.cs 32
AsyncResultWrapper.cs 53
AsyncResultWrapper.cs 56
AsyncTimeoutAttribute.cs 26
ButtonBuilder.cs 50
ButtonsAndLinkExtensions.cs 89
CookieTempDataProvider.cs 15
FileCollectionModelBinder.cs 15
FileCollectionModelBinder.cs 18
MailToExtensions.cs 39
MailToExtensions.cs 42
RadioExtensions.cs 69
ReflectedAsyncControllerDescriptor.cs 15
ReflectedAsyncControllerDescriptor.cs 30
ReflectedAsyncPatternActionDescriptor.cs 32
ReflectedAsyncPatternActionDescriptor.cs 65
ReflectedAsyncPatternActionDescriptor.cs 68
ReflectedAsyncPatternActionDescriptor.cs 157
ReflectedAsyncPatternActionDescriptor.cs 189
ReflectedDelegatePatternActionDescriptor.cs 32
ReflectedDelegatePatternActionDescriptor.cs 59
ReflectedDelegatePatternActionDescriptor.cs 62
ReflectedDelegatePatternActionDescriptor.cs 182
ReflectedEventPatternActionDescriptor.cs 31
ReflectedEventPatternActionDescriptor.cs 64
ReflectedEventPatternActionDescriptor.cs 67
ReflectedEventPatternActionDescriptor.cs 197
ReflectedEventPatternActionDescriptor.cs 206
RequireSslAttribute.cs 18
AcceptVerbsAttribute.cs 52
ActionDescriptor.cs 29
ActionDescriptor.cs 52
ActionExecutedContext.cs 18
ActionExecutingContext.cs 17
ActionExecutingContext.cs 20
AjaxHelper.cs 13
AjaxHelper.cs 16
AjaxHelper.cs 19
AjaxRequestExtensions.cs 8
AntiForgeryData.cs 22
AntiForgeryDataSerializer.cs 52
AuthorizeAttribute.cs 41
AuthorizeAttribute.cs 66
AuthorizeAttribute.cs 91
ContentResult.cs 25
Controller.cs 370
Controller.cs 373
ControllerActionInvoker.cs 128
ControllerBase.cs 72
ControllerBuilder.cs 41
ControllerBuilder.cs 49
ControllerContext.cs 29
ControllerContext.cs 44
ControllerContext.cs 47
ControllerDescriptor.cs 35
ControllerDescriptor.cs 44
DefaultControllerFactory.cs 55
DefaultModelBinder.cs 141
DefaultViewLocationCache.cs 35
DefaultViewLocationCache.cs 42
ExceptionContext.cs 18
FileContentResult.cs 11
FileResult.cs 35
FileStreamResult.cs 14
FormCollection.cs 21
FormCollection.cs 70
HandleErrorAttribute.cs 25
HandleErrorAttribute.cs 56
HandleErrorInfo.cs 9
InputExtensions.cs 104
MvcForm.cs 11
ValidationExtensions.cs 75
HtmlHelper.cs 29
HtmlHelper.cs 32
HtmlHelper.cs 35
HttpPostedFileBaseModelBinder.cs 9
HttpPostedFileBaseModelBinder.cs 12
HttpUnauthorizedResult.cs 8
JavaScriptResult.cs 13
JsonResult.cs 26
ModelBinderAttribute.cs 11
ModelBinderDictionary.cs 102
ModelError.cs 14
ModelStateDictionary.cs 18
ModelStateDictionary.cs 117
ModelStateDictionary.cs 131
MultiSelectList.cs 29
MvcHandler.cs 20
MvcHttpHandler.cs 9
NameValueCollectionExtensions.cs 14
NameValueCollectionExtensions.cs 17
OutputCacheAttribute.cs 105
ParameterDescriptor.cs 36
ParameterDescriptor.cs 45
RedirectResult.cs 28
RedirectToRouteResult.cs 44
ReflectedActionDescriptor.cs 24
ReflectedActionDescriptor.cs 30
ReflectedActionDescriptor.cs 76
ReflectedActionDescriptor.cs 79
ReflectedControllerDescriptor.cs 16
ReflectedControllerDescriptor.cs 31
ReflectedParameterDescriptor.cs 12
ReflectedParameterDescriptor.cs 15
ResultExecutedContext.cs 16
ResultExecutingContext.cs 16
RouteCollectionExtensions.cs 18
RouteCollectionExtensions.cs 21
RouteCollectionExtensions.cs 65
RouteCollectionExtensions.cs 68
UrlHelper.cs 15
UrlHelper.cs 18
ValidateAntiForgeryTokenAttribute.cs 43
ValidateInputAttribute.cs 21
ValueProviderResult.cs 87
ViewContext.cs 16
ViewContext.cs 19
ViewContext.cs 22
ViewContext.cs 25
ViewDataDictionary.cs 33
ViewEngineCollection.cs 19
ViewEngineCollection.cs 27
ViewEngineCollection.cs 64
ViewEngineCollection.cs 76
ViewEngineResult.cs 9
ViewEngineResult.cs 17
ViewEngineResult.cs 20
ViewResultBase.cs 66
VirtualPathProviderViewEngine.cs 79
VirtualPathProviderViewEngine.cs 98
WebFormView.cs 48
MemberHelper.cs 11
MemberHelper.cs 24
MemberHelper.cs 52
MemberHelper.cs 88
DiskImageStore.cs 55
ImageHandler.cs 89
ImageInfo.cs 17
ImageInfo.cs 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment