/*
 * 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-ko-comment";const SHORT="JET elements should be used in place of Knockout comment bindings wherever possible.";const DESCRIPT="Use of user-developed custom Knockout bindings increases the direct dependency on Knockout "+"itself and raises the exposure to any future Knockout migration issues or bugs.";const BINDINGS=["foreach","if","ifnot","text","with","component"];const SUGGESTED=["oj-bind-for-each","oj-if","oj-if","oj-bind-text",null,null];var _overrides;function getName(){return RULE_NAME};function getShortDescription(){return SHORT};function getDescription(){return DESCRIPT};function register(regCtx){let opt=regCtx.rulePack.getRuleCustomOption("ignore");if(opt){if(!Array.isArray(opt)){regCtx.utils.msgLib.error(`Rule ${RULE_NAME} :  rule override option 'ignore' is not an array`);return false}_overrides=[];opt.forEach(val=>{_overrides.push(val.toLowerCase())})}return{"comment":_onComment}};function _onComment(ruleCtx,comment){if(comment.length===0||!comment.toLowerCase().startsWith("ko ")){return}let i=_eatWhite(comment,3);if(i<0){return}let issue,binding,suggest;comment=comment.substring(i);i=comment.indexOf(":");if(!(binding=i>0?comment.substring(0,i).trim():""))return;if(_overrides&&_overrides.indexOf(binding.toLowerCase())>=0){return}let suggestKey;if((suggestKey=_isKnownBinding(binding))>=0){suggest=_getSuggestedJetBinding(suggestKey);issue=new ruleCtx.Issue(`Knockout comment binding "${binding}:" found`+(suggest?`. Use of JET ${suggest} recommended.`:""))}else{issue=new ruleCtx.Issue(`Custom Knockout binding '${binding}' adds a direct dependency on KO itself and raises exposure to future KO migration issues/bugs.`);issue.setMsgKey(RULE_NAME+"_1");issue.setSeverity("minor")}if(issue){ruleCtx.reporter.addIssue(issue,ruleCtx)}};function _isKnownBinding(binding){return BINDINGS.indexOf(binding.toLowerCase())};function _getSuggestedJetBinding(index){var s;if(index>=0&&(s=SUGGESTED[index])){s=`<${s}>`}return s};function _eatWhite(str,startIndex){var i,len,ret=-1;startIndex=startIndex?startIndex:0;len=str?str.length:0;for(i=startIndex;i<len;i++){if(!_isWhite(str.charAt(i))){ret=i;break}}return ret};function _isWhite(c){return" \t\n\r\x0B".indexOf(c)>=0};module.exports={getName,getDescription,getShortDescription,register};