/*
 * 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 FORMAT_JSON="json";var Reporter=function(msgCtx){this._issues=[];this._msgCtx=msgCtx;this._msgFilter=null;this._isDebug=msgCtx.isDebug;this._debug=msgCtx.debug;this._severity=null};Reporter.prototype.addIssue=function(issue,ruleCtx,severity){var sev,usev,id,offset;if(!issue||!ruleCtx){return}var rulePack=ruleCtx.rulePack;var opts=rulePack.getRuleOptions(ruleCtx.ruleName,null,true);if(opts.$sevLocked){issue.severity=opts.severity}else{issue.severity=severity&&this._severity.isValidRuleSeverity(severity)?severity:issue.severity?issue.severity:opts.severity}if(!issue.msgId){issue.msgId=ruleCtx.getMsgId(ruleCtx,issue.msgKey)}issue.prefix=rulePack.getPrefix();id=issue.prefix+"-"+issue.msgId;if(this._isDebug){this._debug(`  emitted -> [${id}]: "${issue.msg&&issue.msg.length>60?issue.msg.substring(0,60)+"...":issue.msg}"`)}if(this._msgFilter&&!this._isMsgFiltered(id)){if(this._isDebug){this._debug("..Issue suppressed by config.messages")}return}sev=this._severity.getMsgSev(id);usev=sev?this._severity.unmap(sev):issue.severity;if(!this._severity.matchSeverityLevel(usev)){if(this._isDebug)this._debug("Reporter ignoring issue because of severity");return}issue.severity=sev||usev;issue.rsi=ruleCtx._rsi;offset=ruleCtx.position?ruleCtx.position.offset:0;offset=typeof offset==="number"?offset:0;if(issue.index!==undefined){if(issue.index.start===undefined){issue.index.start=ruleCtx.position.start;issue.index.end=ruleCtx.position.end}}else{issue.index=ruleCtx.position}if(issue.index&&issue.index.start!==undefined){if(offset>0){issue.index.start+=offset;issue.index.end+=offset;issue.index.line=undefined}}issue.$hook=opts.$hook;if(this._outFormat===FORMAT_JSON){issue.name=issue.filepath?issue.filepath:ruleCtx.filepath}issue.ruleName=ruleCtx.ruleName;issue.token=this._parseData;issue.tokType=this._parseType;if(ruleCtx.filepath&&!issue.filepath){issue.filepath=ruleCtx.filepath}issue.msg=issue.msg.replace(/&lt;/g,"<");issue.msg=issue.msg.replace(/&gt;/g,">");this._issues.push(issue)};Reporter.prototype.getIssues=function(){return this._issues};Reporter.prototype.getCount=function(){return this._issues.length};Reporter.prototype.clearIssues=function(){return this._issues.length=0};Reporter.prototype.setParseData=function(parseData,parseType){this._parseData=parseData;this._parseType=parseType};Reporter.prototype.getFormat=function(){return this._outFormat};Reporter.prototype.setOutFormat=function(format){return this._outFormat=format};Reporter.prototype.setSevInstance=function(sevInst){this._severity=sevInst};Reporter.prototype.setDebugMode=function(b){this._isDebug=b};Reporter.prototype.setMessageFilter=function(messages){var a,am,i;if(messages){a=messages.accept?messages.accept:messages.reject?messages.reject:null;if(a&&a.length){am=[];for(i=0;i<a.length;i++){am.push(new RegExp(a[i]))}}if(am){if(messages.reject){this._msgFilter={reject:am}}else if(messages.accept){this._msgFilter={accept:am}}}}if(!am){this._msgFilter=null}};Reporter.prototype._isMsgFiltered=function(msgId){var a,b=false,i;if(!this._msgFilter){return true}a=this._msgFilter.accept?this._msgFilter.accept:this._msgFilter.reject?this._msgFilter.reject:null;if(a){for(i=0;i<a.length;i++){if(a[i].test(msgId)){b=true;break}}}return this._msgFilter.accept?b:!b};module.exports=Reporter;