tinylint 0.1.0
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 +123 -0
- package/chunks/index-CanivEwi.js +1211 -0
- package/chunks/index-CanivEwi.js.map +1 -0
- package/engine.d.ts +6 -0
- package/engine.d.ts.map +1 -0
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -0
- package/monaco.d.ts +68 -0
- package/monaco.d.ts.map +1 -0
- package/monaco.js +343 -0
- package/monaco.js.map +1 -0
- package/package.json +29 -0
- package/types.d.ts +147 -0
- package/types.d.ts.map +1 -0
- package/utils.d.ts +10 -0
- package/utils.d.ts.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# TinyLint
|
|
2
|
+
|
|
3
|
+
TinyLint is a tiny (~8KB compressed) browser-first TypeScript-native linter. It runs directly on top of the `typescript` API, avoids parser duplication, and supports three integration modes:
|
|
4
|
+
|
|
5
|
+
- Direct `ts.Program` linting
|
|
6
|
+
- Persistent `programProvider` linting
|
|
7
|
+
- Managed in-memory `LanguageService` linting
|
|
8
|
+
- Monaco-friendly managed worker integration via `tinylint/monaco`
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install tinylint typescript
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
TinyLint ships the lint engine and rule API. You define the rules that fit your project. There are no built-in rules.
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import ts from "typescript";
|
|
22
|
+
import { createLinter, defineConfig, defineRule, DiagnosticSeverity, LintPhase, lintWithProgram, RuleMeta, RuleScope } from "tinylint";
|
|
23
|
+
|
|
24
|
+
// Define rules
|
|
25
|
+
const noDebuggerRule = defineRule({
|
|
26
|
+
meta: new RuleMeta("no-debugger", {
|
|
27
|
+
defaultSeverity: DiagnosticSeverity.Error,
|
|
28
|
+
requiresTypeInfo: false,
|
|
29
|
+
scope: RuleScope.File,
|
|
30
|
+
}),
|
|
31
|
+
nodeKinds: [ts.SyntaxKind.DebuggerStatement],
|
|
32
|
+
create(context) {
|
|
33
|
+
const ts = context.typescript;
|
|
34
|
+
return {
|
|
35
|
+
enter(node) {
|
|
36
|
+
if (ts.isDebuggerStatement(node) === false) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
context.report(node, "Unexpected debugger statement.");
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Create config containing all the rules
|
|
46
|
+
const config = defineConfig({
|
|
47
|
+
rules: {
|
|
48
|
+
"no-debugger": noDebuggerRule,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Example 1: lint against an existing ts.Program.
|
|
53
|
+
const program: ts.Program = createProgram();
|
|
54
|
+
|
|
55
|
+
const oneShotResult = lintWithProgram({
|
|
56
|
+
config,
|
|
57
|
+
currentFile: "/main.ts",
|
|
58
|
+
phase: LintPhase.Debounced,
|
|
59
|
+
program,
|
|
60
|
+
typescript: ts
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// Example 2: lint in-memory source code with the managed linter.
|
|
64
|
+
const managed = createLinter({
|
|
65
|
+
config,
|
|
66
|
+
files: {
|
|
67
|
+
"/main.ts": "debugger;\n",
|
|
68
|
+
},
|
|
69
|
+
typescript: ts
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const managedResult = managed.lint({ currentFile: "/main.ts", phase: LintPhase.Debounced });
|
|
73
|
+
|
|
74
|
+
// Example 3: replace the managed project contents and lint again.
|
|
75
|
+
managed.resetProject?.({
|
|
76
|
+
files: {
|
|
77
|
+
"/other.ts": "debugger;\n"
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const resetResult = managed.lint({ currentFile: "/other.ts", phase: LintPhase.Debounced });
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Public API
|
|
85
|
+
|
|
86
|
+
- `defineRule(rule)` adds a custom rule.
|
|
87
|
+
- `defineConfig(config)` creates a plain-object config.
|
|
88
|
+
- `lintWithProgram(...)` runs a one-shot pass against a caller-provided `ts.Program`.
|
|
89
|
+
- `createLinter(...)` creates either a provider-backed or managed persistent linter.
|
|
90
|
+
- `resetProject(...)` replaces the managed linter's current project and clears its caches.
|
|
91
|
+
|
|
92
|
+
## Monaco Integration
|
|
93
|
+
|
|
94
|
+
TinyLint does not depend on Monaco Editor, but it exposes a worker-friendly helper at `tinylint/monaco`.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
import ts from "typescript";
|
|
98
|
+
import { defineConfig, defineRule, DiagnosticSeverity, LintPhase, RuleMeta, RuleScope } from "tinylint";
|
|
99
|
+
import { createMonacoProjectLinter } from "tinylint/monaco";
|
|
100
|
+
|
|
101
|
+
const linter = createMonacoProjectLinter({
|
|
102
|
+
compilerOptions: {
|
|
103
|
+
module: ts.ModuleKind.ESNext,
|
|
104
|
+
noLib: true,
|
|
105
|
+
strict: true,
|
|
106
|
+
target: ts.ScriptTarget.ES2020
|
|
107
|
+
},
|
|
108
|
+
config,
|
|
109
|
+
snapshots: [
|
|
110
|
+
{
|
|
111
|
+
languageId: "typescript",
|
|
112
|
+
uri: "file:///main.ts",
|
|
113
|
+
value: "debugger;\n",
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
typescript: ts
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const result = linter.lintModel("file:///main.ts", LintPhase.Debounced);
|
|
120
|
+
// result.files[0].markers can be passed directly to monaco.editor.setModelMarkers(...)
|
|
121
|
+
|
|
122
|
+
linter.dispose();
|
|
123
|
+
```
|