Skip to content

Commit afc6766

Browse files
committed
Merge branch 'rubberduck-vba-next' into CodeExplorer
2 parents 3dd8766 + d4c0d8b commit afc6766

File tree

124 files changed

+16889
-11079
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+16889
-11079
lines changed

README.md

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Rubberduck](http://i.stack.imgur.com/taIMg.png)
1+
![Rubberduck](http://i.stack.imgur.com/vmqXM.png)
22

33
| Branch | Build Status |
44
|------------|--------------|
@@ -12,37 +12,38 @@
1212

1313
Rubberduck is a COM Add-In for the VBA IDE that makes VBA development even more enjoyable, by extending the Visual Basic Editor (VBE) with menus, toolbars and toolwindows that enable things we didn't even think were possible when we first started this project.
1414

15-
If you're learning VBA, Rubberduck can help you avoid a few common beginner mistakes, and can probably show you a trick or two - even if you're only ever writing *macros*. If you're a more advanced programmer, you will appreciate the richness of [Rubberduck's feature set](https://github.com/rubberduck-vba/Rubberduck/wiki/Features).
15+
If you're learning VBA, Rubberduck can help you avoid a few common beginner mistakes, and can probably show you a trick or two - even if you're only ever writing *macros*. If you're a more advanced programmer, you will appreciate the richness of [Rubberduck's feature set](https://github.com/retailcoder/Rubberduck/wiki/Features).
1616

1717
[**Follow us on Twitter!**](https://twitter.com/rubberduckvba)
1818

19-
[**Rubberduck Wiki**](https://github.com/rubberduck-vba/Rubberduck/wiki)
19+
[**Rubberduck Wiki**](https://github.com/retailcoder/Rubberduck/wiki)
2020

2121
---
2222

23-
#Contributing
23+
#[Contributing](https://github.com/rubberduck-vba/Rubberduck/wiki/Contributing)
2424

2525
If you're a C# developer looking for a fun project to contribute to, feel free to fork the project and
26-
[come meet the devs in Code Review's "VBA" chatroom][chat] - we'll be happy to answer your questions and help you help us take the VBE into the 21st century!
27-
28-
Some issues are tagged with [help-wanted][helpwanted], but that doesn't mean we can't use some help with anything else in the project - if this project interests you, we want to hear from you!
26+
[come meet the devs in Code Review's "VBA Rubberducking" chatroom][chat] - we'll be happy to answer your questions and help you help us!
2927

3028
We follow a [development branch workflow][branch], so please submit any Pull Requests to the `next` branch.
3129

32-
There is additonal information about [building the project in our wiki][install].
33-
34-
[chat]:http://chat.stackexchange.com/rooms/14929/vba
30+
[chat]:http://chat.stackexchange.com/rooms/14929
3531
[helpwanted]:https://github.com/rubberduck-vba/Rubberduck/labels/help-wanted
36-
[install]:https://github.com/rubberduck-vba/Rubberduck/wiki/Building-&-Installation
3732
[branch]:https://github.com/rubberduck-vba/Rubberduck/issues/288
3833

3934
---
4035

36+
#[Installing](https://github.com/rubberduck-vba/Rubberduck/wiki/Installing)
37+
38+
This section was moved to a dedicated wiki page.
39+
40+
---
41+
4142
#License
4243

4344
Rubberduck is a COM add-in for the VBA IDE (VBE).
4445

45-
Copyright (C) 2014-2015 Mathieu Guindon & Christopher McClellan
46+
Copyright (C) 2014-2016 Mathieu Guindon & Christopher McClellan
4647

4748
This program is free software: you can redistribute it and/or modify
4849
it under the terms of the GNU General Public License as published by
@@ -59,24 +60,6 @@ along with this program. If not, see http://www.gnu.org/licenses/.
5960

6061
---
6162

62-
#Installation
63-
64-
Visit our releases page, [download the installer](https://github.com/rubberduck-vba/Rubberduck/releases/latest), and run the Setup.exe.
65-
66-
If you're **upgrading** from version 1.0, you will need to completely uninstall it before installing the newest release. This isn't necessary when upgrading from newer versions. Also, be sure to back up the `rubberduck.config` file in the `\AppData\Roaming\Rubberduck\` directory prior to installation.
67-
68-
##System Requirements
69-
70-
- Windows Vista or more recent (tested on Win7 and Win8.1)
71-
- .Net Framework 4.5
72-
- Microsoft Office 97-2003 or higher
73-
74-
Please feel free to test it on other versions and [submit any bugs on our issue tracker](https://github.com/rubberduck-vba/Rubberduck/issues).
75-
76-
**Note:** The 1.2 installer doesn't work for 64 bit versions of office. You can find the [work around here](https://rubberduckvba.wordpress.com/2015/03/11/64-bit-rubberduck-a-work-around-until-release-1-21-soon/).
77-
78-
---
79-
8063
#Attributions
8164

8265
##Software & Libraries
@@ -105,16 +88,6 @@ LibGit2Sharp is the library that has allowed us to integrate Git right into the
10588
10689
Which basically means it's a reimplementation of Git in C. It also [happens to be the technology Microsoft uses for their own Git integration with Visual Studio](http://www.hanselman.com/blog/GitSupportForVisualStudioGitTFSAndVSPutIntoContext.aspx).
10790

108-
###[Smart Indenter](http://www.oaltd.co.uk/Indenter/)
109-
110-
**What is Smart Indenter?**
111-
112-
> *The Smart Indenter is a utility to tidy up VBA code by rebuilding the indentation of each line. Most developers naturally indent code within control structures, such as For...Next, If...End If, etc. Many developers also indent all the code within a procedure, to ease identification of line labels, error handling blocks etc. From that point on, there is much more variety in indenting styles, ranging from how to treat declaration lines to handling end-of-line comments.*
113-
114-
The Rubberduck project was graciously offered the source code for this formidable tool by Stephen Bullen and Rob Bovey. We've translated the VB6 source code to C# and embedded a managed indenting API that Rubberduck calls into, while decoupling the indenter logic from the Windows Registry so we could store indenter options together with the Rubberduck settings, and configure the indenter from Rubberduck's options dialog.
115-
116-
If you're already using Smart Indenter, Rubberduck's options dialog allow importing the settings from the registry. If we did our part well, you can uninstall Smart Indenter after installing Rubberduck 2.0, and still benefit from the smartest indenting tool available for VBA.
117-
11891
##Icons
11992

12093
We didn't come up with these icons ourselves! Here's who did what:
@@ -133,7 +106,7 @@ Icons in the `./Resources/Microsoft/` directory are licensed under Microsoft's S
133106

134107
> You have a right to Use and Distribute these files. This means that you are free to copy and use these images in documents and projects that you create, but you may not modify them in anyway.
135108
136-
For more information, please see the EULAs in the [./Resources/Microsoft/ directory](https://github.com/rubberduck-vba/Rubberduck/tree/master/RetailCoder.VBE/Resources/Microsoft).
109+
For more information, please see the EULAs in the [./Resources/Microsoft/ directory](https://github.com/retailcoder/Rubberduck/tree/master/RetailCoder.VBE/Resources/Microsoft).
137110

138-
* [Visual Studio 2013 Image Library EULA](https://github.com/rubberduck-vba/Rubberduck/blob/master/RetailCoder.VBE/Resources/Microsoft/Visual%20Studio%202013%20Image%20Library%20EULA.rtf)
139-
* [Visual Studio 2012 Image Library EULA](https://github.com/rubberduck-vba/Rubberduck/blob/master/RetailCoder.VBE/Resources/Microsoft/Visual%20Studio%202012%20Image%20Library%20EULA.rtf)
111+
* [Visual Studio 2013 Image Library EULA](https://github.com/retailcoder/Rubberduck/blob/master/RetailCoder.VBE/Resources/Microsoft/Visual%20Studio%202013%20Image%20Library%20EULA.rtf)
112+
* [Visual Studio 2012 Image Library EULA](https://github.com/retailcoder/Rubberduck/blob/master/RetailCoder.VBE/Resources/Microsoft/Visual%20Studio%202012%20Image%20Library%20EULA.rtf)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Antlr4.Runtime;
2+
using Rubberduck.Parsing;
3+
using Rubberduck.Parsing.Grammar;
4+
using Rubberduck.UI;
5+
using Rubberduck.VBEditor;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Text.RegularExpressions;
9+
10+
namespace Rubberduck.Inspections
11+
{
12+
public class ConvertToProcedureQuickFix : CodeInspectionQuickFix
13+
{
14+
private readonly IEnumerable<string> _returnStatements;
15+
16+
public ConvertToProcedureQuickFix(ParserRuleContext context, QualifiedSelection selection)
17+
: this(context, selection, new List<string>())
18+
{
19+
}
20+
21+
public ConvertToProcedureQuickFix(ParserRuleContext context, QualifiedSelection selection, IEnumerable<string> returnStatements)
22+
: base(context, selection, RubberduckUI.Inspections_ConvertFunctionToProcedure)
23+
{
24+
_returnStatements = returnStatements;
25+
}
26+
27+
public override void Fix()
28+
{
29+
var context = (VBAParser.FunctionStmtContext)Context;
30+
var visibility = context.visibility() == null ? string.Empty : context.visibility().GetText() + ' ';
31+
var name = ' ' + context.ambiguousIdentifier().GetText();
32+
var args = context.argList().GetText();
33+
var asType = context.asTypeClause() == null ? string.Empty : ' ' + context.asTypeClause().GetText();
34+
35+
var oldSignature = visibility + Tokens.Function + name + args + asType;
36+
var newSignature = visibility + Tokens.Sub + name + args;
37+
38+
var procedure = Context.GetText();
39+
string noReturnStatements = procedure;
40+
_returnStatements.ToList().ForEach(returnStatement =>
41+
noReturnStatements = Regex.Replace(noReturnStatements, @"[ \t\f]*" + returnStatement + @"[ \t\f]*\r?\n?", ""));
42+
var result = noReturnStatements.Replace(oldSignature, newSignature)
43+
.Replace(Tokens.End + ' ' + Tokens.Function, Tokens.End + ' ' + Tokens.Sub)
44+
.Replace(Tokens.Exit + ' ' + Tokens.Function, Tokens.Exit + ' ' + Tokens.Sub);
45+
46+
var module = Selection.QualifiedName.Component.CodeModule;
47+
var selection = Context.GetSelection();
48+
49+
module.DeleteLines(selection.StartLine, selection.LineCount);
50+
module.InsertLines(selection.StartLine, result);
51+
}
52+
}
53+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Parsing.Symbols;
4+
using Rubberduck.Parsing.VBA;
5+
using Rubberduck.Parsing.Grammar;
6+
using Antlr4.Runtime;
7+
using Rubberduck.UI;
8+
9+
namespace Rubberduck.Inspections
10+
{
11+
public sealed class FunctionReturnValueNotUsedInspection : InspectionBase
12+
{
13+
public FunctionReturnValueNotUsedInspection(RubberduckParserState state)
14+
: base(state)
15+
{
16+
Severity = CodeInspectionSeverity.Warning;
17+
}
18+
19+
public override string Description { get { return InspectionsUI.FunctionReturnValueNotUsedInspection; } }
20+
public override CodeInspectionType InspectionType { get { return CodeInspectionType.CodeQualityIssues; } }
21+
22+
public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
23+
{
24+
var functions = UserDeclarations.Where(function => function.DeclarationType == DeclarationType.Function).ToList();
25+
var returnValueNotUsedFunctions = functions.Where(function =>
26+
function.References.All(usage =>
27+
IsReturnStatement(function, usage) || IsAddressOfCall(usage) || IsCallWithoutAssignment(usage)));
28+
29+
var issues = returnValueNotUsedFunctions
30+
.Select(function =>
31+
new FunctionReturnValueNotUsedInspectionResult(
32+
this,
33+
function.Context,
34+
function.QualifiedName,
35+
function.References.Where(usage => IsReturnStatement(function, usage)).Select(usage => usage.Context.Parent.Parent.Parent.GetText())));
36+
37+
return issues;
38+
}
39+
40+
private bool IsAddressOfCall(IdentifierReference usage)
41+
{
42+
RuleContext current = usage.Context;
43+
while (current != null && !(current is VBAParser.VsAddressOfContext)) current = current.Parent;
44+
return current != null;
45+
}
46+
47+
private bool IsReturnStatement(Declaration function, IdentifierReference assignment)
48+
{
49+
return assignment.ParentScope == function.Scope;
50+
}
51+
52+
private bool IsCallWithoutAssignment(IdentifierReference usage)
53+
{
54+
return usage.Context.Parent != null && usage.Context.Parent is VBAParser.ICS_B_ProcedureCallContext;
55+
}
56+
}
57+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using Antlr4.Runtime;
3+
using Rubberduck.Parsing.Grammar;
4+
using Rubberduck.UI;
5+
using Rubberduck.VBEditor;
6+
using System.Text.RegularExpressions;
7+
using System.Linq;
8+
using System;
9+
using Rubberduck.Parsing;
10+
11+
namespace Rubberduck.Inspections
12+
{
13+
public class FunctionReturnValueNotUsedInspectionResult : CodeInspectionResultBase
14+
{
15+
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;
16+
17+
public FunctionReturnValueNotUsedInspectionResult(IInspection inspection, ParserRuleContext context, QualifiedMemberName qualifiedName, IEnumerable<string> returnStatements)
18+
: base(inspection, string.Format(inspection.Description, qualifiedName.MemberName), qualifiedName.QualifiedModuleName, context)
19+
{
20+
_quickFixes = new[]
21+
{
22+
new ConvertToProcedureQuickFix(context, QualifiedSelection, returnStatements),
23+
};
24+
}
25+
26+
public override IEnumerable<CodeInspectionQuickFix> QuickFixes { get { return _quickFixes; } }
27+
}
28+
}

RetailCoder.VBE/Inspections/InspectionsUI.Designer.cs

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/Inspections/InspectionsUI.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,10 @@
371371
<data name="SelfAssignedDeclarationInspectionName" xml:space="preserve">
372372
<value>Self-assigned property</value>
373373
</data>
374+
<data name="FunctionReturnValueNotUsedInspectionName" xml:space="preserve">
375+
<value>Function return value is never used.</value>
376+
</data>
377+
<data name="FunctionReturnValueNotUsedInspection" xml:space="preserve">
378+
<value>Return value of function '{0}' is never used.</value>
379+
</data>
374380
</root>

RetailCoder.VBE/Inspections/MoveFieldCloserToUsageInspection.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
namespace Rubberduck.Inspections
99
{
10-
public sealed class MoveFieldCloseToUsageInspection : InspectionBase
10+
public sealed class MoveFieldCloserToUsageInspection : InspectionBase
1111
{
1212
private readonly ICodePaneWrapperFactory _wrapperFactory;
1313

14-
public MoveFieldCloseToUsageInspection(RubberduckParserState state)
14+
public MoveFieldCloserToUsageInspection(RubberduckParserState state)
1515
: base(state)
1616
{
1717
_wrapperFactory = new CodePaneWrapperFactory();
@@ -52,7 +52,7 @@ public override IEnumerable<CodeInspectionResultBase> GetInspectionResults()
5252
}.Contains(parentDeclaration.DeclarationType);
5353
})
5454
.Select(issue =>
55-
new MoveFieldCloseToUsageInspectionResult(this, issue, State, _wrapperFactory, new MessageBox()));
55+
new MoveFieldCloserToUsageInspectionResult(this, issue, State, _wrapperFactory, new MessageBox()));
5656
}
5757

5858
private Declaration ParentDeclaration(IdentifierReference reference)

RetailCoder.VBE/Inspections/MoveFieldCloserToUsageInspectionResult.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
namespace Rubberduck.Inspections
1111
{
12-
public class MoveFieldCloseToUsageInspectionResult : CodeInspectionResultBase
12+
public class MoveFieldCloserToUsageInspectionResult : CodeInspectionResultBase
1313
{
1414
private readonly IEnumerable<CodeInspectionQuickFix> _quickFixes;
1515

16-
public MoveFieldCloseToUsageInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox)
16+
public MoveFieldCloserToUsageInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox)
1717
: base(inspection, string.Format(inspection.Description, target.IdentifierName), target)
1818
{
1919
_quickFixes = new[]

RetailCoder.VBE/Inspections/MultilineParameterInspectionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public override void Fix()
4747
var parameter = lines.Substring(adjustedStartColumn,
4848
adjustedEndColumn - adjustedStartColumn)
4949
.Replace("_", "")
50-
.RemoveExtraSpaces();
50+
.RemoveExtraSpacesLeavingIndentation();
5151

5252
var start = startLine.Remove(adjustedStartColumn);
5353
var end = lines.Remove(0, adjustedEndColumn);

RetailCoder.VBE/Inspections/NonReturningFunctionInspectionResult.cs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Rubberduck.Parsing.Grammar;
66
using Rubberduck.UI;
77
using Rubberduck.VBEditor;
8+
using System.Text.RegularExpressions;
89

910
namespace Rubberduck.Inspections
1011
{
@@ -27,35 +28,4 @@ public NonReturningFunctionInspectionResult(IInspection inspection, string resul
2728

2829
public override IEnumerable<CodeInspectionQuickFix> QuickFixes { get { return _quickFixes; } }
2930
}
30-
31-
public class ConvertToProcedureQuickFix : CodeInspectionQuickFix
32-
{
33-
public ConvertToProcedureQuickFix(ParserRuleContext context, QualifiedSelection selection)
34-
: base(context, selection, RubberduckUI.Inspections_ConvertFunctionToProcedure)
35-
{
36-
}
37-
38-
public override void Fix()
39-
{
40-
var context = (VBAParser.FunctionStmtContext) Context;
41-
var visibility = context.visibility() == null ? string.Empty : context.visibility().GetText() + ' ';
42-
var name = ' ' + context.ambiguousIdentifier().GetText();
43-
var args = context.argList().GetText();
44-
var asType = context.asTypeClause() == null ? string.Empty : ' ' + context.asTypeClause().GetText();
45-
46-
var oldSignature = visibility + Tokens.Function + name + args + asType;
47-
var newSignature = visibility + Tokens.Sub + name + args;
48-
49-
var procedure = Context.GetText();
50-
var result = procedure.Replace(oldSignature, newSignature)
51-
.Replace(Tokens.End + ' ' + Tokens.Function, Tokens.End + ' ' + Tokens.Sub)
52-
.Replace(Tokens.Exit + ' ' + Tokens.Function, Tokens.Exit + ' ' + Tokens.Sub);
53-
54-
var module = Selection.QualifiedName.Component.CodeModule;
55-
var selection = Context.GetSelection();
56-
57-
module.DeleteLines(selection.StartLine, selection.LineCount);
58-
module.InsertLines(selection.StartLine, result);
59-
}
60-
}
6131
}

0 commit comments

Comments
 (0)