@daml-tools/lint-plugin 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# @daml-tools/lint-plugin
|
|
2
2
|
|
|
3
|
-
TypeScript types and starter templates for external `daml-lint
|
|
4
|
-
|
|
3
|
+
TypeScript types and starter templates for external `daml-lint` custom rule
|
|
4
|
+
plugin authors.
|
|
5
5
|
|
|
6
6
|
Install it with TypeScript and esbuild in your rule project:
|
|
7
7
|
|
|
@@ -14,7 +14,24 @@ Author rules in TypeScript, keep top-level `const NAME`, `const SEVERITY`, an
|
|
|
14
14
|
optional `const DESCRIPTION`, and top-level visitor `function` declarations,
|
|
15
15
|
then assign the same values to `globalThis.__daml_lint_rule` so TypeScript can
|
|
16
16
|
validate the rule object. Bundle the rule to one JavaScript file before passing
|
|
17
|
-
it to `daml-lint --rules
|
|
17
|
+
it to `daml-lint --rules` or exposing it from a plugin package.
|
|
18
|
+
|
|
19
|
+
Installed plugin packages expose bundled rules from `package.json`:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"name": "daml-lint-plugin-template",
|
|
24
|
+
"damlLint": {
|
|
25
|
+
"rules": {
|
|
26
|
+
"template-requires-ensure": "dist/template-requires-ensure.js"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Consumers enable installed rules from `.daml-lint.json` with `plugin/rule`
|
|
33
|
+
IDs. Rule options from `[severity, options]` settings are available as global
|
|
34
|
+
`CONFIG`.
|
|
18
35
|
|
|
19
36
|
Runtime helper functions are intentionally not exported. The package is the
|
|
20
37
|
public rule-facing IR contract and starter templates for plugin projects.
|
package/dist/index.d.ts
CHANGED
|
@@ -282,6 +282,9 @@ export type DamlLintRuleModule = {
|
|
|
282
282
|
export type DamlLintReportTarget = { span: Span } | { span: SrcPos } | number;
|
|
283
283
|
|
|
284
284
|
declare global {
|
|
285
|
+
/** Per-rule options from `.daml-lint.json`. Defaults to `{}`. */
|
|
286
|
+
var CONFIG: unknown;
|
|
287
|
+
|
|
285
288
|
var __daml_lint_rule: DamlLintRuleModule | undefined;
|
|
286
289
|
|
|
287
290
|
/** Report a finding at a node's span, or at an explicit 1-based line number.
|
package/package.json
CHANGED
|
@@ -1,20 +1,31 @@
|
|
|
1
1
|
# daml-lint plugin starter
|
|
2
2
|
|
|
3
|
-
This project shows the minimal TypeScript flow for a `daml-lint
|
|
4
|
-
|
|
3
|
+
This project shows the minimal TypeScript flow for a `daml-lint` custom rule
|
|
4
|
+
plugin loaded through `.daml-lint.json`.
|
|
5
5
|
|
|
6
6
|
```sh
|
|
7
7
|
npm install
|
|
8
8
|
npm run check
|
|
9
9
|
npm run build
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
npm run lint:missing
|
|
11
|
+
npm run lint:clean
|
|
12
12
|
```
|
|
13
13
|
|
|
14
14
|
The first scan reports one `template-requires-ensure` finding. The second scan
|
|
15
15
|
has no finding from the custom rule.
|
|
16
16
|
|
|
17
|
+
The package manifest exposes bundled rule files under `damlLint.rules`.
|
|
18
|
+
`.daml-lint.json` uses `pluginPaths: ["."]` so the project can resolve itself
|
|
19
|
+
before it is published. After publishing, consumers install the package and
|
|
20
|
+
enable rules by `plugin/rule` ID.
|
|
21
|
+
|
|
17
22
|
The runtime still discovers top-level metadata constants and visitor
|
|
18
23
|
`function` declarations. The `globalThis.__daml_lint_rule` assignment gives
|
|
19
24
|
TypeScript a single rule object to validate, but it is not the only runtime
|
|
20
25
|
discovery mechanism.
|
|
26
|
+
|
|
27
|
+
For a one-off script test, the bundled JavaScript can still be passed directly:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
daml-lint fixtures/missing-ensure.daml --rules dist/template-requires-ensure.js --fail-on info
|
|
31
|
+
```
|
|
@@ -6,11 +6,16 @@
|
|
|
6
6
|
"scripts": {
|
|
7
7
|
"check": "tsc --noEmit",
|
|
8
8
|
"build": "esbuild src/template-requires-ensure.ts --bundle --format=esm --target=es2020 --outfile=dist/template-requires-ensure.js",
|
|
9
|
-
"lint:missing": "daml-lint fixtures/missing-ensure.daml --
|
|
10
|
-
"lint:clean": "daml-lint fixtures/with-ensure.daml --
|
|
9
|
+
"lint:missing": "daml-lint fixtures/missing-ensure.daml --fail-on info",
|
|
10
|
+
"lint:clean": "daml-lint fixtures/with-ensure.daml --fail-on info"
|
|
11
|
+
},
|
|
12
|
+
"damlLint": {
|
|
13
|
+
"rules": {
|
|
14
|
+
"template-requires-ensure": "dist/template-requires-ensure.js"
|
|
15
|
+
}
|
|
11
16
|
},
|
|
12
17
|
"devDependencies": {
|
|
13
|
-
"@daml-tools/lint-plugin": "^0.3.
|
|
18
|
+
"@daml-tools/lint-plugin": "^0.3.4",
|
|
14
19
|
"esbuild": "^0.28.1",
|
|
15
20
|
"typescript": "^6.0.3"
|
|
16
21
|
}
|