layout/case.bend checks
raw source on the hub · import bend-lint-rules@0.3.2.0/layout/case.bend as Case
layout/case: a name whose case does not follow the kind of what it names. Fix: renames the declaration, with its uses. Heuristics: the kind comes from the syntax and the written types, not from the checker:
| Kind | Case | Examples |
| ------------------------------------------------- | ----------------- | ---------------------------- |
| type, constructor, import alias | PascalCase | Maybe, Some{}, M |
| def whose written return type ends in a sort | PascalCase | IO, Pair, Set() |
| law whose statement ends in a sort | PascalCase | law Game: Data |
| parameter or field whose written type ends in one | PascalCase | -A: Type, F: U32 -> Type |
| law, other def, parameter or field | snake_case | add_comm, from_list, n |
| variable, lambda, forall, def without a return | either | Big, small |
| namespace segment | its parent's case | IO.print, Set.from_list |
A sort is Type, Data or Kind(..); a type ends in one when it is one, or a function type whose
result does. A binder written bare (<a>, (x)) is a quantity, so snake_case. PascalCase is a
capital, then letters and digits: IO, OP and U32 pass. snake_case has no capital. A dotted
name is checked by its last segment; the segments before it name its parent, checked where the parent
is declared. import Base, and a def that fills a law of another file, are skipped: their names are
not this file's to choose.
4 imports
import Base import bend-lint-api@0.3.2.0/linter/api/impl.bend as LintImpl import bend-lint-api@0.3.2.0/linter/api/spec.bend as Lint import bend-lint-api@0.3.2.0/shared.bend as Shared
Types
type Case source · line 28 · raw
Data
Types =====
PascalCase
SnakeCase
EitherCase
Definitions
def has_no_underscore source · line 35 · raw
@s:String -> Bool
Case ====
def has_no_capital source · line 44 · raw
@s:String -> @ok:Bool -> Bool
def is_pascal.rest source · line 53 · raw
@upper:Bool -> @rest:String -> Bool
def is_pascal source · line 60 · raw
@s:String -> Bool
def is_snake.of source · line 67 · raw
@empty:Bool -> @s:String -> Bool
def is_snake source · line 74 · raw
@+s:String -> Bool
def fits source · line 77 · raw
@want:Case -> @+s:String -> Bool
def has_small_head source · line 86 · raw
@s:String -> Bool
def has_capital_head source · line 93 · raw
@s:String -> Bool
def snake_cap source · line 100 · raw
@cut:Bool -> @c:Char -> @acc:String -> String
def snake source · line 110 · raw
@s:String -> @capital:Bool -> @+prev:U32 -> @acc:String -> String
s in snake_case: a word starts at a capital after a small letter or digit, or at the last capital of a run before a
small letter. capital: whether s starts with a capital. prev: the character before is none or _ (0), a small
letter or digit (1), or a capital (2). acc: the result so far, last character first.
def pascal source · line 129 · raw
@s:String -> @up:Bool -> @acc:String -> String
s in PascalCase: _ goes, and the character after it becomes a capital.
def recased source · line 140 · raw
@want:Case -> @+s:String -> String
def ends source · line 151 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> Bool
Whether the type the last of nodes writes ends in a sort: it is one, or a function type whose result does.
def typed source · line 165 · raw
@+nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> Case
The case of a name whose written type is the last of nodes: none written, either.
def returns source · line 173 · raw
@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> Case
The case of a def's name, by its written return type, among its nodes.
def wanted source · line 186 · raw
@+node:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node -> @namespace:String -> Maybe<&2, Case>
The case a declaration's name takes, if the file chooses it.
def noun source · line 206 · raw
@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> @sort:Bool -> String
A name of syntax, in a message. sort: whether it is a type.
def what source · line 233 · raw
@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> @want:Case -> String
def is_local.of source · line 243 · raw
@declares:Maybe<&2, Bool> -> Bool
Whether a name is a binder's: only its own declaration names it, so a rename touches no other file.
def is_local source · line 250 · raw
@syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> Bool
def renames source · line 254 · raw
@ok:Bool -> @at:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> @full:String -> @to:String -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Fix>
The fix that renames a local name to to, if recasing made one that fits.
def misfit source · line 263 · raw
@+syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> @+want:Case -> @+name:String -> @+span:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
The finding for a name that does not fit: it says the new name when recasing makes one that fits, and, for a local name, offers the rename.
def verdict source · line 282 · raw
@fit:Bool -> @syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> @want:Case -> @name:String -> @span:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def judged source · line 295 · raw
@want:Maybe<&2, Case> -> @syntax:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Syntax -> @+name:String -> @span:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def judge source · line 307 · raw
@+namespace:String -> @declarations:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Declaration> -> @out:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>
def run source · line 334 · raw
@+here:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Here -> 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Ask(List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>)
def rule source · line 337 · raw
0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule