Skip to content
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

Warnings/fix/navisworks #3083

Merged
merged 28 commits into from
Dec 1, 2023
Merged

Warnings/fix/navisworks #3083

merged 28 commits into from
Dec 1, 2023

Conversation

jsdbroughton
Copy link
Contributor

This global PR tackles many warnings to pre-empt the more granular initiative.

It is understood to address:

  • CA1032: Implement standard exception constructors
  • CA1051: Do not declare visible instance fields
  • CA1508: Avoid dead conditional code
  • CA1724: Type names should not match namespaces
  • CA1854: Prefer 'IsEmpty' over 'Count' to determine whether the collection contains any items
  • CA1859: Avoid unnecessary lambda captures
  • CA1860: Use Enumerable.Any() to determine whether any item exists in a collection
  • CA1861: Do not use 'Enumerable.Last()' to determine whether any item exists in a collection
  • IDE0004: Cast is redundant
  • IDE0010: Add missing cases to switch statements
  • IDE0033: Use explicitly provided tuple name
  • IDE0036: Order modifiers
  • IDE0044: Make field read-only
  • IDE0047: Remove unnecessary parentheses
  • IDE0059: Unnecessary assignment of a value
  • IDE0066: Convert switch statement to expression

3 suppressions have been introduced with Justifications:

  1. CA1812: Avoid uninstantiated internal classes: for the two classes that Navis will instantiate at runtime - this is the plugin pattern
  2. CA1508: Avoid dead conditional code: for one class that adds condition handlers not yet migrated to UI options. Yes, this is a partial implementation floating around.
  3. CA1031: Do not catch general exception types: For a single instance where Avalonia is initiated, I have no clue what exceptions that may throw.

AlanRynne and others added 27 commits November 28, 2023 16:38
* fix(core): IDE0005 Redundant Using statements

* fix(ci): GenerateDocumentationFile is required for IDE0005 to run on CI

* fix(ci): Allow warnings on all CI jobs
* fix(gh): IDE0005 for Grasshopper connector

* fix(rhino): IDE0005 for Rhino connector

* fix(rh/gh): IDE0005 for Rhino/Grasshopper shared converter
* remove connector usings

* remove converter usings

* remove revit shared resources usings

* dxfConverter

* remove more usings

* remove unused statement

* is this all of them?

---------

Co-authored-by: Connor Ivy <connor@speckle.systems>
* fix(dyn): IDE005 first run

* fix(dyn): Fix dangling warning
* fix(tekla): IDE0005 Redundant using statements

* fix(structuralUtils): IDE0005 Redundant Using statements
- Remove unused using statements
- Clean up namespace declaration
Update variable names in ConnectorNavisworksBindings.cs to follow naming conventions. Update _doc to s_doc, _cachedCommit to s_cachedCommit, and _cachedState to s_cachedState.
The try-catch block swallows unknown exceptions in the InitAvalonia instance of the CreateControlPane method.

Introduced as a justified suppression
Refactor code to use discard variable (`_`) instead of unused variable (`unused`) in ConverterNavisworks.ToSpeckle.cs. This change is to a different convention to eliminate the warning generated by the IDE.
- Changed return type of GetObjectsFromSelection and GetObjectsFromSavedSets methods from IEnumerable<ModelItem> to HashSet<ModelItem>
- Changed return type of TranslateFragmentGeometry method from IReadOnlyList<Base> to List<Base>
- Changed return type of MoveAndScaleVertices method from IEnumerable<double> to List<double>
- Changed return type of ViewpointToBase method from Base to View3D
Refactor code to use `static readonly` instead of `readonly static` for dictionary and string variables in multiple files. This improves code readability and follows best practices.
Refactor code to use `Count` property instead of `Any()` method for checking if a collection is empty. This change was made in multiple files: ConnectorNavisworksBindings.cs, ConnectorNavisworksBindings.Filters.cs, ConnectorNavisworksBindings.Send.cs, SelectionBuilder.cs, ConverterNavisworks.Properties.cs, and ConverterNavisworks.ToSpeckle.cs.
Mostly adding redundant default conditions.

- In ConnectorNavisworksBindings.Filters.cs, added a default case to handle savedItem.IsGroup == true.
- In Autosave.cs, added a default case with an empty comment to cover all logical scenarios for a boolean 'enable'.
- In SelectionBuilder.cs, added a default case in the switch statement to throw an ArgumentOutOfRangeException for an unrecognized filter type. Also added a default case in the switch statement to handle SDK object scenarios.
Refactor code to use a static readonly array for `lowerBounds` and `separator`. This improves code readability and maintainability by centralizing the values used in multiple places.
The variable "element" is now assigned from `pair.Value.Key` instead of `pair.Value.Item2` use of the explicit Tuple value provided.
Refactor ConverterNavisworks.Settings.cs to use `TryGetValue` instead of `ContainsKey` and indexer access for retrieving values from the Settings dictionary. This improves code readability and reduces unnecessary dictionary lookups.
Refactor switch statement to use switch expression in ConverterNavisworks.Other.cs.

This commit replaces the switch statement with a switch expression to simplify the code and improve readability. The `renderColor` variable is now assigned based on the value of `materialSettings.Mode`, with corresponding cases for "`active`", "`permanent`", and "`original`". A default case has also been added to handle any other values.
Refactor code to remove unnecessary parentheses.
Adds a suppression as the switch expression includes the method solutions for future development feature already scoped and partially implemented.
Add [SuppressMessage] attribute to internal classes in Ribbon.xaml.cs and SpeckleNavisworksCommand.cs to avoid CA1812 warning.

These classes are the Plugin and the Ribbon which will be instantiated by Navisworks at runtime.
- Remove cast to `Action`

consequently
- Remove unnecessary line breaks and indentation in the Invoke method call.
variable `_settingsHandler` was not marked as `readonly`.
Change the access modifier of `ProgressBar` field in `SelectionBuilder.cs` to `internal`. This fixes the Code Analysis warning CA1051: Do not declare visible instance fields
Refactor `Utilities` class to `SpeckleNavisworksUtilities` to avoid clash with `Autodesk.Navisworks.Gui.Utilities`.

Update references in ConnectorNavisworksBindings.cs, ConnectorNavisworksBindings.Send.cs, and SpeckleStreamManager.cs to use the new class name.
@jsdbroughton
Copy link
Contributor Author

jsdbroughton commented Nov 30, 2023

@AlanRynne i targeted this at dev as requested, but having branched from IDE0005 it includes some commit noise from the merged fixes contained prior. It passes CI, but let me know if you need me to finesse this a bit. Your GitFu may be needed.

Copy link
Contributor

@BovineOx BovineOx left a comment

Choose a reason for hiding this comment

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

Happy for this to go as-is but worth reviewing my comments as it throws up a few Qs on some of the existing code.

@@ -142,6 +142,8 @@ private static TreeNode GetViews(SavedItem savedItem)
return null;
case false:
return treeNode;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of missing the context here, might look at the file more completely but I was wondering about this default: break; looking like the default is to continue and wondering if the switch statement made sense still?

{
return node;
}

var elements = node.Elements.Select(RemoveNullNodes).Where(childNode => childNode != null).ToList();

if (!elements.Any())
if (elements.Count == 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given we've converted the LINQ to a list, Count should be fine but Any() will be faster in other places. What warning was this fixing?

@@ -2,27 +2,27 @@ namespace Speckle.ConnectorNavisworks.Entry;

public abstract class LaunchSpeckleConnector
Copy link
Contributor

Choose a reason for hiding this comment

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

Outside of review scope really, but these abstract classes look a bit funky.

"Speckle",
DisplayName = "Speckle",
Options = PluginOptions.None,
ToolTip = "Speckle Connector for Navisworks",
ExtendedToolTip = "Speckle Connector for Navisworks"
)
]
// ReSharper disable once ClassNeverInstantiated.Global - This is because of the mechanism Navisworks uses to load plugins.
[SuppressMessage(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, very clear 👍🏻

@@ -36,6 +36,10 @@ private void UpdateAutoSaveSetting(bool enable)
case true when _autosaveSetting:
rootOptions.SetBoolean("general.autosave.enable", true);
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

Again this makes me wonder if the switch use is a bit janky here...

@@ -37,6 +37,9 @@ private Element(string pseudoId)

public string PseudoId { get; private set; }

private static readonly int[] s_lowerBounds = new[] { 1 };
private static readonly string[] s_separator = new[] { "." };
Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose arrays cannot be changed but we can change the single elements within the arrays. I don't know what they are but curious about them. Are they app domain specific? Should anything be coming from CurrentCulture?

_uniqueModelItems.AddRange(GetObjectsFromSavedViewpoint());
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

Being picky I'd prefer a line space between the break of the previous case and the default case and generally between break and cases but maybe that's coming soon.

@@ -267,6 +265,10 @@ private TreeNode GetViews(SavedItem savedItem)
treeNode.Elements.Add(GetViews(childItem));
}
break;
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

So I think with one or two of these you're saying it has to be handled in a previous switch statement. I would argue if that is the case then the default could throw, because this throw helps validate our belief that it can never be X or Y. More likely, at least when I say this, I am saying it should never get to this default, throwing ensures that this continues to be true and if it ceases to be true, we can spot it.

@AlanRynne AlanRynne merged commit 6c9e573 into dev Dec 1, 2023
30 checks passed
@AlanRynne AlanRynne deleted the warnings/fix/navisworks branch December 1, 2023 12:43
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.

None yet

4 participants