@fluid-project/fluid-lint
v1.0.0
Published
Linting of Infusion 6 JavaScript and Single File Components - a lezer grammar of the runes of configuration, nested within JavaScript and SFCs, and a linter of layer records, for CodeMirror 6 and node
Keywords
Readme
@fluid-project/fluid-lint
Linting of Infusion 6 JavaScript and Single File Components, for CodeMirror 6 and for node.
What it reads
- JavaScript is parsed by
@lezer/javascript. Within it, the grammar of configuration's runes,grammar/fluid-runes.grammar, is nested over the interior of each String and template literal which configures a layer: those within the record written tofluid.def, passing through objects and arrays but never into code, e.g. the body of a function written as afunc. A String held attemplateorpartialTemplateis read as a template, unless it is a reference or a compact record. - SFCs are parsed by
@lezer/htmlin its self-closing dialect. The JavaScript of each top-level<script>is read as above, and the interpolations of its<template>. - The grammar of runes has three top rules:
Value- a configuration String, read as Infusion reads it, by its first character: a reference{context selector}.path:label, a compact record$type:fn(args), a backslash-escaped literal, or a plain literal.Template- text holding interpolations@{...}, in which@@{is literal.CallBody- a call without its rune, e.g. theforwardof a$lens.
What it checks
- Syntax. JavaScript and HTML syntax, and the syntax of every rune, down to its interior. Examples: an unclosed
reference or call, a malformed interpolation, a
$beginning a literal, which should be written\\$. - Compact records. The directive of each compact record, which must be
$compute,$effector$method.$effectmust list its arguments. A quoted argument draws a warning, since compact arguments are not unquoted. - Directives of layer records.
$layers,$varietyand$importMapbelong to a record.$forand$ifbelong to the record of a$component.- A member's directives (
$compute,$effect,$method,$lens,$bindable,$linkage,$component,$reactiveRoot,$transient) stand alone as the single key of the member's record.
- Full forms. Their keys and required members, e.g. a function record's
func, a$lens'ssource, or a$for'ssource. A$component's record is linted in turn as a layer record. - Recovery. A missing comma between the members of an object or the elements of an array is reported, and repaired in place for the rest of the linting, so that one slip doesn't hide the errors after it. A mismatched or unclosed bracket is reported with the line of the bracket left open. Errors within a rune are described by what is missing, e.g. an unclosed reference or call, an empty argument, or text after a whole rune.
- Fragments. A fragment of a record, e.g.
view: {$component: {...}}, as documentation shows, is linted as if within a record.isFragmenttells whether a text is one.
Use
- In node:
lint(text, kind)insrc/fluidLint.jsreturns diagnostics{from, to, severity, message}.kindis"js"or"vue", and by default is guessed from the text. - Through ESLint:
eslint-plugin-fluid-lintreports its diagnostics as ESLint rules. Infusion's ownnpm run lintapplies it. - A summary of ESLint's run:
eslint-summary-formatter.cjsis a formatter for ESLint 8 or later, an optional peer dependency. It prints ESLint's own "stylish" report, followed by a count of the files free of errors and warnings, e.g.138/138 files lint free. Use it aseslint --format ./node_modules/fluid-lint/eslint-summary-formatter.cjs .... Infusion'snpm run lintuses it. - For CodeMirror 6:
src/codemirror.jsprovides the languages (fluidJavaScript,fluidSfc), the linter (fluidLinter), andfluidEditor, which makes an editor of either. - The bundle:
npm run buildregenerates the parser from the grammar, and bundlessrc/codemirror.jswith CodeMirror as the browser globalfluid.codemirror6, into Infusion'ssrc/lib/fluid-lint/fluid-lint.js.fluid.liveExampleloads that bundle; it is the live example of Infusion's documentation. - Tests:
npm testrunstest/lintTests.js. The live example's own tests are intests/framework-tests/components/html/LiveExampleTests.html.
The package is ESM, as the parser lezer-generator writes is. @codemirror/view and @codemirror/state are pinned to
the versions @codemirror/lint requires, since a second copy of either within the bundle silently disables the linter.
