@oracle/oraclejet-audit 15.0.1 → 15.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jaf-amd.js +1 -1
- package/lib/Issue.js +1 -1
- package/lib/MetaLib.js +1 -1
- package/lib/checkage.js +1 -1
- package/lib/defaults.js +1 -1
- package/meta/15.0.0/jetauditmeta.js +1 -1
- package/meta/metaverlist.json +1 -1
- package/package.json +2 -2
- package/rules/jet/oj-html-slot-pref-content.js +1 -1
- package/rules/jet/oj-tsx-slot-pref-content.js +1 -1
package/meta/metaverlist.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"metaList":{"8.3.0":{"version":"8.3.0","date":"Monday May 04, 2020","time":"4:34pm edt"},"9.0.0":{"version":"9.0.0","date":"Friday Jun 12, 2020","time":"1:57am utc"},"9.1.0":{"version":"9.1.0","date":"Thursday Aug 06, 2020","time":"2:13am utc"},"9.2.0":{"version":"9.2.0","date":"Wednesday Oct 07, 2020","time":"5:41pm utc"},"10.0.0":{"version":"10.0.0","date":"Thursday Jan 07, 2021","time":"9:20pm utc"},"10.1.0":{"version":"10.1.0","date":"Saturday Apr 17, 2021","time":"4:01pm utc"},"11.0.0":{"version":"11.0.0","date":"Friday Jul 02, 2021","time":"3:02am utc"},"11.1.0":{"version":"11.1.0","date":"Thursday Sep 30, 2021","time":"9:33pm utc"},"12.0.0":{"version":"12.0.0","date":"Friday Feb 04, 2022","time":"2:29am utc"},"12.1.0":{"version":"12.1.0","date":"Saturday Apr 09, 2022","time":"7:54am utc"},"13.0.0":{"version":"13.0.4","date":"Thursday Sep 22, 2022","time":"3:14am utc"},"13.1.0":{"version":"13.1.0","date":"Sunday Oct 02, 2022","time":"3:37am utc"},"14.0.0":{"version":"14.0.0","date":"Tuesday Jan 03, 2023","time":"8:54pm utc"},"14.1.0":{"version":"14.1.0","date":"Thursday Apr 06, 2023","time":"7:55pm utc"},"15.0.0":{"version":"15.0.
|
|
1
|
+
{"metaList":{"8.3.0":{"version":"8.3.0","date":"Monday May 04, 2020","time":"4:34pm edt"},"9.0.0":{"version":"9.0.0","date":"Friday Jun 12, 2020","time":"1:57am utc"},"9.1.0":{"version":"9.1.0","date":"Thursday Aug 06, 2020","time":"2:13am utc"},"9.2.0":{"version":"9.2.0","date":"Wednesday Oct 07, 2020","time":"5:41pm utc"},"10.0.0":{"version":"10.0.0","date":"Thursday Jan 07, 2021","time":"9:20pm utc"},"10.1.0":{"version":"10.1.0","date":"Saturday Apr 17, 2021","time":"4:01pm utc"},"11.0.0":{"version":"11.0.0","date":"Friday Jul 02, 2021","time":"3:02am utc"},"11.1.0":{"version":"11.1.0","date":"Thursday Sep 30, 2021","time":"9:33pm utc"},"12.0.0":{"version":"12.0.0","date":"Friday Feb 04, 2022","time":"2:29am utc"},"12.1.0":{"version":"12.1.0","date":"Saturday Apr 09, 2022","time":"7:54am utc"},"13.0.0":{"version":"13.0.4","date":"Thursday Sep 22, 2022","time":"3:14am utc"},"13.1.0":{"version":"13.1.0","date":"Sunday Oct 02, 2022","time":"3:37am utc"},"14.0.0":{"version":"14.0.0","date":"Tuesday Jan 03, 2023","time":"8:54pm utc"},"14.1.0":{"version":"14.1.0","date":"Thursday Apr 06, 2023","time":"7:55pm utc"},"15.0.0":{"version":"15.0.3","date":"Tuesday Aug 22, 2023","time":"4:30pm utc"}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oracle/oraclejet-audit",
|
|
3
|
-
"version": "15.0.
|
|
3
|
+
"version": "15.0.3",
|
|
4
4
|
"description": "JET AUDIT FRAMEWORK",
|
|
5
5
|
"main": "jaf.js",
|
|
6
6
|
"files": [
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"lint"
|
|
45
45
|
],
|
|
46
46
|
"Jaf": {
|
|
47
|
-
"version": "7.0.
|
|
47
|
+
"version": "7.0.5"
|
|
48
48
|
},
|
|
49
49
|
"license": "UPL-1.0",
|
|
50
50
|
"dependencies": {
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Licensed under The Universal Permissive License (UPL), Version 1.0
|
|
4
4
|
* as shown at https://oss.oracle.com/licenses/upl/
|
|
5
5
|
*/
|
|
6
|
-
const getParentNodeForSlot=require("./helpers/has-slot-name");const RULE_NAME="oj-html-slot-pref-content";const DESCRIPT="When component metadata defines 'preferredContent' for a slot, child elements placed into that slot should "+"implement one or more of the requested interfaces and document that through their 'implements' metadata. "+"This rule applies to components that are directly allocated to a slot, or which are direct children "+"of a template allocated to that slot.";const SHORT=DESCRIPT;const IGNORE_TAG=["oj-defer","html","head","body","script"];const TEMPLATE="template";const OJ_SWITCHER="oj-switcher";const OJ_DEFER="oj-defer";const OJ_BIND="oj-bind";const OJ_TOOLBAR="oj-toolbar";const OJ_LABEL="oj-label";const OJ_BIND_SLOT="oj-bind-slot";const DIV="div";const SPAN="span";const TAG="tag";const SLOT="slot";const _isBindTag=tagName=>{return tagName.startsWith("oj-bind")};const _ignoreTag=tagName=>{return IGNORE_TAG.includes(tagName)||tagName.startsWith("oj-bind")};function Rule(){};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT};Rule.prototype.getDescription=function(){return DESCRIPT};Rule.prototype.register=function(regCtx){this._metaLib=regCtx.utils.metaLib;this._hasJetWCInterfaces=this._metaLib.hasJetWCInterfaces();this._utils=regCtx.utils.utils;this._domUtils=regCtx.utils.DomUtils;return{"webcomp":this._onWebComp,"elem":this._onElem}};Rule.prototype._onElem=function(ruleCtx,elemName){if(ruleCtx.utils.DomUtils.isCommonElem(elemName)||elemName===TEMPLATE){if(!_ignoreTag(elemName)){return this._onWebComp(ruleCtx,elemName)}}};Rule.prototype._onWebComp=function(ruleCtx,tagName){var attribs=ruleCtx.tagNode.attribs;var slotx,slotName="";this._slotDefined=false;if(this._utils.hasAnyProps(attribs)){slotx=attribs[SLOT];if(slotx||slotx===""){slotName=slotx;this._slotDefined=true}}this._onSlot(ruleCtx,SLOT,slotName)};Rule.prototype._onSlot=function(ruleCtx,slotAttr,slotName){var pnode,slotTag,psc;if(slotName&&ruleCtx.tagNode.name===OJ_BIND_SLOT){return}if(!(pnode=getParentNodeForSlot(ruleCtx,slotName))){return}if(pnode.name===OJ_SWITCHER||!this._metaLib.isWCTag(pnode.name)){return}if(this._metaLib.isJetTag(pnode.name)&&!this._hasJetWCInterfaces){return}psc=this._metaLib.getPreferredSlotContentEx(pnode.name,slotName);if(!(psc&&psc.interfaces)){return}slotTag=ruleCtx.tag;if(slotTag==="oj-vb-fragment"||slotTag==="oj-module"){return}if(slotTag.startsWith(OJ_BIND)||slotTag===OJ_DEFER||slotTag===TEMPLATE||slotTag===DIV){let child;if(!(child=_getFirstChildTag(ruleCtx.tagNode.children))||!this._isSlotInterfaceSupported(child,psc)){if(child?.name!==SPAN){this._emitIssue(ruleCtx,ruleCtx.tagNode,slotName,pnode.name,psc,2)}}return}if(ruleCtx.utils.DomUtils.isCommonElem(slotTag)){if(pnode.name!==OJ_TOOLBAR&&ruleCtx.tagNode.name!==SPAN){this._emitIssue(ruleCtx,ruleCtx.tagNode,slotName,pnode.name,psc,3)}return}if(this._metaLib.isWCTag(slotTag)){if(!_isBindTag(slotTag)&&slotTag!==OJ_DEFER&&slotTag!==TEMPLATE){if(!this._isSlotInterfaceSupported(ruleCtx.tagNode,psc)){this._emitIssue(ruleCtx,ruleCtx.tagNode,slotName,pnode.name,psc,1)}}}};Rule.prototype._isSlotInterfaceSupported=function(node,psc){var ret,aIfc;if(aIfc=this._metaLib.getInterfaces(node.name)){for(let ifc of aIfc){if(psc.interfaces.includes(ifc)){ret=true;break}}}return ret};Rule.prototype._emitIssue=function(ruleCtx,elemNode,slotName,slotOwner,psci,issueType){var ifc=_list(psci.interfaces,"or");var comp=psci.components?` (e.g. ${_list(psci.components,"or",true)})`:"";var multi=psci.interfaces.length>1;var slotName=slotName?`slot '${slotName}'`:"default slot";var isDefSlot=!slotName;var issue,msg;if(issueType===1){msg=`<${elemNode.name}> is in${isDefSlot?" the":""} ${slotName} of <${slotOwner}> but does not implement interface${multi?"s":""} ${ifc}${comp}`}else if(issueType===2){msg=`<${elemNode.name}> is in${isDefSlot?" the":""} ${slotName} of <${slotOwner}> but its first child does not implement interface${multi?"s":""} ${ifc}${comp}`}else if(issueType===3){msg=`${slotName} on <${elemNode.name}> for <${slotOwner}> cannot provide ${multi?"interfaces":"an interface"} of type ${ifc}${comp}`}else{return}issue=new ruleCtx.Issue(msg);if(this._slotDefined){let attrPos=ruleCtx.utils.DomUtils.getAttrValuePosition(ruleCtx.data,ruleCtx.tagNode,SLOT);ruleCtx.utils.DomUtils.getAttrPosition(ruleCtx.data,ruleCtx.tagNode,SLOT);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end)}ruleCtx.reporter.addIssue(issue,ruleCtx)};function _getFirstChildTag(childs){var ret,childs,child;if(childs){for(let i=0;i<childs.length;i++){child=childs[i];if(child.type!==TAG){continue}if(child.name.startsWith("oj-bind-")||child.name===OJ_DEFER||child.name===TEMPLATE){return _getFirstChildTag(child.children)}ret=child;break}}return ret};function _list(a,orand,isComp){var s="";for(let i=0;i<a.length;i++){if(i){if(i===a.length-1){s+=(isComp?">":"'")+" "+orand+" "}else{s+=(isComp?">":"'")+", "}}s+=(isComp?"<":"'")+a[i]}return s?s+=isComp?">":"'":s};module.exports=Rule;
|
|
6
|
+
const getParentNodeForSlot=require("./helpers/has-slot-name");const RULE_NAME="oj-html-slot-pref-content";const DESCRIPT="When component metadata defines 'preferredContent' for a slot, child elements placed into that slot should "+"implement one or more of the requested interfaces and document that through their 'implements' metadata. "+"This rule applies to components that are directly allocated to a slot, or which are direct children "+"of a template allocated to that slot.";const SHORT=DESCRIPT;const IGNORE_TAG=["oj-defer","html","head","body","script"];const TEMPLATE="template";const OJ_SWITCHER="oj-switcher";const OJ_DEFER="oj-defer";const OJ_BIND="oj-bind";const OJ_TOOLBAR="oj-toolbar";const OJ_LABEL="oj-label";const OJ_BIND_SLOT="oj-bind-slot";const DIV="div";const SPAN="span";const TAG="tag";const SLOT="slot";const _isBindTag=tagName=>{return tagName.startsWith("oj-bind")};const _ignoreTag=tagName=>{return IGNORE_TAG.includes(tagName)||tagName.startsWith("oj-bind")};function Rule(){};Rule.prototype.getName=function(){return RULE_NAME};Rule.prototype.getShortDescription=function(){return SHORT};Rule.prototype.getDescription=function(){return DESCRIPT};Rule.prototype.register=function(regCtx){this._metaLib=regCtx.utils.metaLib;this._hasJetWCInterfaces=this._metaLib.hasJetWCInterfaces();this._utils=regCtx.utils.utils;this._domUtils=regCtx.utils.DomUtils;return{"webcomp":this._onWebComp,"elem":this._onElem}};Rule.prototype._onElem=function(ruleCtx,elemName){if(ruleCtx.utils.DomUtils.isCommonElem(elemName)||elemName===TEMPLATE){if(!_ignoreTag(elemName)){return this._onWebComp(ruleCtx,elemName)}}};Rule.prototype._onWebComp=function(ruleCtx,tagName){var attribs=ruleCtx.tagNode.attribs;var slotx,slotName="";this._slotDefined=false;if(this._utils.hasAnyProps(attribs)){slotx=attribs[SLOT];if(slotx||slotx===""){slotName=slotx;this._slotDefined=true}}this._onSlot(ruleCtx,SLOT,slotName)};Rule.prototype._onSlot=function(ruleCtx,slotAttr,slotName){var pnode,slotTag,psc;if(slotName&&ruleCtx.tagNode.name===OJ_BIND_SLOT){return}if(!(pnode=getParentNodeForSlot(ruleCtx,slotName))){return}if(pnode.name===OJ_SWITCHER||!this._metaLib.isWCTag(pnode.name)){return}if(this._metaLib.isJetTag(pnode.name)&&!this._hasJetWCInterfaces){return}psc=this._metaLib.getPreferredSlotContentEx(pnode.name,slotName);if(!(psc&&psc.interfaces)){return}slotTag=ruleCtx.tag;if(slotTag==="oj-vb-fragment"||slotTag==="oj-module"){return}if(slotTag.startsWith(OJ_BIND)||slotTag===OJ_DEFER||slotTag===TEMPLATE||slotTag===DIV){let child;if(!(child=_getFirstChildTag(ruleCtx.tagNode.children))||!this._isSlotInterfaceSupported(child,psc)){if(child?.name!==SPAN){this._emitIssue(ruleCtx,ruleCtx.tagNode,slotName,pnode.name,psc,2)}}return}if(ruleCtx.utils.DomUtils.isCommonElem(slotTag)){if(pnode.name!==OJ_TOOLBAR&&ruleCtx.tagNode.name!==SPAN){this._emitIssue(ruleCtx,ruleCtx.tagNode,slotName,pnode.name,psc,3)}return}if(this._metaLib.isWCTag(slotTag)){if(!_isBindTag(slotTag)&&slotTag!==OJ_DEFER&&slotTag!==TEMPLATE){if(!this._isSlotInterfaceSupported(ruleCtx.tagNode,psc)){this._emitIssue(ruleCtx,ruleCtx.tagNode,slotName,pnode.name,psc,1)}}}};Rule.prototype._isSlotInterfaceSupported=function(node,psc){var ret,aIfc;if(aIfc=this._metaLib.getInterfaces(node.name)){for(let ifc of aIfc){if(psc.interfaces.includes(ifc)){ret=true;break}}}return ret};Rule.prototype._emitIssue=function(ruleCtx,elemNode,slotName,slotOwner,psci,issueType){var ifc=_list(psci.interfaces,"or");var comp=psci.components?` (e.g. ${_list(psci.components,"or",true)})`:"";var multi=psci.interfaces.length>1;var actualSlot=slotName;var slotName=slotName?`slot '${slotName}'`:"default slot";var isDefSlot=!slotName;var issue,msg;if(issueType===1){msg=`<${elemNode.name}> is in${isDefSlot?" the":""} ${slotName} of <${slotOwner}> but does not implement interface${multi?"s":""} ${ifc}${comp}`}else if(issueType===2){msg=`<${elemNode.name}> is in${isDefSlot?" the":""} ${slotName} of <${slotOwner}> but its first child does not implement interface${multi?"s":""} ${ifc}${comp}`}else if(issueType===3){msg=`${slotName} on <${elemNode.name}> for <${slotOwner}> cannot provide ${multi?"interfaces":"an interface"} of type ${ifc}${comp}`}else{return}issue=new ruleCtx.Issue(msg);if(this._slotDefined){let attrPos=ruleCtx.utils.DomUtils.getAttrValuePosition(ruleCtx.data,ruleCtx.tagNode,SLOT);ruleCtx.utils.DomUtils.getAttrPosition(ruleCtx.data,ruleCtx.tagNode,SLOT);issue.setPosition(attrPos.row,attrPos.col,attrPos.start,attrPos.end)}issue.setMsgEx({slotName:actualSlot,slotElem:elemNode.name,slotOwner:slotOwner});ruleCtx.reporter.addIssue(issue,ruleCtx)};function _getFirstChildTag(childs){var ret,childs,child;if(childs){for(let i=0;i<childs.length;i++){child=childs[i];if(child.type!==TAG){continue}if(child.name.startsWith("oj-bind-")||child.name===OJ_DEFER||child.name===TEMPLATE){return _getFirstChildTag(child.children)}ret=child;break}}return ret};function _list(a,orand,isComp){var s="";for(let i=0;i<a.length;i++){if(i){if(i===a.length-1){s+=(isComp?">":"'")+" "+orand+" "}else{s+=(isComp?">":"'")+", "}}s+=(isComp?"<":"'")+a[i]}return s?s+=isComp?">":"'":s};module.exports=Rule;
|
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* Licensed under The Universal Permissive License (UPL), Version 1.0
|
|
4
4
|
* as shown at https://oss.oracle.com/licenses/upl/
|
|
5
5
|
*/
|
|
6
|
-
const getParentNodeForSlot=require("./helpers/tsx/has-slot-name");const RULE_NAME="oj-tsx-slot-pref-content";const DESCRIPT="When component metadata defines 'preferredContent' for a slot, child elements placed into that slot should "+"implement one or more of the requested interfaces and document that through their 'implements' metadata. "+"This rule applies to components that are directly allocated to a slot, or which are direct children "+"of a template allocated to that slot.";const SHORT=DESCRIPT;const IGNORE_TAG=["oj-defer","html","head","body","script"];const TEMPLATE="template";const OJ_SWITCHER="oj-switcher";const OJ_DEFER="oj-defer";const OJ_BIND="oj-bind";const OJ_TOOLBAR="oj-toolbar";const OJ_LABEL="oj-label";const OJ_BIND_SLOT="oj-bind-slot";const DIV="div";const SPAN="span";const TAG="tag";const SLOT="slot";const _isBindTag=tagName=>{return tagName.startsWith("oj-bind")};const _ignoreTag=tagName=>{return IGNORE_TAG.includes(tagName)||tagName.startsWith("oj-bind")};class Rule{getName(){return RULE_NAME}getDescription(){return DESCRIPT}getShortDescription(){return SHORT}register(regCtx){this._utils=regCtx.utils.utils;this._metaLib=regCtx.utils.metaLib;this._tsxUtils=regCtx.utils.tsxUtils;this._hasJetWCInterfaces=this._metaLib.hasJetWCInterfaces();return{"TsxRenderComponent":this._onTsxRC}}_onTsxRC(ruleCtx,tsxRC){tsxRC.components.forEach(tsxComp=>{this._checkComp(ruleCtx,tsxComp)})}_checkComp(ruleCtx,tsxComp){var tagName=tsxComp.name;var isTag;if(!(isTag=this._metaLib.isWCTag(tagName))){if(isTag=this._tsxUtils.isCommonElem(tagName)||tagName==="template"){isTag=!_ignoreTag(tagName)}}if(isTag){this._checkTag(ruleCtx,tsxComp)}if(tsxComp.children){tsxComp.children.forEach(child=>{this._checkComp(ruleCtx,child)})}}_checkTag(ruleCtx,tsxComp){var tsxProp,slotx,slotName="";this._slotDefined=false;if(tsxProp=this._tsxUtils.getProperty(tsxComp,SLOT)){if(this._tsxUtils.isPropertyString(tsxProp)){slotx=this._tsxUtils.getPropertyRawValue(tsxComp,SLOT,true)}}if(slotx||slotx===""){slotName=slotx;this._slotDefined=true}this._onSlot(ruleCtx,tsxComp,SLOT,slotName)}_onSlot(ruleCtx,tsxComp,slotAttr,slotName){var pnode,psc;var slotTag=tsxComp.name;if(slotName&&tsxComp.name===OJ_BIND_SLOT){return}if(!(pnode=getParentNodeForSlot(ruleCtx,tsxComp,slotName))){return}if(pnode.name===OJ_SWITCHER||!this._metaLib.isWCTag(pnode.name)){return}if(this._metaLib.isJetTag(pnode.name)&&!this._hasJetWCInterfaces){return}psc=this._metaLib.getPreferredSlotContentEx(pnode.name,slotName);if(!(psc&&psc.interfaces)){return}if(slotTag==="oj-vb-fragment"||slotTag==="oj-module"){return}if(slotTag.startsWith(OJ_BIND)||slotTag===OJ_DEFER||slotTag===TEMPLATE||slotTag===DIV){let child;if(!(child=this._getFirstChildTag(tsxComp.children))||!this._isSlotInterfaceSupported(child,psc)){if(child?.name!==SPAN){this._emitIssue(ruleCtx,tsxComp,slotName,pnode.name,psc,2)}}return}if(this._tsxUtils.isCommonElem(slotTag)){if(pnode.name!==OJ_TOOLBAR&&slotName!==SPAN){this._emitIssue(ruleCtx,tsxComp,slotName,pnode.name,psc,3)}return}if(this._metaLib.isWCTag(slotTag)){if(!_isBindTag(slotTag)&&slotTag!==OJ_DEFER&&slotTag!==TEMPLATE){if(!this._isSlotInterfaceSupported(tsxComp,psc)){this._emitIssue(ruleCtx,tsxComp,slotName,pnode.name,psc,1)}}}}_isSlotInterfaceSupported(tsxComp,psc){var ret,aIfc;if(aIfc=this._metaLib.getInterfaces(tsxComp.name)){for(let ifc of aIfc){if(psc.interfaces.includes(ifc)){ret=true;break}}}return ret}_emitIssue(ruleCtx,tsxComp,slotName,slotOwner,psci,issueType){var ifc=_list(psci.interfaces,"or");var comp=psci.components?` (e.g. ${_list(psci.components,"or",true)})`:"";var multi=psci.interfaces.length>1;var slotName=slotName?`slot '${slotName}'`:"default slot";var tagName=tsxComp.name;var isDefSlot=!slotName;var issue,msg;if(issueType===1){msg=`<${tagName}> is in${isDefSlot?" the":""} ${slotName} of <${slotOwner}> but does not implement interface${multi?"s":""} ${ifc}${comp}`}else if(issueType===2){msg=`<${tagName}> is in${isDefSlot?" the":""} ${slotName} of <${slotOwner}> but its first child does not implement interface${multi?"s":""} ${ifc}${comp}`}else if(issueType===3){msg=`${slotName} on <${tagName}> for <${slotOwner}> cannot provide ${multi?"interfaces":"an interface"} of type ${ifc}${comp}`}else{return}issue=new ruleCtx.Issue(msg);if(this._slotDefined){let tsxProp=this._tsxUtils.getProperty(tsxComp,SLOT);this._tsxUtils.setIssuePosition(issue,tsxProp)}ruleCtx.reporter.addIssue(issue,ruleCtx)}_getFirstChildTag(childs){var ret,childs,child;if(childs){for(let i=0;i<childs.length;i++){child=childs[i];if(child.name.startsWith("oj-bind-")||child.name===OJ_DEFER||child.name===TEMPLATE){return this._getFirstChildTag(child.children)}ret=child;break}}return ret}}function _list(a,orand,isComp){var s="";for(let i=0;i<a.length;i++){if(i){if(i===a.length-1){s+=(isComp?">":"'")+" "+orand+" "}else{s+=(isComp?">":"'")+", "}}s+=(isComp?"<":"'")+a[i]}return s?s+=isComp?">":"'":s};module.exports=Rule;
|
|
6
|
+
const getParentNodeForSlot=require("./helpers/tsx/has-slot-name");const RULE_NAME="oj-tsx-slot-pref-content";const DESCRIPT="When component metadata defines 'preferredContent' for a slot, child elements placed into that slot should "+"implement one or more of the requested interfaces and document that through their 'implements' metadata. "+"This rule applies to components that are directly allocated to a slot, or which are direct children "+"of a template allocated to that slot.";const SHORT=DESCRIPT;const IGNORE_TAG=["oj-defer","html","head","body","script"];const TEMPLATE="template";const OJ_SWITCHER="oj-switcher";const OJ_DEFER="oj-defer";const OJ_BIND="oj-bind";const OJ_TOOLBAR="oj-toolbar";const OJ_LABEL="oj-label";const OJ_BIND_SLOT="oj-bind-slot";const DIV="div";const SPAN="span";const TAG="tag";const SLOT="slot";const _isBindTag=tagName=>{return tagName.startsWith("oj-bind")};const _ignoreTag=tagName=>{return IGNORE_TAG.includes(tagName)||tagName.startsWith("oj-bind")};class Rule{getName(){return RULE_NAME}getDescription(){return DESCRIPT}getShortDescription(){return SHORT}register(regCtx){this._utils=regCtx.utils.utils;this._metaLib=regCtx.utils.metaLib;this._tsxUtils=regCtx.utils.tsxUtils;this._hasJetWCInterfaces=this._metaLib.hasJetWCInterfaces();return{"TsxRenderComponent":this._onTsxRC}}_onTsxRC(ruleCtx,tsxRC){tsxRC.components.forEach(tsxComp=>{this._checkComp(ruleCtx,tsxComp)})}_checkComp(ruleCtx,tsxComp){var tagName=tsxComp.name;var isTag;if(!(isTag=this._metaLib.isWCTag(tagName))){if(isTag=this._tsxUtils.isCommonElem(tagName)||tagName==="template"){isTag=!_ignoreTag(tagName)}}if(isTag){this._checkTag(ruleCtx,tsxComp)}if(tsxComp.children){tsxComp.children.forEach(child=>{this._checkComp(ruleCtx,child)})}}_checkTag(ruleCtx,tsxComp){var tsxProp,slotx,slotName="";this._slotDefined=false;if(tsxProp=this._tsxUtils.getProperty(tsxComp,SLOT)){if(this._tsxUtils.isPropertyString(tsxProp)){slotx=this._tsxUtils.getPropertyRawValue(tsxComp,SLOT,true)}}if(slotx||slotx===""){slotName=slotx;this._slotDefined=true}this._onSlot(ruleCtx,tsxComp,SLOT,slotName)}_onSlot(ruleCtx,tsxComp,slotAttr,slotName){var pnode,psc;var slotTag=tsxComp.name;if(slotName&&tsxComp.name===OJ_BIND_SLOT){return}if(!(pnode=getParentNodeForSlot(ruleCtx,tsxComp,slotName))){return}if(pnode.name===OJ_SWITCHER||!this._metaLib.isWCTag(pnode.name)){return}if(this._metaLib.isJetTag(pnode.name)&&!this._hasJetWCInterfaces){return}psc=this._metaLib.getPreferredSlotContentEx(pnode.name,slotName);if(!(psc&&psc.interfaces)){return}if(slotTag==="oj-vb-fragment"||slotTag==="oj-module"){return}if(slotTag.startsWith(OJ_BIND)||slotTag===OJ_DEFER||slotTag===TEMPLATE||slotTag===DIV){let child;if(!(child=this._getFirstChildTag(tsxComp.children))||!this._isSlotInterfaceSupported(child,psc)){if(child?.name!==SPAN){this._emitIssue(ruleCtx,tsxComp,slotName,pnode.name,psc,2)}}return}if(this._tsxUtils.isCommonElem(slotTag)){if(pnode.name!==OJ_TOOLBAR&&slotName!==SPAN){this._emitIssue(ruleCtx,tsxComp,slotName,pnode.name,psc,3)}return}if(this._metaLib.isWCTag(slotTag)){if(!_isBindTag(slotTag)&&slotTag!==OJ_DEFER&&slotTag!==TEMPLATE){if(!this._isSlotInterfaceSupported(tsxComp,psc)){this._emitIssue(ruleCtx,tsxComp,slotName,pnode.name,psc,1)}}}}_isSlotInterfaceSupported(tsxComp,psc){var ret,aIfc;if(aIfc=this._metaLib.getInterfaces(tsxComp.name)){for(let ifc of aIfc){if(psc.interfaces.includes(ifc)){ret=true;break}}}return ret}_emitIssue(ruleCtx,tsxComp,slotName,slotOwner,psci,issueType){var ifc=_list(psci.interfaces,"or");var comp=psci.components?` (e.g. ${_list(psci.components,"or",true)})`:"";var multi=psci.interfaces.length>1;var actualSlot=slotName;var slotName=slotName?`slot '${slotName}'`:"default slot";var tagName=tsxComp.name;var isDefSlot=!slotName;var issue,msg;if(issueType===1){msg=`<${tagName}> is in${isDefSlot?" the":""} ${slotName} of <${slotOwner}> but does not implement interface${multi?"s":""} ${ifc}${comp}`}else if(issueType===2){msg=`<${tagName}> is in${isDefSlot?" the":""} ${slotName} of <${slotOwner}> but its first child does not implement interface${multi?"s":""} ${ifc}${comp}`}else if(issueType===3){msg=`${slotName} on <${tagName}> for <${slotOwner}> cannot provide ${multi?"interfaces":"an interface"} of type ${ifc}${comp}`}else{return}issue=new ruleCtx.Issue(msg);if(this._slotDefined){let tsxProp=this._tsxUtils.getProperty(tsxComp,SLOT);this._tsxUtils.setIssuePosition(issue,tsxProp)}issue.setMsgEx({slotName:actualSlot,slotElem:tagName.name,slotOwner:slotOwner});ruleCtx.reporter.addIssue(issue,ruleCtx)}_getFirstChildTag(childs){var ret,childs,child;if(childs){for(let i=0;i<childs.length;i++){child=childs[i];if(child.name.startsWith("oj-bind-")||child.name===OJ_DEFER||child.name===TEMPLATE){return this._getFirstChildTag(child.children)}ret=child;break}}return ret}}function _list(a,orand,isComp){var s="";for(let i=0;i<a.length;i++){if(i){if(i===a.length-1){s+=(isComp?">":"'")+" "+orand+" "}else{s+=(isComp?">":"'")+", "}}s+=(isComp?"<":"'")+a[i]}return s?s+=isComp?">":"'":s};module.exports=Rule;
|