/*
 * 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-5-attr-obs";const POSSIBLE_CONFORMING_ATTRS={"border":["img"],"charset":["script"],"language":["script"],"type":["script","style"],"name":["a"],"maxlength":["input"],"size":["input"]};function getName(){return RULE_NAME};function getShortDescription(){return"HTML5 obsolete attributes must not be used"};function getDescription(){return"HTML5 obsolete attributes must not be used."};function register(){return{"tag":_handleTag}};function _handleTag(ruleCtx,tagName){var attribs,attrName,attrValue,issue,attrPos,possibleConformingAttr;attribs=ruleCtx.node.attribs;if(!attribs){return}for(attrName in attribs){issue=null;attrName=attrName.charAt(0)!==":"?attrName:attrName.substring(1);possibleConformingAttr=_isPossibleConformingAttr(attrName);if(ruleCtx.utils.DomUtils.isHtml5ObsoleteAttr(tagName,attrName)){attrValue=attribs[attrName];if(_isConformingException(tagName,attrName,attrValue,attribs)){continue}issue=new ruleCtx.Issue("Attribute '"+attrName+"' is obsolete "+(possibleConformingAttr?"(but conforming) ":"")+"for <"+tagName+"> in HTML5")}else if(possibleConformingAttr){if(!_isConformingException(tagName,attrName,attrValue,attribs)){issue=new ruleCtx.Issue("Attribute '"+attrName+"' is obsolete but conforming <"+tagName+"> in HTML5")}}if(issue){attrPos=ruleCtx.utils.DomUtils.getAttribPosition(ruleCtx.data,ruleCtx.node,attrName);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end);issue.setMsgKey(RULE_NAME+(possibleConformingAttr?"_2":"_1"));ruleCtx.reporter.addIssue(issue,ruleCtx)}}};function _isConformingException(tagName,attrName,attrValue,attribs){var ret=false;if(tagName==="a"&&attrName==="name"){ret=_checkAnchor(attrValue,attribs)}else if(tagName==="img"&&attrName==="border"){ret=_checkImg(attrValue)}else if(tagName==="script"){if(attrName==="language"){ret=_checkScriptLanguage(attrValue,attribs)}else if(attrName==="charset"){ret=_checkScriptCharSet(attrValue,attribs)}}else if(tagName==="style"&&attrName==="type"){ret=_checkStyleType(attrValue,attribs)}return ret};function _checkAnchor(nameValue,attribs){var Id;if(nameValue==="")return true;Id=attribs.id;if(Id&&nameValue===Id)return true;return false};function _checkImg(borderValue){return borderValue==="0"};function _checkScriptLanguage(languageValue,attribs){if(languageValue.toLowerCase()==="javascript"){return!attribs.type||attribs.type.toLowerCase()==="text/javascript"}return true};function _checkScriptCharSet(charSetValue,attribs){return charSetValue.toLowerCase()==="utf-8"};function _checkStyleType(typeValue,attribs){return typeValue.toLowerCase()==="text/css"};function _isPossibleConformingAttr(attrName){};module.exports={getName,getDescription,getShortDescription,register};