/*
 * Copyright (c) 2018, 2026, 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 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 SHORT_DESCRIPT="Custom components should not used a hard-coded 'for' attribute and it should be set an expression";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(ruleCtx,tagName){if(!ruleCtx.ojTag||!ruleCtx.filepath.includes("jet-composites")||!ruleCtx.tagNode.attribs){return}if(ruleCtx.utils.metaLib.isBindingTag(tagName)){return}let md;if(md=ruleCtx.utils.metaLib.getTagMetadata(tagName)){if(md.hasOwnProperty("type")&&md.type!=="composite"){return}}let isOjLabel,attribs,isFor,isColonFor;isOjLabel=tagName==="oj-label";attribs=ruleCtx.tagNode.attribs;isFor=attribs.hasOwnProperty(FOR);isColonFor=attribs.hasOwnProperty(COLON_FOR);if(!isFor&&!isColonFor){return}let attr=isFor?FOR:COLON_FOR;let isExpr=_isAttrExpr(attribs[attr]);let msg;if(isFor){if(isOjLabel){if(!isExpr){msg=`<${ruleCtx.tag}> 'for' should be set to an expression`}}else{msg=`<${ruleCtx.tag}> 'for' should be prefixed as ':for'"${!isExpr?" and set to an expression":""}`}}else{msg=isOjLabel?`<${ruleCtx.tag}> ':for' should be unprefixed${!isExpr?", and set to an expression":""}`:`<${ruleCtx.tag}> ':for' should be set to an expression`}if(msg){let issue=new ruleCtx.Issue(msg);let attrPos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.node,attr);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end);ruleCtx.reporter.addIssue(issue,ruleCtx)}};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};