@@ -211,6 +211,52 @@ function componentVersionTsMacroCheck(context, node) {
211211 }
212212}
213213
214+ function componentActionAnnotationsCheck ( context , node ) {
215+ const component = getComponentFromNode ( node ) ;
216+
217+ if ( ! component ) return ;
218+ const { properties } = component ;
219+
220+ const typeProp = findPropertyWithName ( "type" , properties ) ;
221+ if ( typeProp ?. value ?. value !== "action" ) return ;
222+
223+ const annotationsProp = findPropertyWithName ( "annotations" , properties ) ;
224+
225+ // Error 1 - annotations missing entirely
226+ if ( ! annotationsProp ) {
227+ context . report ( {
228+ node : component ,
229+ message : "Action component is missing required 'annotations' object" ,
230+ } ) ;
231+ return ;
232+ }
233+
234+ // Error 2 - annotations is not an object expression
235+ if ( annotationsProp . value . type !== "ObjectExpression" ) {
236+ context . report ( {
237+ node : annotationsProp . value ,
238+ message : "Property 'annotations' must be an object expression" ,
239+ } ) ;
240+ return ;
241+ }
242+
243+ // Error 3 - required keys missing
244+ const requiredKeys = [
245+ "destructiveHint" ,
246+ "openWorldHint" ,
247+ "readOnlyHint" ,
248+ ] ;
249+
250+ for ( const requiredKey of requiredKeys ) {
251+ if ( ! astIncludesProperty ( requiredKey , annotationsProp . value . properties ) ) {
252+ context . report ( {
253+ node : annotationsProp . value ,
254+ message : `Property 'annotations' is missing required key: '${ requiredKey } '` ,
255+ } ) ;
256+ }
257+ }
258+ }
259+
214260// Rules run on two different AST node types: ExpressionStatement (CJS) and
215261// ExportDefaultDeclaration (ESM)
216262module . exports = {
@@ -347,5 +393,17 @@ module.exports = {
347393 } ;
348394 } ,
349395 } ,
396+ "action-annotations" : {
397+ create : function ( context ) {
398+ return {
399+ ExpressionStatement ( node ) {
400+ componentActionAnnotationsCheck ( context , node ) ;
401+ } ,
402+ ExportDefaultDeclaration ( node ) {
403+ componentActionAnnotationsCheck ( context , node ) ;
404+ } ,
405+ } ;
406+ } ,
407+ } ,
350408 } ,
351409} ;
0 commit comments