Credence.RuleName (credence v0.7.0)

Copy Markdown

The one place that turns a rule's name into every derived form — snake, Pascal, rule atom, rule module, and the conventional paths/modules of its test files.

The naming convention (rule Credence.Pattern.NoFoo lives at lib/pattern/no_foo.ex; its check test is test/pattern/no_foo_check_test.exs defining Credence.Pattern.NoFooCheckTest) used to be re-typed in several places — MetaTestSupport.test_path/2, RuleTestCompletenessTest, and (soon) the generator and its pin. Re-typing means the copies can drift. Here it is derived once, and everyone — the generator that writes the files, the gates that check them, and the pin that proves the generator matches the gates — calls the same code. There is nothing to drift from.

Summary

Functions

Derive every name form from a rule name ("NoFooBar" or "no_foo_bar") and its type.

Derive from an existing rule module, inferring the type from its namespace. Used by the gates, which iterate over discovered rule modules.

The conventionally-named test module for a rule's kind file, e.g. Credence.Pattern.NoFooCheckTest for kind "check".

The conventional path of a rule's kind test file ("test/<type>/<snake>_<kind>_test.exs"). kind is "check", "fix", "equivalence", "analyze", …

Types

derived()

@type derived() :: %{
  type: rule_type(),
  snake: String.t(),
  pascal: String.t(),
  atom: atom(),
  rule_module: module(),
  rule_path: String.t(),
  test_dir: String.t()
}

rule_type()

@type rule_type() :: :pattern | :syntax | :semantic

Functions

derive(name, type)

@spec derive(String.t(), rule_type()) :: derived()

Derive every name form from a rule name ("NoFooBar" or "no_foo_bar") and its type.

from_module(module)

@spec from_module(module()) :: derived()

Derive from an existing rule module, inferring the type from its namespace. Used by the gates, which iterate over discovered rule modules.

test_module(map, kind)

@spec test_module(derived(), String.t()) :: module()

The conventionally-named test module for a rule's kind file, e.g. Credence.Pattern.NoFooCheckTest for kind "check".

test_path(map, kind)

@spec test_path(derived(), String.t()) :: String.t()

The conventional path of a rule's kind test file ("test/<type>/<snake>_<kind>_test.exs"). kind is "check", "fix", "equivalence", "analyze", …