rumdl-wasm 0.2.56 → 0.2.58

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
@@ -80,6 +80,73 @@ const rules = JSON.parse(get_available_rules());
80
80
  // [{ name: "MD001", description: "Heading levels should only increment by one level at a time" }, ...]
81
81
  ```
82
82
 
83
+ ## Configuration
84
+
85
+ `lint_markdown` and `apply_all_fixes` use rumdl's defaults. For configured
86
+ linting, create a `Linter` with an options object that mirrors the `[global]`
87
+ section of `.rumdl.toml` plus per-rule tables:
88
+
89
+ ```javascript
90
+ import init, { Linter } from 'rumdl-wasm';
91
+
92
+ await init();
93
+
94
+ const linter = new Linter({
95
+ disable: ['MD041'],
96
+ 'line-length': 120,
97
+ flavor: 'mkdocs', // "standard" (default), "mkdocs", "obsidian", ...
98
+ MD013: { 'line-length': 100 },
99
+ });
100
+
101
+ const warnings = JSON.parse(linter.check(content, 'docs/guide.md')); // path is optional
102
+ const fixed = linter.fix(content, 'docs/guide.md');
103
+
104
+ JSON.parse(linter.get_config()); // the effective configuration
105
+ JSON.parse(linter.get_config_warnings()); // e.g. unknown rule options
106
+ ```
107
+
108
+ Passing a path lets `exclude` and `per-file-ignores` patterns apply.
109
+
110
+ ### Loading `.rumdl.toml` files, including `extends`
111
+
112
+ A flat options object cannot follow `extends`, so `new Linter(...)` reports an
113
+ `extends` key as a config warning and ignores it. To load config files the way
114
+ the CLI does (same parsing, `extends` resolution, and merge order), hand rumdl
115
+ the file contents and let it tell you which file it needs next. This works
116
+ from any host that can read files, including ones that can only do so
117
+ asynchronously:
118
+
119
+ ```javascript
120
+ import init, { Linter, resolve_config_chain } from 'rumdl-wasm';
121
+ import { readFile } from 'fs/promises';
122
+
123
+ await init();
124
+
125
+ const root = '.rumdl.toml';
126
+ const files = { [root]: await readFile(root, 'utf-8') };
127
+ const request = () => ({ root, files, env: process.env, home: process.env.HOME });
128
+
129
+ for (;;) {
130
+ const r = JSON.parse(resolve_config_chain(request()));
131
+ if (r.status === 'need-file') {
132
+ // r.path is resolved already: relative to the declaring file's directory,
133
+ // with `$VAR` expanded from `env` and `~/` from `home`. Store null for a
134
+ // file that does not exist.
135
+ files[r.path] = await readFile(r.path, 'utf-8').catch(() => null);
136
+ } else if (r.status === 'error') {
137
+ throw new Error(r.message); // parse error, missing target, cycle, ...
138
+ } else {
139
+ console.log('config chain:', r.files); // root first
140
+ break;
141
+ }
142
+ }
143
+
144
+ const linter = Linter.from_config_files({ ...request(), 'default-flavor': 'mkdocs' });
145
+ ```
146
+
147
+ `root` may also be a `pyproject.toml` (its `[tool.rumdl]` table is used).
148
+ `default-flavor` applies only when no file in the chain sets a flavor.
149
+
83
150
  ## Warning Format
84
151
 
85
152
  Each warning object contains:
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Ruben J. Jongejan <ruben.jongejan@gmail.com>"
6
6
  ],
7
7
  "description": "Fast markdown linter with 60+ rules - WebAssembly build",
8
- "version": "0.2.56",
8
+ "version": "0.2.58",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/rumdl_lib.d.ts CHANGED
@@ -41,6 +41,21 @@ export class Linter {
41
41
  * Uses the same fix coordinator as the CLI for consistent behavior.
42
42
  */
43
43
  fix(content: string, path?: string | null): string;
44
+ /**
45
+ * Create a Linter from config file contents, following `extends`.
46
+ *
47
+ * Takes the same request object as [`resolve_config_chain`], which must
48
+ * already report the chain complete: every file the chain reaches has to
49
+ * be in `files`. The files are parsed, merged and validated exactly as the
50
+ * rumdl CLI does it (`[global]` section, rule sections and aliases,
51
+ * `extends` precedence, per-rule `enabled`), so a `.rumdl.toml` means the
52
+ * same thing in an embedding as on the command line. Validation warnings
53
+ * are available from `get_config_warnings()`.
54
+ *
55
+ * Fails with a message when a file is missing from `files` or the chain
56
+ * has a config error; `resolve_config_chain` reports both beforehand.
57
+ */
58
+ static from_config_files(request: any): Linter;
44
59
  /**
45
60
  * Get the current configuration as JSON
46
61
  *
@@ -94,6 +109,34 @@ export function get_version(): string;
94
109
  */
95
110
  export function init(): void;
96
111
 
112
+ /**
113
+ * Find out which config files a chain needs before building a `Linter` from it.
114
+ *
115
+ * Embedders that can only read files asynchronously call this in a loop: start
116
+ * with the root file's contents, add whatever path the result asks for, and
117
+ * repeat until the chain is complete. Returns a JSON object with `status`:
118
+ *
119
+ * - `{"status": "need-file", "path": "base/.rumdl.toml"}`: read this path
120
+ * (relative paths are relative to wherever `root` is relative to), add it to
121
+ * `files` (or `null` if it does not exist), and call again.
122
+ * - `{"status": "complete", "files": [".rumdl.toml", "base/.rumdl.toml"]}`:
123
+ * every file is present; `files` lists the chain root first.
124
+ * - `{"status": "error", "message": "..."}`: the chain cannot be loaded
125
+ * (parse error, missing `extends` target, cycle, undefined `$VAR`, ...).
126
+ *
127
+ * ```javascript
128
+ * const files = { [root]: await read(root) };
129
+ * for (;;) {
130
+ * const r = JSON.parse(resolve_config_chain({ root, files }));
131
+ * if (r.status === "need-file") { files[r.path] = await readOrNull(r.path); continue; }
132
+ * if (r.status === "error") throw new Error(r.message);
133
+ * break;
134
+ * }
135
+ * const linter = Linter.from_config_files({ root, files });
136
+ * ```
137
+ */
138
+ export function resolve_config_chain(request: any): string;
139
+
97
140
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
98
141
 
99
142
  export interface InitOutput {
@@ -103,9 +146,11 @@ export interface InitOutput {
103
146
  readonly get_version: (a: number) => void;
104
147
  readonly linter_check: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
105
148
  readonly linter_fix: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
149
+ readonly linter_from_config_files: (a: number, b: number) => void;
106
150
  readonly linter_get_config: (a: number, b: number) => void;
107
151
  readonly linter_get_config_warnings: (a: number, b: number) => void;
108
152
  readonly linter_new: (a: number, b: number) => void;
153
+ readonly resolve_config_chain: (a: number, b: number) => void;
109
154
  readonly init: () => void;
110
155
  readonly __wbindgen_export: (a: number, b: number) => number;
111
156
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
package/rumdl_lib.js CHANGED
@@ -7,6 +7,13 @@
7
7
  * `check()` to lint content and `fix()` to auto-fix issues.
8
8
  */
9
9
  export class Linter {
10
+ static __wrap(ptr) {
11
+ ptr = ptr >>> 0;
12
+ const obj = Object.create(Linter.prototype);
13
+ obj.__wbg_ptr = ptr;
14
+ LinterFinalization.register(obj, obj.__wbg_ptr, obj);
15
+ return obj;
16
+ }
10
17
  __destroy_into_raw() {
11
18
  const ptr = this.__wbg_ptr;
12
19
  this.__wbg_ptr = 0;
@@ -92,6 +99,37 @@ export class Linter {
92
99
  wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
93
100
  }
94
101
  }
102
+ /**
103
+ * Create a Linter from config file contents, following `extends`.
104
+ *
105
+ * Takes the same request object as [`resolve_config_chain`], which must
106
+ * already report the chain complete: every file the chain reaches has to
107
+ * be in `files`. The files are parsed, merged and validated exactly as the
108
+ * rumdl CLI does it (`[global]` section, rule sections and aliases,
109
+ * `extends` precedence, per-rule `enabled`), so a `.rumdl.toml` means the
110
+ * same thing in an embedding as on the command line. Validation warnings
111
+ * are available from `get_config_warnings()`.
112
+ *
113
+ * Fails with a message when a file is missing from `files` or the chain
114
+ * has a config error; `resolve_config_chain` reports both beforehand.
115
+ * @param {any} request
116
+ * @returns {Linter}
117
+ */
118
+ static from_config_files(request) {
119
+ try {
120
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
121
+ wasm.linter_from_config_files(retptr, addHeapObject(request));
122
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
123
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
124
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
125
+ if (r2) {
126
+ throw takeObject(r1);
127
+ }
128
+ return Linter.__wrap(r0);
129
+ } finally {
130
+ wasm.__wbindgen_add_to_stack_pointer(16);
131
+ }
132
+ }
95
133
  /**
96
134
  * Get the current configuration as JSON
97
135
  *
@@ -228,6 +266,59 @@ export function get_version() {
228
266
  export function init() {
229
267
  wasm.init();
230
268
  }
269
+
270
+ /**
271
+ * Find out which config files a chain needs before building a `Linter` from it.
272
+ *
273
+ * Embedders that can only read files asynchronously call this in a loop: start
274
+ * with the root file's contents, add whatever path the result asks for, and
275
+ * repeat until the chain is complete. Returns a JSON object with `status`:
276
+ *
277
+ * - `{"status": "need-file", "path": "base/.rumdl.toml"}`: read this path
278
+ * (relative paths are relative to wherever `root` is relative to), add it to
279
+ * `files` (or `null` if it does not exist), and call again.
280
+ * - `{"status": "complete", "files": [".rumdl.toml", "base/.rumdl.toml"]}`:
281
+ * every file is present; `files` lists the chain root first.
282
+ * - `{"status": "error", "message": "..."}`: the chain cannot be loaded
283
+ * (parse error, missing `extends` target, cycle, undefined `$VAR`, ...).
284
+ *
285
+ * ```javascript
286
+ * const files = { [root]: await read(root) };
287
+ * for (;;) {
288
+ * const r = JSON.parse(resolve_config_chain({ root, files }));
289
+ * if (r.status === "need-file") { files[r.path] = await readOrNull(r.path); continue; }
290
+ * if (r.status === "error") throw new Error(r.message);
291
+ * break;
292
+ * }
293
+ * const linter = Linter.from_config_files({ root, files });
294
+ * ```
295
+ * @param {any} request
296
+ * @returns {string}
297
+ */
298
+ export function resolve_config_chain(request) {
299
+ let deferred2_0;
300
+ let deferred2_1;
301
+ try {
302
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
303
+ wasm.resolve_config_chain(retptr, addHeapObject(request));
304
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
305
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
306
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
307
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
308
+ var ptr1 = r0;
309
+ var len1 = r1;
310
+ if (r3) {
311
+ ptr1 = 0; len1 = 0;
312
+ throw takeObject(r2);
313
+ }
314
+ deferred2_0 = ptr1;
315
+ deferred2_1 = len1;
316
+ return getStringFromWasm0(ptr1, len1);
317
+ } finally {
318
+ wasm.__wbindgen_add_to_stack_pointer(16);
319
+ wasm.__wbindgen_export4(deferred2_0, deferred2_1, 1);
320
+ }
321
+ }
231
322
  function __wbg_get_imports() {
232
323
  const import0 = {
233
324
  __proto__: null,
@@ -349,6 +440,10 @@ function __wbg_get_imports() {
349
440
  const ret = getObject(arg0)[arg1 >>> 0];
350
441
  return addHeapObject(ret);
351
442
  },
443
+ __wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
444
+ const ret = getObject(arg0)[getObject(arg1)];
445
+ return addHeapObject(ret);
446
+ },
352
447
  __wbg_instanceof_ArrayBuffer_7c8433c6ed14ffe3: function(arg0) {
353
448
  let result;
354
449
  try {
@@ -444,6 +539,10 @@ function __wbg_get_imports() {
444
539
  const ret = BigInt.asUintN(64, arg0);
445
540
  return addHeapObject(ret);
446
541
  },
542
+ __wbindgen_object_clone_ref: function(arg0) {
543
+ const ret = getObject(arg0);
544
+ return addHeapObject(ret);
545
+ },
447
546
  __wbindgen_object_drop_ref: function(arg0) {
448
547
  takeObject(arg0);
449
548
  },
package/rumdl_lib_bg.wasm CHANGED
Binary file