@@ -527,6 +527,47 @@ function createCollectionOrUtilMethodRule( methods, message, options ) {
527527 } ) , description , options . fixable , options . deprecated ) ;
528528}
529529
530+ /**
531+ * Create a rule for a method on any object
532+ *
533+ * @param {string|string[] } methods Method or list of method names
534+ * @param {string|Function } message Message to report. See createCollectionMethodRule.
535+ * @param {Function } linkGenerator Function to generate a markdown link
536+ * @param {Object } [options] Options. See createCollectionMethodRule.
537+ * for a given function name.
538+ * @return {Object } Rule
539+ */
540+ function createUniversalMethodRule ( methods , message , linkGenerator , options ) {
541+ options = options || { } ;
542+
543+ options . mode = 'util' ;
544+
545+ methods = Array . isArray ( methods ) ? methods : [ methods ] ;
546+
547+ let description = 'Disallows the ' + methods . map ( linkGenerator ) . join ( '/' ) + ' ' +
548+ ( methods . length > 1 ? 'methods' : 'method' ) + '.' ;
549+
550+ description += messageSuffix ( message ) ;
551+
552+ return createRule ( ( context ) => ( {
553+ 'CallExpression:exit' : ( node ) => {
554+ if ( node . callee . type !== 'MemberExpression' ) {
555+ return ;
556+ }
557+ const name = node . callee . property . name ;
558+ if ( ! methods . includes ( name ) ) {
559+ return ;
560+ }
561+
562+ context . report ( {
563+ node,
564+ message : messageToPlainString ( message , node , name , options ) ,
565+ fix : options . fix && options . fix . bind ( this , node , context )
566+ } ) ;
567+ }
568+ } ) , description , options . fixable , options . deprecated ) ;
569+ }
570+
530571function eventShorthandFixer ( node , context , fixer ) {
531572 const name = node . callee . property . name ;
532573 if ( node . callee . parent . arguments . length ) {
@@ -580,6 +621,7 @@ module.exports = {
580621 createUtilMethodRule,
581622 createUtilPropertyRule,
582623 createCollectionOrUtilMethodRule,
624+ createUniversalMethodRule,
583625 eventShorthandFixer,
584626 jQueryCollectionLink,
585627 jQueryGlobalLink,
0 commit comments