~/bend-docscommunity

src/rules/style/negate.bend checks

raw source on the hub · import bolt@1.63.0.0/src/rules/style/negate.bend as Negate

rule negate: a U32 or Nat comparison negated, where the opposite comparison has a word of its own. Among the significant tokens (spaces, newlines and comments dropped): a dotted Bool.not, (, a dotted comparison (U32.is_eq, is_ne, is_lt, is_le, is_gt or is_ge, or the same six of Nat), (, any tokens up to the ) that closes that bracket, and ) right after it. One finding, on the Bool.not token.

Base has all six comparisons for both types, and each one negated is another of the six with the same Bool for every pair of arguments: Bool.not(U32.is_eq(a, b)) is U32.is_ne(a, b), and Bool.not(Nat.is_lt(a, b)) is Nat.is_ge(a, b). The plainer word says the test in one step, with one bracket fewer to match.

Left alone: a Bool.not whose argument goes on past the comparison (Bool.not(U32.is_eq(a, b) && c): the ) that follows the comparison is not right after it); F32, where the negation of is_lt is not is_ge when either side is NaN; Char and Cmp, which have no is_ne to suggest; a qualified or aliased name; and the shape written inside a string or a comment. A LAWS.bend or a PROOF.bend is exempt, and so is a law and a def that is a proof (def f(x):, or one that returns -> {..}) in any file, from its keyword to the next def, type or import (src/rules/suspicious/empty.bend's reading of one): a law states the test as it means it.

9 imports
import Base
import ../../src.bend as Src
import ../../paths.bend as Paths
import ../../role.bend as Role
import ../../lazy/lazy.bend as Lazy
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../tokens.bend as T
import ../suspicious/empty.bend as Empty

Definitions

def opposite source · line 36 · raw

@+op:String -> String

the opposite of one of the six comparisons, by its name after the type; "" for any other name

def under source · line 45 · raw

@ty:String -> @op:String -> String

the comparison of a type that the opposite of op names; "" when op is none of the six

def word source · line 51 · raw

@+t:String -> String

the word for a comparison negated: the opposite comparison of the same type, for U32 and for Nat; "" for any other name

def shut source · line 59 · raw

@toks:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.Tok> -> @+d:Nat -> @done:Bool -> Maybe<&2, List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.Tok>>

the tokens after the bracket that closes a group, read from right inside it: d counts the brackets opened on the way and not yet closed, and done says the last token read was the closing one. None when the tokens run out first

def ends.at source · line 69 · raw

@toks:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.Tok> -> Bool

do the tokens open with )?

def ends source · line 77 · raw

@m:Maybe<&2, List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.Tok>> -> Bool

does a ) follow right after the bracket that closes the comparison?

def at.go source · line 86 · raw

@ok:Bool -> @w:String -> String

the comparison negated, when the brackets are where they belong; "" when not

def at source · line 96 · raw

@toks:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.Tok> -> String

the tokens after a Bool.not: (, a dotted name, (, its arguments, ) and )? Then the name's opposite, "" when it has none or the shape is another

def named source · line 105 · raw

@k:0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.TokKind -> @t:String -> Bool

a dotted Bool.not?

def found.go source · line 113 · raw

@name:Bool -> @rest:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.Tok> -> String

the word for the test a token opens, if it is Bool.not

def found source · line 121 · raw

@skip:Bool -> @k:0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.TokKind -> @t:String -> @rest:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.Tok> -> String

the word for a token's test, outside a law and a def that is a proof

def say source · line 129 · raw

@+w:String -> String

what a finding says: the word for the negated test

def cite source · line 133 · raw

@w:String -> @path:String -> @l:U32 -> @c:U32 -> 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding

the finding on a Bool.not, over its eight chars

def hit.go source · line 137 · raw

@none:Bool -> @w:String -> @path:String -> @l:U32 -> @c:U32 -> @more:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding> -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>

a finding when there is a word, before the rest

def hit source · line 145 · raw

@+w:String -> @path:String -> @l:U32 -> @c:U32 -> @more:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding> -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>

the finding a test makes, if any, before the rest

def walk source · line 150 · raw

@toks:List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/syntax/lex.Tok> -> @+path:String -> @skip:Bool -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>

every negated comparison among the tokens, in order; skip says whether the tokens so far sit in a law or a def that is a proof

def check source · line 159 · raw

@s:0xa8d4b6b02772814375b557e7f0e8d309/src/src.Src -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>

the rule

def check.role source · line 165 · raw

@r:0xa8d4b6b02772814375b557e7f0e8d309/src/role.Role -> @s:0xa8d4b6b02772814375b557e7f0e8d309/src/src.Src -> List<&2, 0xa8d4b6b02772814375b557e7f0e8d309/src/finding.Finding>

the rule, told the file's role (src/role.bend): a law or proof file is skipped