12 Reference: Custom Audit Rule Listener Types
Use this reference to learn about the listener types that you can register in custom audit rules. The available listener types are specific to the file types of the Oracle JET application.
Listener Types | Description |
---|---|
The Oracle JAF audit engine supports a long list of listener types specific to HTML and JSON files. |
|
The Oracle JAF audit engine supports listener types specific to CSS source files. |
|
The Oracle JAF audit engine supports listener types specific to JavaScript source files. |
|
The Oracle JAF audit engine supports listener types specific to Markdown source files. |
|
The Oracle JAF audit engine supports listener types specific to renderable JSX content in TSX source files. |
Listener Types for HTML and JSON Rules
The Oracle JAF audit engine supports a long list of listener types specific to HTML and JSON files.
The following table describes the listener event types for the various data nodes that JAF may encounter when parsing the contents of HTML and JSON files and generating an abstract syntax tree (AST) for the parsed files. You implement audit rules for the HTML and JSON files of your application by registering an event listener on the desired node. The table also list the expected arguments that you supply in the registered listener and the context properties that your listener can access on the event for a particular node.
Listener Type | Listener Arguments | Description, Including Available Context Properties |
---|---|---|
webcomp |
(Object context, string elementName) |
Called for any DOM element recognized as a web component. Your webcomp event listener can access the following context properties.
|
jetcomp |
(Object context, string elementName) |
Called for any JET web component. Your jetcomp event listener can access the
following context properties.
For all other context contents, refer to the previous webcomp entry. |
extcomp |
(Object context, string elementName) |
Called for any external (not-JET) web component. Your extcomp event listener can access the
following context properties.
For all other context contents, refer to the previous webcomp entry. |
elem |
(Object context, string elementName) |
Called for any DOM element. Your elem event listener can access the following context properties.
|
globtag |
(Object context, string elementName) |
Called for any global/common DOM element (including standard HTML5 element names). Your globtag event listener can access the following context properties.
|
notglob |
(Object context, string elementName) |
Called for any element that is not a common HTML name nor an SVG tag name. Your notglob event listener can access the
following context properties.
|
tag |
(Object context, string elementName) |
Called for any element name NOT starting with Your tag event listener can access the following properties.
|
bindingtag |
(Object context, string elementName) |
Called for a JET binding tag such as Your bindingtag event listener can access the following properties.
|
ojtag |
(Object context, string elementName) |
Called for any element name starting with Your ojtag event listener can access the following properties.
|
<component> |
(Object context, string elementName) |
Called for any non-global HTML element with the name declared between angle brackets (e.g., Your <component> event listener can access the following properties.
|
<component attrname=> |
(Object context, string attribName, string attribValue, string rawAttribValue) |
Called for the specified attribute if found on the component element (e.g., Whitespace is permitted on either side of the component name and before the ending chevron. The component declaration may not be a regular expression. Your <component attrname=> event listener can access the following
properties.
Note: See the note in the<attrname=>
entry for additional information regarding the
class and style
attributes.
|
<attrname=> |
(Object context, string attribName, string attribValue, string rawAttribValue) |
Called for the specified attribute found on any component element (e.g., This is a special case of the component/attribute combination listed above, with the component omitted. Whitespace is permitted on either side of the attribute declaration. Your <attrname=> event listener can access the following properties.
Note: This syntax should not be used forstyle or
class attributes. These special cases are
handled by their own registered types of style and class
respectively. See the subsequent entries in this table.
|
script |
(Object context, string elementName) |
Called for |
link |
(Object context, string elementName) |
Called for |
attr |
(Object context, string attribName, string attribValue, string rawAttribValue) |
Called for each attribute of an element (excluding Oracle JET The rawAttrValue attribute value contains the complete text including the string delimiting quotes. Your attr event listener can access the following property.
|
attrexpr |
(Object context, string attribName, string attribValue, string rawAttribValue) |
Called for each attribute of an element if the attribute value represents a |
attrexpr-$props |
(Object context, string attribName, string attribValue, string rawAttribValue) |
Called for each attribute whose value represents a
|
class |
(Object context, string elemName, string classValue) |
Called for each Your class event listener can access the following property.
|
style |
(Object context, string attribName, string[] attribValue, string rawAttribValue) |
Called for each The attrValue is an array of styles extracted from the style attribute. rawAttrValue is the attribute string. Your style event listener can access the following property.
|
type |
(Object context, string elemName, string typeValue) |
Called for each Your type event listener can access the following property.
|
event |
(Object context, string eventName, Object eventValue) |
Called for each Oracle JET event attribute (starting with The eventValue attribute is an object with the following properties:
Your event event listener can access the following property.
|
comment |
(Object context, string comment) |
Called for HTML comments of the form For example, for the comment <!-- This is a comment -->, the comment argument will contain the string |
doctype |
(Object context, string comment, string value) |
Called for directives of the form For example, for the comment <!DOCTYPE html>, the doctype argument will contain the full data, including the string |
procstmt |
(Object context, string procinstr, string value) |
Called for processing instructions of type For example, the procinstr argument might be the string |
directive |
(Object context, string directive, string value) |
Called for processing instructions of the form For example, for the directive <!ABCD xxxx>, the directive argument will contain the full data, including the string |
json |
(Object context) |
Called for a file of type Your json event listener can access the following properties.
|
compjson |
(Object context) |
Called for a file of type Your compjson event listener can access the following properties.
|
file |
(Object context) |
Called after reading a file, and prior to any standard rules (node rules, not hook rules) being fired on the file. Your file event listener can access the following properties.
|
endfile |
(Object context) |
Called after all standard rules (node rules, not hook rules) have been fired on the file. Your endfile event listener can access the following properties.
|
Listener Types for CSS Rules
The Oracle JAF audit engine supports listener types specific to CSS source files.
The following table describes the listener event types for the various data nodes that JAF may encounter when parsing the contents of CSS files and generating an abstract syntax tree (AST) for the parsed files. You implement audit rules for the CSS files of your application by registering an event listener on the desired CSS node. The table also list the expected arguments that you supply in the registered listener.
Listener Type | Listener Arguments | Description |
---|---|---|
css-sheet |
(Object context, node sheet) |
Called for a stylesheet. sheet is a node from the AST representing all the Rule nodes in the sheet. The complete AST can be found in context.ast. |
css-rule | (Object context, Object rule) |
Called for a CSS rule declaration. rule is a node from the AST. A rule node contains the following properties and sub-properties: SelectorList, Selector, Block. The complete AST can be found in context.ast. |
css-atrule | (Object context, Object rule, string identifier) |
Called for any CSS rule is a node from the AST. identifier is the rule identifier. For example, for A rule node contains the following properties and sub-properties: SelectorList, Selector, Block. The complete AST can be found in context.ast. |
css-@xxxx | (Object context, Object rule, string identifier) |
Called for a CSS statement of the name xxxx. For example, for rule is a node from the AST. identifier is the rule identifier. For example, for A rule node contains the following properties and sub-properties: SelectorList, Selector, Block. The complete AST can be found in context.ast. |
css-selector |
(Object context, node selector) |
Called for a selector of some type. Refer to node.type for the actual selector type. |
css-sel-type |
(Object context, node selector) |
Called for a type selector. |
css-sel-id |
(Object context, node selector) |
Called for an ID selector. |
css-sel-class |
(Object context, node selector) |
Called for a class selector. |
css-sel-pseudo |
(Object context, node selector) |
Called for a pseudo selector. |
css-var |
(Object context, node var, Object rule ) |
Called for a CSS variable declaration. var is the variable declaration node in the AST and contains all information about the variable. Two of the prominent members of var are:
Argument rule is the Rule object that contains the variable declaration. |
Listener Types for Markdown Rules
The Oracle JAF audit engine supports listener types specific to Markdown source files.
The following table describes the listener event types for the data nodes that JAF may encounter when parsing the contents of Markdown files and generating an abstract syntax tree (AST) for the parsed files. You implement audit rules for the Markdown files of your application by registering an event listener on the desired Markdown node. The table also lists the expected arguments that you supply in the registered listener.
For descriptions of the format of returned objects and their properties, see Context Object Properties Available to Markdown Rule Listeners.
Listener Type | Listener Arguments | Description |
---|---|---|
md-link |
(Object context, Object link) |
Invoked for direct or indirect link references. For example,
It is also invoked for URLs found in paragraph text without markup. The
If the link declaration uses a reference link, the link object will have the property inline declared to be |
md-ref | (Object context, Object ref) |
Invoked for indirect link references. For example,
The
|
md-para | (Object context, Object para) |
Invoked for paragraph text, and headings using The
Note: For standard paragraph text, level is 0. A value greater than zero represents the number of markup heading |
md-image | (Object context, Object image) |
Invoked for all image references. For example,
The
If the image declaration uses a reference link, the image object will have the property inline declared to be |
md-code | (Object context, Object code) |
Invoked for all fenced code blocks (using backticks or tildes). For example,
The
|
md-list | (Object context, Object list) |
Invoked for ordered or unordered lists using the markup The
If a list item represents a sub-list, the children property is used within the list item. The children property is an array containing sub-list objects; each object is formatted the same as the |
Listener Types for JavaScript/TypeScript Rules
The Oracle JAF audit engine supports listener types specific to JavaScript/TypeScript source files.
The following table describes the listener event types for the various data nodes that JAF may encounter when parsing the contents of JavaScript/TypeScript files and generating an abstract syntax tree (AST) for the parsed files. You implement audit rules for the JavaScript/TypeScript files of your application by registering an event listener on the desired JavaScript/TypeScript node.
Listener Type | Listener Type | Listener Type |
---|---|---|
AssignmentExpression AssignmentPattern ArrayExpression ArrayPattern ArrowFunctionExpression AwaitExpression BlockStatement BinaryExpression BreakStatement CallExpression CatchClause ClassBody ClassDeclaration ClassExpression ConditionalExpression ContinueStatement DoWhileStatement DebuggerStatement EmptyStatement ExperimentalRestProperty ExperimentalSpreadProperty ExpressionStatement ForStatement ForInStatement ForOfStatement FunctionDeclaration FunctionExpression |
Identifier IfStatement Literal LabeledStatement LogicalExpression MemberExpression MetaProperty MethodDefinition NewExpression ObjectExpression ObjectPattern Program Property RestElement ReturnStatement SequenceExpression SpreadElement Super SwitchCase SwitchStatement TaggedTemplateExpression TemplateElement TemplateLiteral ThisExpression ThrowStatement TryStatement UnaryExpression |
UpdateExpression VariableDeclaration VariableDeclarator WhileStatement WithStatement YieldExpression JSXIdentifier JSXNamespacedName JSXMemberExpression JSXEmptyExpression JSXExpressionContainer JSXElement JSXClosingElement JSXOpeningElement JSXAttribute JSXSpreadAttribute JSXText ExportDefaultDeclaration ExportNamedDeclaration ExportAllDeclaration ExportSpecifier ImportDeclaration ImportSpecifier ImportDefaultSpecifier ImportNamespaceSpecifier |
As an alternative to the AST node types defined above, an object of abbreviated string constants can be found in the rule context. For example:
var NT = ruleCtx.utils.AstUtils.getNodeTypes() ;
if (node.type === NT.CALL_EXPR || node.type === NT.MEMBER_EXPR) {
. . .
}
In the register context, the node types object can be found in regCtx.jsNodeTypes() or regCtx.tsNodeTypes(), depending on whether the rule handles JavaScript or TypeScript. The following example caches the node types for JavaScript.
var NT ;
register(regXtx) {
NT = regCtx.jsNodeTypes ; // cache the node types
. . .
}
Here is a list of available constants:
Constant | Node Type |
---|---|
ARRAY_EXPR | "ArrayExpression" |
ARROW_FUNC_EXPR | "ArrowFunctionExpression" |
ASSIGN_PATTERN | "AssignmentPattern" |
ASSIGN_EXPR | "AssignmentExpression" |
ASSIGNMENT_EXPR | "AssignmentExpression" |
AWAIT_EXPR | "AwaitExpression" |
BINARY_EXPR | "BinaryExpression" |
BLOCK_STMT | "BlockStatement" |
BREAK_STMT | "BreakStatement" |
CALL_EXPR | "CallExpression" |
CATCH_CLAUSE | "CatchClause" |
CLASS_BODY | "ClassBody" |
CLASS_DECLARATION | "ClassDeclaration" |
CONDITIONAL_EXPR | "ConditionalExpression" |
CONTINUE_STMT | "ContinueStatement |
CLASS_EXPR | "ClassExpression" |
DO_WHILE_STMT | "DoWhileStatement" |
DEBUG_STMT | "DebuggerStatement" |
EMPTY_STMT | "EmptyStatement" |
EX_REST_PROP | "ExperimentalRestProperty" |
EXPR_STMT | "ExpressionStatement" |
EX_SPREAD_STMT | "ExperimentalSpreadProperty" |
FOR_STMT | "ForStatement" |
FOR_IN_STMT | "ForInStatement" |
FOR_OF_STMT | "ForOfStatement" |
FUNC_DECLARATION | "FunctionDeclaration" |
FUNC_EXPR | "FunctionExpression" |
IDENTIFIER | "Identifier" |
IF_STMT | "IfStatement" |
LOGIC_EXPR | "LogicalExpression" |
LABELED_STMT | "LabeledStatement" |
LITERAL | "Literal" |
MEMBER_EXPR | "MemberExpression" |
META_PROP | "MetaProperty" |
METH_DEF | "MethodDefinition" |
NEW_EXPR | "NewExpression" |
OBJ_EXPR | "ObjectExpression" |
OBJ_PATTERN | "ObjectPattern" |
PROGRAM | "Program" |
PROPERTY | "Property" |
PROPERTY_DEF |
"PropertyDefintion" Note: The parent node of an ArrowFunctionExpression used to define a class method may be changed when using the newer AST parser library from ClassProperty to this PropertyDefintion node type |
REST_ELEM | "RestElement" |
RETURN_STMT | "ReturnStatement" |
SEQUENCE_EXPR | "SequenceExpression" |
SPREAD_ELEM | "SpreadElement" |
SUPER | "Super" |
SWITCH_CASE | "SwitchCase" |
SWITCH_STMT | "SwitchStatement" |
TAGGED_TEMPLATE_EXPR | "TaggedTemplateExpression" |
TEMPLATE_ELEM | "TemplateElement" |
TEMPLATE_LIT | "TemplateLiteral" |
THIS_EXPR | "ThisExpression" |
THROW_EXPR | "ThrowExpression" |
TRY_STMT | "TryStatement" |
UNARY_EXPR | "UnaryExpression" |
UPDATE_EXPR | "UpdateExpression" |
VAR_DECLARATION | "VariableDeclaration" |
VAR_DECLARATOR | "VariableDeclarator" |
WHILE_STMT | "WhileStatement" |
WITH_STMT | "WithStatementt" |
YIELD_EXPR | "YieldExpression" |
JSX_ID | "JSXIdentifier" |
JSX_NS_NAME | "JSXNamespacedName" |
JSX_EMPTY_EXPR | "JSXEmptyExpression" |
JSX_EXPR_CONTAINER | "JSXExpressionContainer" |
JSX_ELEM | "JSXElement" |
JSX_CLOSING_ELEM | "JSXClosingElement" |
JSX_OPENING_ELEM | "JSXOpeningElement" |
JSX_ATTRIB | "JSXAttribute" |
SX_SPREAD_ATTRIB | "JSXSpreadAttribute" |
JSX_TEXT | "JSXText" |
EXPORT_DEFAULT_DECL | "ExportDefaultDeclaration" |
EXPORT_NAMED_DECL | "ExportNamedDeclaration" |
EXPORT_ALL_DECL | "ExportAllDeclaration" |
EXPORT_SPECIFIER | "ExportSpecifier" |
IMPORT_DECL | "ImportDeclaration" |
IMPORT_EQUALS_DECL | "TSImportEqualsDeclaration" |
IMPORT_SPECIFIER | "ImportSpecifier" |
IMPORT_DEFAULT_SPECIFIER | "ImportDefaultSpecifier" |
IMPORT_NS_SPECIFIER | "ImportNamespaceSpecifier" |
EXTERN_MOD_REF | "TSExternalModuleReference" |
Listener Types for TSX Rules
The Oracle JAF audit engine supports listener types specific to TSX files.
The following table describes the listener event types for the various data nodes that JAF may encounter when parsing the contents of TSX files and generating an abstract syntax tree (AST) for the parsed files. You implement audit rules for the TSX files of your application by registering an event listener on the desired node. The table also list the expected arguments that you supply in the registered listener and the context properties that your listener can access on the event for a particular node.
Listener Type | Listener Signature | Description, Including Available Context Properties |
---|---|---|
TsxRenderComponent |
(Object ruleContext, Object tsxRenderComponent) |
Called for an associated group of TSX renderable content (that is, multiple component/HTML markup elements in a single declaration, such as a render() call, or a variable declaration, and so on.) |
TsxComponent |
(Object ruleContext, Object tsxComponent) |
Called for any component/HTML element/Preact function found in the TSX renderable content. |
TsxWebComponent |
(Object ruleContext, Object tsxComponent) |
Called for any web component known to JAF found in the TSX renderable content. |
TsxJetComponent |
(Object ruleContext, Object tsxComponent) |
Called for any JET web component (legacy or Jet Core pack) |
TsxElem |
(Object ruleContext, Object tsxComponent) |
Called for any standard HTML element found in the TSX renderable content. |
TsxProperty |
(Object ruleContext, Object tsxProperty) |
Called for any property found in the TSX renderable content. |
Tsx<component_name> |
(Object ruleContext, Object tsxComponent) |
Called for the named component/HTML element element found in the TSX renderable content. |
Tsx<component_name propName=> |
(Object ruleContext, Object tsxProperty) |
Called for the named component/HTML element and named property found in the TSX renderable content. |
Tsx<propName=> |
(Object ruleContext, Object tsxProperty) |
Called for the named property found in the TSX renderable markup. |
Additionally, all file hook listener types (such as file
and
endfile
) and any AST node types are permitted.
Note:
For named properties and events, the TSX form shown above must be used. That is, an event type of the form<oj-foo>
cannot be used. It must be declared
as Tsx<oj-foo>
.