react-code-dataset / wp-calypso /packages /eslint-plugin-wpcalypso /lib /rules /post-message-no-wildcard-targets.js
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
/**
* @file Disallow using the wildcard `*` in postMessage
* @author Automattic
* @copyright 2017 Automattic. All rights reserved.
* See LICENSE.md file in root directory for full license.
*/
//------------------------------------------------------------------------------
// Helper Functions
//------------------------------------------------------------------------------
const getCallee = require( '../util/get-callee' );
const getTextContentFromNode = require( '../util/get-text-content-from-node' );
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
const rule = ( module.exports = function ( context ) {
return {
CallExpression: function ( node ) {
if ( 'postMessage' !== getCallee( node ).name ) {
return;
}
if ( node.arguments.length < 2 ) {
return;
}
const target = node.arguments[ 1 ];
if ( '*' === getTextContentFromNode( target ) ) {
context.report( node, rule.ERROR_MESSAGE );
}
},
};
} );
rule.ERROR_MESSAGE = 'Always provide a specific targetOrigin, not *';
rule.schema = [];