Tiny Robots Credo Checks

CIHex versionHex downloadsLicense

Highly opinionatedCredo checks used by Tiny Robots. They encode the Elixir / Phoenix / LiveView conventions we rely on across our apps.

These checks are opinionated by design — they enforce the Tiny Robots house style and may not be suitable (or desired) for contribution upstream to mainline Credo. They're published here so our projects can share them, but anyone sharing our conventions is welcome to use them.

Available checks

See the individual modules for full descriptions and examples. The recommended way to enable them is Rbtz.CredoChecks.all/0 — see Installation and configuration.

Design

Readability

Refactor

Warning

Installation and configuration

  1. Add rbtz_credo_checks to your mix.exs dependencies:

    def deps do
    [
    {:rbtz_credo_checks, "~> 0.1", only: [:dev, :test], runtime: false}
    ]
    end
  2. Run mix deps.get.

  3. Enable the checks in your .credo.exs. The recommended way is Rbtz.CredoChecks.all/0, which returns every check as a {module, opts} tuple ready to append to your enabled: list. It stays in sync automatically as this library adds checks — there's nothing to hand-maintain:

    %{
    configs: [
    %{
    checks: %{
    enabled:
    [
    # ...your Credo built-in checks...
    ] ++ Rbtz.CredoChecks.all()
    }
    }
    ]
    }

Customising and disabling checks

Use Rbtz.CredoChecks.all_replacing/1 with a list of {module, opts} replacements. Each is matched by module name and replaces that check's options, leaving every other check untouched.

To customise a check's options, pass a keyword list:

Rbtz.CredoChecks.all_replacing([
{Rbtz.CredoChecks.Readability.SnakeCaseVariableNumbering, exclude: ["utf8", "ipv4", "ipv6"]}
])

To disable a check, pass false as its options — Credo treats {check, false} as disabled, so the check stays in the list but is turned off:

Rbtz.CredoChecks.all_replacing([
{Rbtz.CredoChecks.Design.PreferLogsterInLib, false}
])

You can combine both, and replacements naming a module that isn't one of these checks raise an ArgumentError, so typos surface immediately:

enabled:
[
# ...your Credo built-in checks...
] ++
Rbtz.CredoChecks.all_replacing([
{Rbtz.CredoChecks.Readability.SnakeCaseVariableNumbering, exclude: ["utf8", "ipv4", "ipv6"]},
{Rbtz.CredoChecks.Design.PreferLogsterInLib, false}
])

Enabling checks individually

If you'd rather not enable everything, you can skip the helpers and list the checks by hand in your enabled: list. This is the full set Rbtz.CredoChecks.all/0 returns — drop any you don't want, and add a second tuple element to customise a check (or false to disable it):

enabled:
[
# ...your Credo built-in checks...
{Rbtz.CredoChecks.Design.BareScriptInHeex, []},
{Rbtz.CredoChecks.Design.CnInClassList, []},
{Rbtz.CredoChecks.Design.CustomAliasInRouterScope, []},
{Rbtz.CredoChecks.Design.PreferLogsterInLib, []},
{Rbtz.CredoChecks.Design.RawHtmlElementsInHeex, []},
{Rbtz.CredoChecks.Design.RawSvgInHeex, []},
{Rbtz.CredoChecks.Readability.AtomHttpStatusCodes, []},
{Rbtz.CredoChecks.Readability.AwkwardPipe, []},
{Rbtz.CredoChecks.Readability.ClassAttrFormatting, []},
{Rbtz.CredoChecks.Readability.LiveViewCallbackOrder, []},
{Rbtz.CredoChecks.Readability.ModuleAttrCollectionFormatting, []},
{Rbtz.CredoChecks.Readability.PreferBlockFormForMultilineIf, []},
{Rbtz.CredoChecks.Readability.PreferBooleanDataAttrShorthand, []},
{Rbtz.CredoChecks.Readability.PreferCapture, []},
{Rbtz.CredoChecks.Readability.PreferNilEquality, []},
{Rbtz.CredoChecks.Readability.PreferSigilSForEscapedQuotes, []},
{Rbtz.CredoChecks.Readability.PreferToTimeout, []},
{Rbtz.CredoChecks.Readability.RedundantClassAttrWrapping, []},
{Rbtz.CredoChecks.Readability.ShorthandDefMustBeCompact, []},
{Rbtz.CredoChecks.Readability.SnakeCaseVariableNumbering, []},
{Rbtz.CredoChecks.Readability.TopLevelAliasImportRequire, []},
{Rbtz.CredoChecks.Refactor.PreferEctoMigrationHelper, []},
{Rbtz.CredoChecks.Refactor.PreferForAttrOverForBlock, []},
{Rbtz.CredoChecks.Refactor.PreferTextColumns, []},
{Rbtz.CredoChecks.Refactor.PreferToFormInTemplates, []},
{Rbtz.CredoChecks.Refactor.RawHtmlMatchInLiveViewTests, []},
{Rbtz.CredoChecks.Refactor.RedundantThen, []},
{Rbtz.CredoChecks.Warning.AssertNonEmptyBeforeIterate, []},
{Rbtz.CredoChecks.Warning.BooleanDataAttrCoalescesNil, []},
{Rbtz.CredoChecks.Warning.DisableMigrationLock, []},
{Rbtz.CredoChecks.Warning.EnumEachInHeex, []},
{Rbtz.CredoChecks.Warning.LiveViewFormCanBeRehydrated, []},
{Rbtz.CredoChecks.Warning.PhxClickAwayWithoutId, []},
{Rbtz.CredoChecks.Warning.PhxHookComponentWithoutStableId, []},
{Rbtz.CredoChecks.Warning.PhxHookWithoutId, []},
{Rbtz.CredoChecks.Warning.PhxUpdateStreamWithoutId, []},
{Rbtz.CredoChecks.Warning.PreferGetFieldOnChangeset, []},
{Rbtz.CredoChecks.Warning.PushEventSocketBinding, []},
{Rbtz.CredoChecks.Warning.ReqTestWithoutVerifyOnExit, []},
{Rbtz.CredoChecks.Warning.SetMimicGlobal, []},
{Rbtz.CredoChecks.Warning.SortKeywordValidateResult, []},
{Rbtz.CredoChecks.Warning.StringInterpolationInClassAttr, []},
{Rbtz.CredoChecks.Warning.UnnamedOtpProcess, []}
]

License

MIT. See LICENSE.