@@ -32,23 +32,44 @@ export namespace Example { export class Error extends Schema.TaggedErrorClass<Er
3232 } ,
3333 {
3434 name : "spread fields" ,
35- errors : 0 ,
35+ errors : 1 ,
3636 source : `import { Schema } from "effect"
3737const fields = { message: Schema.String }
3838class Example extends Schema.TaggedErrorClass<Example>()("Example", { ...fields }) {}` ,
3939 } ,
4040 {
4141 name : "computed fields" ,
42- errors : 0 ,
42+ errors : 1 ,
4343 source : `import { Schema } from "effect"
4444const key = "message"
4545class Example extends Schema.TaggedErrorClass<Example>()("Example", { [key]: Schema.String }) {}` ,
46+ } ,
47+ {
48+ name : "optional message" ,
49+ errors : 1 ,
50+ source : `import { Schema } from "effect"
51+ class Example extends Schema.TaggedErrorClass<Example>()("Example", { message: Schema.optional(Schema.String) }) {}` ,
52+ } ,
53+ {
54+ name : "piped optional message" ,
55+ errors : 1 ,
56+ source : `import { Schema } from "effect"
57+ class Example extends Schema.TaggedErrorClass<Example>()("Example", { message: Schema.String.pipe(Schema.optional) }) {}` ,
4658 } ,
4759 {
4860 name : "unrelated Schema binding" ,
4961 errors : 0 ,
5062 source : `const Schema = getSchema()
5163class Example extends Schema.TaggedErrorClass()("Example", {}) {}` ,
64+ } ,
65+ {
66+ name : "shadowed Schema binding" ,
67+ errors : 0 ,
68+ source : `import { Schema } from "effect"
69+ function example() {
70+ const Schema = getSchema()
71+ return class extends Schema.TaggedErrorClass()("Example", {}) {}
72+ }` ,
5273 } ,
5374 {
5475 name : "missing message" ,
@@ -67,6 +88,24 @@ class Example extends Schema.TaggedErrorClass<Example>()("Example", {}) { static
6788 errors : 1 ,
6889 source : `import { Schema } from "effect"
6990class Example extends Schema.TaggedErrorClass<Example>()("Example", {}) { declare message: string }` ,
91+ } ,
92+ {
93+ name : "undefined property" ,
94+ errors : 1 ,
95+ source : `import { Schema } from "effect"
96+ class Example extends Schema.TaggedErrorClass<Example>()("Example", {}) { override message = undefined }` ,
97+ } ,
98+ {
99+ name : "empty getter" ,
100+ errors : 1 ,
101+ source : `import { Schema } from "effect"
102+ class Example extends Schema.TaggedErrorClass<Example>()("Example", {}) { override get message() { return "" } }` ,
103+ } ,
104+ {
105+ name : "non-string message schema" ,
106+ errors : 1 ,
107+ source : `import { Schema } from "effect"
108+ class Example extends Schema.TaggedErrorClass<Example>()("Example", { message: Schema.Unknown }) {}` ,
70109 } ,
71110 {
72111 name : "documented disable" ,
@@ -88,28 +127,31 @@ try {
88127 rules : { "opencode/tagged-error-message" : "error" } ,
89128 } ) ,
90129 )
91- for ( const [ index , fixture ] of cases . entries ( ) ) {
92- const file = path . join ( directory , `${ index } .ts` )
93- await Bun . write ( file , fixture . source )
94- const result = Bun . spawnSync ( [
95- path . join ( import . meta. dir , "../../node_modules/.bin/oxlint" ) ,
96- "--config" ,
97- config ,
98- "--format" ,
99- "json" ,
100- file ,
101- ] )
102- if ( ! result . stdout . length ) throw new Error ( `${ fixture . name } : ${ result . stderr . toString ( ) } ` )
103- const diagnostics : unknown = JSON . parse ( result . stdout . toString ( ) )
104- if ( ! hasDiagnostics ( diagnostics ) ) throw new Error ( `${ fixture . name } : invalid Oxlint output` )
105- const errors = diagnostics . diagnostics . filter (
106- ( item ) => typeof item === "object" && item !== null && "code" in item && item . code === "opencode(tagged-error-message)" ,
107- ) . length
108- if ( errors !== fixture . errors )
109- throw new Error (
110- `${ fixture . name } : expected ${ fixture . errors } errors, received ${ errors } \n${ result . stdout . toString ( ) } ` ,
111- )
112- }
130+ await Promise . all (
131+ cases . map ( async ( fixture , index ) => {
132+ const file = path . join ( directory , `${ index } .ts` )
133+ await Bun . write ( file , fixture . source )
134+ const result = Bun . spawnSync ( [
135+ path . join ( import . meta. dir , "../../node_modules/.bin/oxlint" ) ,
136+ "--config" ,
137+ config ,
138+ "--format" ,
139+ "json" ,
140+ file ,
141+ ] )
142+ if ( ! result . stdout . length ) throw new Error ( `${ fixture . name } : ${ result . stderr . toString ( ) } ` )
143+ const diagnostics : unknown = JSON . parse ( result . stdout . toString ( ) )
144+ if ( ! hasDiagnostics ( diagnostics ) ) throw new Error ( `${ fixture . name } : invalid Oxlint output` )
145+ const errors = diagnostics . diagnostics . filter ( isErrorDiagnostic )
146+ if ( errors . length !== fixture . errors || ! errors . every ( isRuleDiagnostic ) )
147+ throw new Error (
148+ `${ fixture . name } : expected ${ fixture . errors } errors, received ${ errors . length } \n${ result . stdout . toString ( ) } ` ,
149+ )
150+ const exitCode = fixture . errors === 0 ? 0 : 1
151+ if ( result . exitCode !== exitCode || result . signalCode )
152+ throw new Error ( `${ fixture . name } : expected exit ${ exitCode } , received ${ result . exitCode } ` )
153+ } ) ,
154+ )
113155} finally {
114156 await rm ( directory , { recursive : true , force : true } )
115157}
@@ -119,3 +161,16 @@ console.log(`Validated ${cases.length} tagged error lint fixtures`)
119161function hasDiagnostics ( value : unknown ) : value is { diagnostics : unknown [ ] } {
120162 return typeof value === "object" && value !== null && "diagnostics" in value && Array . isArray ( value . diagnostics )
121163}
164+
165+ function isRuleDiagnostic ( value : unknown ) {
166+ return (
167+ typeof value === "object" &&
168+ value !== null &&
169+ "code" in value &&
170+ value . code === "opencode(tagged-error-message)"
171+ )
172+ }
173+
174+ function isErrorDiagnostic ( value : unknown ) {
175+ return typeof value === "object" && value !== null && "severity" in value && value . severity === "error"
176+ }
0 commit comments