@ttsc/lint 0.31.5 → 0.32.1
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.
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
package linthost
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
"os"
|
|
5
|
+
"path/filepath"
|
|
6
|
+
"strings"
|
|
7
|
+
"testing"
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
// TestCommandCheckPreservesCompilerArgumentCwd verifies inherited compiler
|
|
@@ -19,60 +19,60 @@ import (
|
|
|
19
19
|
// @evidence contracts/testing.md#distinguishing-cases Inherited paired response, explicit argv and explicit [] suppression, absent payload and same-cwd default distinguish compiler cwd transport from program/rule root. Direct parser assertions supplement actual command delivery rather than claiming to intercept command state.
|
|
20
20
|
// @evidence contracts/testing.md#execution-ownership This maintained Go unit invokes command and in-process upstream parser/Program boundaries against t.TempDir/t.Setenv inputs; no external compiler, native host build, installed consumer or watcher runs.
|
|
21
21
|
func TestCommandCheckPreservesCompilerArgumentCwd(t *testing.T) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
22
|
+
root := t.TempDir()
|
|
23
|
+
a, b := filepath.Join(root, "A"), filepath.Join(root, "B")
|
|
24
|
+
for _, dir := range []string{a, b} {
|
|
25
|
+
writeFile(t, filepath.Join(dir, "base.json"), `{"compilerOptions":{"module":"commonjs","target":"ES2022","rootDir":".","outDir":"configured"}}`)
|
|
26
|
+
writeFile(t, filepath.Join(dir, "tsconfig.json"), `{"extends":"./base.json","files":["main.ts"]}`)
|
|
27
|
+
}
|
|
28
|
+
writeFile(t, filepath.Join(a, "main.ts"), "export const value = 1;\n")
|
|
29
|
+
writeFile(t, filepath.Join(b, "main.ts"), "export var value = 1;\n")
|
|
30
|
+
writeFile(t, filepath.Join(a, "args.rsp"), "--project ../B/tsconfig.json --outDir products --rootDir ../B\n")
|
|
31
|
+
seedLintRules(t, b, map[string]string{"no-var": "error"})
|
|
32
|
+
t.Setenv(tsgoArgsEnv, `["@args.rsp"]`)
|
|
33
|
+
t.Setenv(tsgoArgsCwdEnv, a)
|
|
34
|
+
args := []string{"check", "--cwd", b, "--plugins-json", lintManifest(t)}
|
|
35
|
+
code, stdout, stderr := captureCommandOutput(t, func() int { return run(args) })
|
|
36
|
+
if code != 2 || stdout != "" || !strings.Contains(stderr, "[no-var]") || !strings.Contains(stderr, "main.ts") {
|
|
37
|
+
t.Fatalf("selected B rule did not run: %d / %q / %q", code, stdout, stderr)
|
|
38
|
+
}
|
|
39
|
+
for _, c := range []struct {
|
|
40
|
+
name, raw, out string
|
|
41
|
+
}{
|
|
42
|
+
{"inherited pair", "", filepath.Join(a, "products")},
|
|
43
|
+
{"explicit argv", `["--outDir","products"]`, filepath.Join(b, "products")},
|
|
44
|
+
{"explicit empty", `[]`, filepath.Join(b, "configured")},
|
|
45
|
+
} {
|
|
46
|
+
t.Run(c.name, func(t *testing.T) {
|
|
47
|
+
forwarded, err := decodeTsgoArgs(c.raw)
|
|
48
|
+
if err != nil {
|
|
49
|
+
t.Fatal(err)
|
|
50
|
+
}
|
|
51
|
+
prog, diags, err := loadProgram(b, "tsconfig.json", loadProgramOptions{tsgoArgs: forwarded, tsgoArgsCwd: decodeTsgoArgsCwd(c.raw, forwarded)})
|
|
52
|
+
if err != nil || len(diags) != 0 || prog == nil {
|
|
53
|
+
t.Fatalf("load: %v / %#v", err, diags)
|
|
54
|
+
}
|
|
55
|
+
defer prog.close()
|
|
56
|
+
normalized := func(value string) string { return filepath.ToSlash(filepath.Clean(value)) }
|
|
57
|
+
options := prog.parsed.CompilerOptions()
|
|
58
|
+
if normalized(options.OutDir) != normalized(c.out) || normalized(options.RootDir) != normalized(b) || normalized(options.ConfigFilePath) != normalized(filepath.Join(b, "tsconfig.json")) {
|
|
59
|
+
t.Fatalf("wrong native options: out=%q root=%q config=%q", options.OutDir, options.RootDir, options.ConfigFilePath)
|
|
60
|
+
}
|
|
61
|
+
expectedRoot, err := os.Stat(b)
|
|
62
|
+
if err != nil {
|
|
63
|
+
t.Fatal(err)
|
|
64
|
+
}
|
|
65
|
+
physicalRoot, err := os.Stat(prog.identity.PhysicalProjectRoot)
|
|
66
|
+
if err != nil {
|
|
67
|
+
t.Fatal(err)
|
|
68
|
+
}
|
|
69
|
+
if prog.cwd != b || normalized(prog.tsProgram.GetCurrentDirectory()) != normalized(b) || prog.findSourceFile(filepath.Join(b, "main.ts")) == nil || prog.findSourceFile(filepath.Join(a, "main.ts")) != nil || !os.SameFile(expectedRoot, physicalRoot) {
|
|
70
|
+
t.Fatalf("compiler argument base replaced Program/rule identity: cwd=%q TypeScriptCwd=%q physicalRoot=%q expectedB=%q Bsource=%t Asource=%t", prog.cwd, prog.tsProgram.GetCurrentDirectory(), prog.identity.PhysicalProjectRoot, b, prog.findSourceFile(filepath.Join(b, "main.ts")) != nil, prog.findSourceFile(filepath.Join(a, "main.ts")) != nil)
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
t.Setenv(tsgoArgsEnv, "")
|
|
75
|
+
if decodeTsgoArgsCwd("", nil) != "" {
|
|
76
|
+
t.Fatal("orphan cwd channel acquired authority")
|
|
77
|
+
}
|
|
78
78
|
}
|
package/linthost/host.go
CHANGED
|
@@ -81,7 +81,7 @@ type loadProgramOptions struct {
|
|
|
81
81
|
// `--target es2020`, …). They are parsed through TypeScript-Go's own
|
|
82
82
|
// command-line parser into a CompilerOptions overlay that wins over the
|
|
83
83
|
// tsconfig, exactly as tsgo's CLI merges them.
|
|
84
|
-
tsgoArgs
|
|
84
|
+
tsgoArgs []string
|
|
85
85
|
// tsgoArgsCwd anchors response and CLI option parsing without changing the
|
|
86
86
|
// Program, rule-input or plugin project root. Empty retains cwd.
|
|
87
87
|
tsgoArgsCwd string
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttsc/lint",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"description": "Reference ttsc plugin: ESLint-style lint rules over the TypeScript-Go Program used by the type-check pass.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"src"
|
|
35
35
|
],
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@wrtnlabs/evidence": "^0.
|
|
37
|
+
"@wrtnlabs/evidence": "^0.5.1",
|
|
38
38
|
"@types/node": "^25.3.0",
|
|
39
39
|
"rimraf": "^6.1.2",
|
|
40
40
|
"typescript": "^7.0.2",
|
|
41
|
-
"ttsc": "0.
|
|
41
|
+
"ttsc": "0.32.1"
|
|
42
42
|
},
|
|
43
43
|
"repository": {
|
|
44
44
|
"type": "git",
|