layout/case.bend checks
raw source on the hub · import bend-lint-rules@0.1.1.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() |
| 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.1.1.0/linter/lint.bend as Lint import bend-lint-api@0.1.1.0/shared/lists.bend as Lists import bend-lint-api@0.1.1.0/shared/strings.bend as Strings
Types
type Case source · line 27 · raw
Data
Types =====
PascalCase
SnakeCase
EitherCase
Definitions
def has_no_underscore source · line 34 · raw
@s:String -> Bool
Case ====
def has_no_capital source · line 43 · raw
@s:String -> @ok:Bool -> Bool
def is_pascal.rest source · line 52 · raw
@upper:Bool -> @rest:String -> Bool
def is_pascal source · line 59 · raw
@s:String -> Bool
def is_snake.of source · line 66 · raw
@empty:Bool -> @s:String -> Bool
def is_snake source · line 73 · raw
@+s:String -> Bool
def fits source · line 76 · raw
@want:Case -> @+s:String -> Bool
def has_small_head source · line 85 · raw
@s:String -> Bool
def has_capital_head source · line 92 · raw
@s:String -> Bool
def snake_cap source · line 99 · raw
@cut:Bool -> @c:Char -> @acc:String -> String
def snake source · line 109 · 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 128 · raw
@s:String -> @up:Bool -> @acc:String -> String
s in PascalCase: _ goes, and the character after it becomes a capital.
def recased source · line 139 · raw
@want:Case -> @+s:String -> String
def ends source · line 150 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.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 164 · raw
@+nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> Case
The case of a name whose written type is the last of nodes: none written, either.
def returns source · line 172 · raw
@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> Case
The case of a def's name, by its written return type, among its nodes.
def wanted source · line 185 · raw
@+node:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node -> @namespace:String -> Maybe<&2, Case>
The case a declaration's name takes, if the file chooses it.
def noun source · line 205 · raw
@syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> @sort:Bool -> String
A name of syntax, in a message. sort: whether it is a type.
def what source · line 230 · raw
@syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> @want:Case -> String
def is_local.of source · line 240 · 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 247 · raw
@syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> Bool
def renames source · line 251 · raw
@ok:Bool -> @at:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span -> @full:String -> @to:String -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Fix>
The fix that renames a local name to to, if recasing made one that fits.
def misfit source · line 260 · raw
@+syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> @+want:Case -> @+name:String -> @+span:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.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 279 · raw
@fit:Bool -> @syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> @want:Case -> @name:String -> @span:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>
def judged source · line 292 · raw
@want:Maybe<&2, Case> -> @syntax:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Syntax -> @+name:String -> @span:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>
def judge source · line 304 · raw
@+namespace:String -> @declarations:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Declaration> -> @out:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>
def run source · line 331 · raw
@+here:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Here -> 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Ask(List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>)
def rule source · line 334 · raw
0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Rule