What is a linter?

Before we get into the real content of this post, we need to establish what the heck a linter is.

In a nutshell, a linter is a tool used to analyze your code for problems and flag them.

In the Dynamo world, this is very common for Generative Design graphs. As you may know, Generative Design has a set of requirements in order to be successful. This includes the requirement of having inputs, outputs, and serialized Revit geometry. This is achieved through a custom linter!

Background

Dynamo has had a linter for quite a while to enable Generative Design to run how it does. However, the linter API was not ready for public use until recently. Thankfully, it is ready and has been enabled as of Dynamo 2.18.1. Personally speaking, as soon as I saw that a linter was being used, I was excited. Until I realized the API was internal only. But when it became public, I was excited again.

Use-Case

If you’ve used Dynamo for any time, you probably know some Dynamo graphs are imperfect. These include graphs without notes, groups, annotation, or appropriate documentation.

Previously, I had a bot that would use a machine-learning dataset to see if a graph had any annotations. But this was after the fact and mostly made for fun.

If you are curious about this bot, check it out here: https://twitter.com/DynamoFacadeBot/with_replies

Implementation

With the opening of the linter APIs, we can now define our linters as a package. This has resulted in a new sample for Dynamo users to learn from. Check that out here:

https://github.com/DynamoDS/DynamoSamples

The sample linter (once installed) is available under graph status:

Once the linter is enabled, there are 3 rules activated (at this time):

  • Slider as input rule: This rule alerts the end user that they might want to do so if the slider is not input or renamed. If a slider is not being used as input, it is typically unnecessary, and a number node or a code block would suffice.
  • Dropdown as Input Rule: Similar to the slider rule, but for dropdowns. It is worth considering an alternative if you aren’t using it as an input.
  • Nodes not in Groups: Having ungrouped nodes is a bad practice. This section allows the linter to flag this behavior based on linter settings in the extra folder in the extension directory.

 

Who is this for?

This is an addition to the Dynamo samples repo. This means that if you are a developer, you now have the infrastructure to build your own linters. At this time, it isn’t for end-users directly, but I hope to see development that allows defining linters through XML files or JSON.

How do I use it?

First, head on over to the Dynamo Samples Github repository.

https://github.com/DynamoDS/DynamoSamples

You can star (save) the repo or even create your own private fork. But, to get started quickly, download the source code as a zip.

After After downloading, it is best to unzip the source code with 7Zip. This helps with blocked references since they were downloaded from the internet.

Once the files are unzipped, you can navigate to the solution file and double-click to open it in Visual Studio.

As you can see, several projects in the Dynamo samples solution exist. You will see all related files in the SampleLinter project for linter workflows.

a

How is the Sample Structured?

Rules

The rules folder contains the appropriate checks to be run on the given Dynamo graph. Each rule consists of a GUID, a Rule Set, and the methods to check the nodes.

SampleLinter Extension Implementation (SampleLinter.cs)

This file loads the rules when Dynamo loads. It is similar to view extensions because it uses an XML to load the file. The XML is included in the sample dataset and is placed in the extra folder in the package directory.

SampleLinter_ExtensionDefinition

This file instructs the linter to load and be available in Dynamo.

 

Next Steps

With all of the Dynamo samples in the repo, there is an assumed amount of knowledge for development. We now have a custom package sample, a view extension sample, and a linter sample in the samples. If you are new to Visual Studio and programming in C#, here are a few resources to help get you started.

Dynamo Office Hours – “Discovering a New Environment”

In this office hours, the team covers how to get started with Visual Studio and C# for Dynamo packages.

Become a Dynamo Zero Touch C# Node Developer in 75 Minutes

This resource (provide by Thomas Mahon-Author of the BIMorph package) is an awesome resource for any aspiring C# Dynamo developer.

Become a Dynamo Zero Touch C# Node Developer in 75 Minutes