/*
 * Copyright (c) 2018, 2025, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const RULE_NAME="oj-html-wctag-for";const SHORT_DESCRIPT="Custom components should not used a hard-coded 'for' attribute and it should be set an expression";const LONG_DESCRIPT="Hard-coded 'for' attributes should not be used within custom components. 'for' attributes must be unique for each instance of the component and set to an expression. See context.uniqueId in the custom element documentation for information on how to derive unique values for elements."+"<p>If a webcomponent implements hard-coded 'for's for HTML elements in the web component view, e.g.<p>"+"<oj-input for=\"foo\"><p>"+"then this is guaranteed to cause issues as soon as more than one instance of "+"the component is used on the page (plus there is a significant risk of "+"collision with other attributes in the page as a whole.";const FOR="for";const COLON_FOR=":for";function getName(){return RULE_NAME};function getShortDescription(){return SHORT_DESCRIPT};function getDescription(){return LONG_DESCRIPT};function register(){return{"webcomp":_handle}}function _handle(context,tagName){var attribs,attr,isFor,isColonFor,isExpr,isOjLabel,msg,issue,attrPos;if(!context.ojTag||!context.filepath.includes("jet-composites")||!context.tagNode.attribs){return}if(context.utils.metaLib.isBindingTag(tagName)){return}isOjLabel=tagName==="oj-label";attribs=context.tagNode.attribs;isFor=attribs.hasOwnProperty(FOR);isColonFor=attribs.hasOwnProperty(COLON_FOR);if(!isFor&&!isColonFor){return}attr=isFor?FOR:COLON_FOR;isExpr=_isAttrExpr(attribs[attr]);if(isFor){if(isOjLabel){if(!isExpr){msg="<"+context.tag+"> 'for' should be set to an expression"}}else{msg="<"+context.tag+"> 'for' should be prefixed as ':for'"+(!isExpr?" and set to an expression":"")}}else{if(isOjLabel){msg="<"+context.tag+"> ':for' should be unprefixed"+(!isExpr?", and set to an expression":"")}else{msg="<"+context.tag+"> ':for' should be set to an expression"}}if(msg){issue=new context.Issue(msg);attrPos=context.utils.DomUtils.getAttribPosition(context.data,context.node,attr);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end);context.reporter.addIssue(issue,context)}};function _isAttrExpr(attrValue){var rc=false;if(typeof attrValue==="string"){attrValue=attrValue.trim();rc=attrValue.startsWith("[[")||attrValue.startsWith("{{")}return rc};module.exports={getName,getDescription,getShortDescription,register};