/** * Every rule, by name, with the finding it reports. The order is the * order they run in within a pass; it only matters when two rules want * the same bytes, and then the one listed first wins the pass and the * other gets the next. */ import { NamedRule } from './rule.zena'; import { functionDeclarations } from './rules/function-declaration.zena'; import { unnecessaryCasts } from './rules/unnecessary-cast.zena'; import { unnecessaryOptionalChains } from './rules/unnecessary-optional-chain.zena'; import { unnecessaryAnnotations } from './rules/unnecessary-annotation.zena'; import { collectionLiterals } from './rules/collection-literal.zena'; import { ifInitializers } from './rules/if-initializer.zena'; import { nullishOperators } from './rules/nullish.zena'; import { matchToIf } from './rules/match-to-if.zena'; import { elseIfs } from './rules/else-if.zena'; import { preferLet } from './rules/prefer-let.zena'; import { immutableFields } from './rules/immutable-field.zena'; import { emptyConstructors } from './rules/empty-constructor.zena'; import { templateLiterals } from './rules/template-literal.zena'; import { consoleToString } from './rules/console-to-string.zena'; import { booleanReturns } from './rules/boolean-return.zena'; import { forInLoops } from './rules/for-in.zena'; import { arrowBodies } from './rules/arrow-body.zena'; import { growable } from 'zena:core'; export function allRules(): GrowableArray { return growable([ new NamedRule('function-declaration', functionDeclarations, 'A top-level arrow function; write a `function` declaration.'), new NamedRule('unnecessary-cast', unnecessaryCasts, 'The expression already has this type; the cast can go.'), new NamedRule('unnecessary-optional-chain', unnecessaryOptionalChains, 'The target is not nullable; the `?` can go.'), new NamedRule('unnecessary-annotation', unnecessaryAnnotations, 'The checker infers this type; the annotation can go.'), new NamedRule('collection-literal', collectionLiterals, 'A collection built by insertions; write a literal.'), new NamedRule('if-initializer', ifInitializers, 'A variable assigned by an `if`; initialize it with an `if` expression.'), new NamedRule('nullish', nullishOperators, 'A null test spelling out `??` or `?.`; use the operator.'), new NamedRule('match-to-if', matchToIf, 'A `match` with one or two arms; write an `if`.'), new NamedRule('else-if', elseIfs, 'An `else` holding only an `if`; write `else if`.'), new NamedRule('for-in', forInLoops, 'An index loop that only reads the element; write `for…in`.'), new NamedRule('boolean-return', booleanReturns, 'Boolean literals chosen by a condition; use the condition.'), new NamedRule('template-literal', templateLiterals, 'Three or more strings joined with `+`; write a template literal.'), new NamedRule('console-to-string', consoleToString, 'A string conversion in a `console` call; pass the value.'), new NamedRule('arrow-body', arrowBodies, 'An arrow whose block only returns; make the expression the body.'), new NamedRule('prefer-let', preferLet, 'A `var` never assigned again; declare it with `let`.'), new NamedRule('immutable-field', immutableFields, 'A `var` field nothing assigns; drop the `var`.'), new NamedRule('empty-constructor', emptyConstructors, 'An empty default constructor; the compiler synthesizes one.'), ]); } /** The rule named `name`, or null. */ export function ruleNamed(name: String): NamedRule | null { for (let rule in allRules()) { if (rule.name == name) { return rule; } } return null; }