Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Complexity

In this workshop, you'll be implementing simple algorithms for checking basic properties of code complexity.

Two design patterns are of importance here:

  • A Builder pattern, which is used to build up state and then finally emit.
  • A Visitor pattern, which is used to abstract the process of visiting a data structure such as abstract syntax tree (AST). The only input you have to provide is what action to perform at each node.

Workshop

The repository contains a stub that parses a javascript file and visits each function. However, we need to calculate the following properties:

  • ParameterCount: The number of parameters for functions
  • SimpleCyclomaticComplexity: The number of if statements/loops + 1
  • MaxNestingDepth: The max depth of scopes (nested ifs, loops, etc)
  • MaxConditions: The max number of conditions in one statement.

For live example of a code complexity calculator, see jscomplexity.

Esprima

Instead of building a scanner and parser by hand like we demonstrated previously. We will use an existing library, esprima, to parse code and create a static analyzer for basic code complexity metrics.

Video

If you have not already watched this video, you can get more background about Esprima here: Watch 5:00-14:30,28:00-34:00.

Interactive AST

Use the demo page to see what a code snippet looks like, in order to help you navigate the data structure.

For example, the following snippet:

function functionName( node )
{
	if( node.id )
	{
		return node.id.name;
	}
	return "anon function @" + node.loc.start.line;
}

Will appear as following, and:

image

Can be interacted with here.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages