Code2flow: Relatively unprejudiced name graphs for dynamic languages

Code2flow: Relatively unprejudiced name graphs for dynamic languages

code2flow logo

Version 2.3.0 Build passing Coverage 100% License MIT

Code2flow generates name graphs for dynamic programming language. Code2flow helps Python, Javascript, Ruby, and PHP.

The basic algorithm is discreet:

  1. Translate your offer files into ASTs.
  2. Obtain all characteristic definitions.
  3. Decide the keep those capabilities are called.
  4. Join the dots.

Code2flow is superb for:

  • Untangling spaghetti code.
  • Figuring out orphaned capabilities.
  • Getting contemporary developers as a lot as trip.

Code2flow will present a shimmering unprejudiced estimate of your venture’s structure. No algorithm can generate a very most attention-grabbing name graph for a dynamic language – even much less so if that language is duck-typed. Gaze the known limitations within the part below.

(Under: Code2flow running on itself (excl javascript, PHP, & Ruby for readability))

code2flow running against itself


While you happen to build no longer maintain it already, you are going to additionally deserve to set up graphviz. Installation directions is also stumbled on here.

Moreover, counting on the language you derive to deserve to parse, that you just may perhaps additionally want to set up additional dependencies:


To generate a DOT file urge one thing love:


Or, for javascript:

code2flow myjavascriptfile.js

You are going to also additionally specify more than one files or import directories:

code2flow venture/itemizing/source_a.js venture/itemizing/source_b.js
code2flow venture/itemizing/*.js
code2flow venture/itemizing --language js

There are a ton of bid line alternatives, to be aware all of them, urge:

How code2flow works

Code2flow approximates the structure of tasks in dynamic languages. It’s no longer doable to generate a very most attention-grabbing callgraph for a dynamic language.

Detailed algorithm:

  1. Generate an AST of the offer code
  2. Recursively separate groups and nodes. Teams are files, modules, or lessons. More precisely, groups are namespaces the keep capabilities are living. Nodes are the capabilities themselves.
  3. For all nodes, name characteristic calls in those nodes.
  4. For all nodes, name in-scope variables. Strive to put those variables to explicit nodes and groups. Here’s the keep there may perhaps be just a few ambiguity within the algorithm consequently of it’s far doable to know the forms of variables in dynamic languages. So, as a change, heuristics wishes to be worn.
  5. For all calls in all nodes, try to derive a match from the in-scope variables. This will also be an edge.
  6. If a definitive match from in-scope variables can’t be stumbled on, try to derive a single match from all diverse groups and nodes.
  7. Neat orphaned nodes and groups.
  8. Output results.

Why is it no longer doable to generate a very most attention-grabbing name graph?

Take care of in mind this toy instance in Python

def func_factory(param):
    if param < .5:



Hey! look, i give tutorials to all my users and i help them!