Credo.Code (Credo v1.6.1) View Source

Credo.Code contains a lot of utility or helper functions that deal with the analysis of - you guessed it - code.

Whenever a function serves a general purpose in this area, e.g. getting the value of a module attribute inside a given module, we want to extract that function and put it in the Credo.Code namespace, so others can utilize them without reinventing the wheel.

Link to this section Summary

Functions

Returns an AST for a given String or Credo.SourceFile.

Takes a SourceFile and returns its source code stripped of all Strings and Sigils.

Takes a SourceFile and returns its source code stripped of all Strings, Sigils and code comments.

Returns true if the given child AST node is part of the larger parent AST node.

Returns an AST without its metadata.

Converts a String or Credo.SourceFile into a List of tuples of {line_no, line}.

Converts a String or Credo.SourceFile into a List of tokens using the :elixir_tokenizer.

Link to this section Functions

Link to this function

ast(string_or_source_file)

View Source

Returns an AST for a given String or Credo.SourceFile.

Link to this function

clean_charlists_strings_and_sigils(source_file_or_source)

View Source

Takes a SourceFile and returns its source code stripped of all Strings and Sigils.

Link to this function

clean_charlists_strings_sigils_and_comments(source_file_or_source, sigil_replacement \\ " ")

View Source

Takes a SourceFile and returns its source code stripped of all Strings, Sigils and code comments.

Link to this function

contains_child?(parent, child)

View Source

Returns true if the given child AST node is part of the larger parent AST node.

Link to this function

postwalk(ast_or_source_file, fun, accumulator \\ [])

View Source

Postwalks a given Credo.SourceFile's AST or a given AST.

Technically this is just a wrapper around Macro.postwalk/3.

Link to this function

prewalk(ast_or_source_file, fun, accumulator \\ [])

View Source

Prewalks a given Credo.SourceFile's AST or a given AST.

Technically this is just a wrapper around Macro.prewalk/3.

Returns an AST without its metadata.

Link to this function

to_lines(string_or_source_file)

View Source

Converts a String or Credo.SourceFile into a List of tuples of {line_no, line}.

Link to this function

to_tokens(string_or_source_file)

View Source

Converts a String or Credo.SourceFile into a List of tokens using the :elixir_tokenizer.

Link to this function

to_tokens(source, filename \\ "nofilename")

View Source