@@ -20,6 +20,7 @@ function expectedMessage(name: string, context: string, language: string): strin
2020const testWords : LanguageReservedWords = {
2121 model : new Set ( [ "reserved" ] ) ,
2222 property : new Set ( [ "reserved" ] ) ,
23+ parameter : new Set ( [ "reserved" ] ) ,
2324 operation : new Set ( [ "reserved" ] ) ,
2425 enumType : new Set ( [ "reserved" ] ) ,
2526 enumMember : new Set ( [ "reserved" ] ) ,
@@ -30,6 +31,7 @@ const testRule = createReservedWordRule("test", "Test", testWords);
3031const contextIsolatedWords : LanguageReservedWords = {
3132 model : new Set ( [ "modelonly" ] ) ,
3233 property : new Set ( [ "proponly" ] ) ,
34+ parameter : new Set ( [ "paramonly" ] ) ,
3335 operation : new Set ( [ "oponly" ] ) ,
3436 enumType : new Set ( [ "enumtypeonly" ] ) ,
3537 enumMember : new Set ( [ "enummemberonly" ] ) ,
@@ -70,6 +72,13 @@ describe("reserved word rule factory", () => {
7072 } ) ;
7173 } ) ;
7274
75+ it ( "emits warning for reserved parameter name" , async ( ) => {
76+ await tester . expect ( `op foo(reserved: string): void;` ) . toEmitDiagnostics ( {
77+ code : "@azure-tools/typespec-client-generator-core/reserved-words-test" ,
78+ message : expectedMessage ( "reserved" , "parameter" , "Test" ) ,
79+ } ) ;
80+ } ) ;
81+
7382 it ( "emits warning for reserved enum type name" , async ( ) => {
7483 await tester . expect ( `enum reserved { a, b }` ) . toEmitDiagnostics ( {
7584 code : "@azure-tools/typespec-client-generator-core/reserved-words-test" ,
@@ -199,6 +208,27 @@ describe("context isolation", () => {
199208 await tester . expect ( `model oponly { name: string; }` ) . toBeValid ( ) ;
200209 } ) ;
201210
211+ // -- parameter-only word --
212+
213+ it ( "warns when parameter-only reserved word is used as a parameter name" , async ( ) => {
214+ await tester . expect ( `op foo(paramonly: string): void;` ) . toEmitDiagnostics ( {
215+ code : "@azure-tools/typespec-client-generator-core/reserved-words-isolated" ,
216+ message : expectedMessage ( "paramonly" , "parameter" , "Isolated" ) ,
217+ } ) ;
218+ } ) ;
219+
220+ it ( "does not warn when parameter-only reserved word is used as a property name" , async ( ) => {
221+ await tester . expect ( `model Foo { paramonly: string; }` ) . toBeValid ( ) ;
222+ } ) ;
223+
224+ it ( "does not warn when parameter-only reserved word is used as an operation name" , async ( ) => {
225+ await tester . expect ( `op paramonly(): void;` ) . toBeValid ( ) ;
226+ } ) ;
227+
228+ it ( "does not warn when parameter-only reserved word is used as a model name" , async ( ) => {
229+ await tester . expect ( `model paramonly { name: string; }` ) . toBeValid ( ) ;
230+ } ) ;
231+
202232 // -- enumType-only word --
203233
204234 it ( "warns when enumType-only reserved word is used as an enum type name" , async ( ) => {
@@ -282,6 +312,28 @@ describe("python reserved words", () => {
282312 } ) ;
283313 } ) ;
284314
315+ it ( "emits warning for 'keys' used as property name (Python dict method conflict)" , async ( ) => {
316+ await tester . expect ( `model Foo { keys: string; }` ) . toEmitDiagnostics ( {
317+ code : "@azure-tools/typespec-client-generator-core/reserved-words-python" ,
318+ message : expectedMessage ( "keys" , "property" , "Python" ) ,
319+ } ) ;
320+ } ) ;
321+
322+ it ( "'keys' does not warn as an operation name (property-only reserved word)" , async ( ) => {
323+ await tester . expect ( `op keys(): void;` ) . toBeValid ( ) ;
324+ } ) ;
325+
326+ it ( "emits warning for 'stream' used as parameter name (Python TSP-specific)" , async ( ) => {
327+ await tester . expect ( `op foo(stream: string): void;` ) . toEmitDiagnostics ( {
328+ code : "@azure-tools/typespec-client-generator-core/reserved-words-python" ,
329+ message : expectedMessage ( "stream" , "parameter" , "Python" ) ,
330+ } ) ;
331+ } ) ;
332+
333+ it ( "'stream' does not warn as a property name (parameter-only reserved word)" , async ( ) => {
334+ await tester . expect ( `model Foo { stream: string; }` ) . toBeValid ( ) ;
335+ } ) ;
336+
285337 it ( "is valid when @clientName resolves conflict for python scope" , async ( ) => {
286338 await tester
287339 . expect ( `model Foo { @clientName("yieldValue", "python") \`yield\`: string; }` )
0 commit comments