Whine.Types
- Package
- purescript-whine-core
- Repository
- collegevine/purescript-whine
#Handle Source
newtype Handle :: (Type -> Type) -> Type
newtype Handle astNode
This function is the core functionality of a linting rule: it takes an AST node and reports anything wrong with it as effects in the monad.
The type variable e
is a peculiarity of how the language-cst-parser
library is structured: the whole AST is parametrized by this type, which
represents possible errors with parsing. When the tree is fully parsed
successfully, e
is set to Void
. Otherwise it's some error type.
Because for the purposes of this library we don't actually care whether the
parsing was successful, the handler function is polymorphic in e
. But we
have to have a RangeOf
instance for it, because it's a prerequisite for
other RangeOf
instances for AST nodes, and we do need those, because we
need to report a source location for every violation.
Constructors
Handle (forall e m. MonadRules () m => RangeOf e => astNode e -> m Unit)
#Rule Source
type Rule = { onBinder :: Handle Binder, onDecl :: Handle Declaration, onExpr :: Handle Expr, onModule :: Handle Module, onModuleExport :: Handle Export, onModuleImport :: Handle ImportDecl, onType :: Handle Type }
A linting rule is just a collection of Handle
functions for different
types of AST nodes. See comments on Handle
for explanation of how it
works.
When constructing a rule, use the emptyRule
value as base, so you don't
have to provide every field.
#Violation Source
type Violation :: Row Type -> Type
type Violation r = { message :: String, source :: Maybe SourceRange | r }
Violation
is an open record. When generated by a rule implementation, it
starts out with just source
and message
, but at higher stack levels
gets annotated with ID of the rule that created the violation (see
WithRule
), with the file whence the violation came (see WithFile
), and
with a flag showing if this particular violation was muted (see
WithMuted
).
#Violations Source
type Violations :: Row Type -> Type
type Violations r = Array (Violation r)
#RuleFactories Source
type RuleFactories = Array (RuleId /\ RuleFactory)
See comments on ruleFactory
#MonadRules Source
class MonadRules :: Row Type -> (Type -> Type) -> Constraint
class (Monad m, MonadLog m) <= MonadRules v m | m -> v where
The monad in which each individual rule is run.
Members
reportViolation :: Violation v -> m Unit
#ruleFactory Source
ruleFactory :: forall args. RuleId -> Codec args -> (args -> Rule) -> RuleId /\ RuleFactory
This function is intended to pair rules with their IDs. Every rule would
take its own args
and provide a JSON codec to decode the args, and the
list of possible rules and their IDs would be constructed like this:
factories :: ∀ m. RuleFactories m
factories =
[ ruleFactory "RuleOne" ruleOneArgsCodec ruleOne
, ruleFactory "RuleTwo" ruleTwoArgsCodec ruleTwo
]
ruleOne :: { arg :: Int, anotherArg :: String } -> Rule m
ruleTwo :: {} -> Rule m
ruleFactory
takes care of parsing the arguments and reporting any errors,
so that the actual rule implementation only has to deal with strongly typed
arguments.
- Modules
- Vscode.
Client - Vscode.
Client. Configuration - Vscode.
Client. Executable - Vscode.
Client. FileSystemWatcher - Vscode.
Client. Workspace - Vscode.
Context - Vscode.
Events - Vscode.
Server. Capabilities - Vscode.
Server. Connection - Vscode.
Server. Diagnostic - Vscode.
Server. TextDocuments - Whine
- Whine.
Core. CaseBranchIndentation - Whine.
Core. CommaFirstArrays - Whine.
Core. UndesirableModules - Whine.
Core. WhineRules - Whine.
Log - Whine.
Muting - Whine.
Prelude - Whine.
Print - Whine.
Runner - Whine.
Runner. Cli - Whine.
Runner. Config - Whine.
Runner. FS - Whine.
Runner. Glob - Whine.
Runner. LanguageServer - Whine.
Runner. PackageVersion - Whine.
Runner. Prelude - Whine.
Runner. Yaml - Whine.
Types - WhineM