@@ -45,38 +45,41 @@ module.exports = {
45
45
node . callee . property . type === 'Identifier' && node . callee . property . name === 'report'
46
46
) {
47
47
const reportInfo = utils . getReportInfo ( node . arguments , context ) ;
48
- if ( ! reportInfo || ! reportInfo . message ) {
48
+ if ( ! reportInfo ) {
49
49
return ;
50
50
}
51
51
52
- const messageStaticValue = getStaticValue ( reportInfo . message , context . getScope ( ) ) ;
53
- if (
54
- (
55
- ( reportInfo . message . type === 'Literal' && typeof reportInfo . message . value === 'string' ) ||
56
- ( messageStaticValue && typeof messageStaticValue . value === 'string' )
57
- ) &&
58
- reportInfo . data &&
59
- reportInfo . data . type === 'ObjectExpression'
60
- ) {
61
- const message = reportInfo . message . value || messageStaticValue . value ;
62
- // https://github.com/eslint/eslint/blob/2874d75ed8decf363006db25aac2d5f8991bd969/lib/linter.js#L986
63
- const PLACEHOLDER_MATCHER = / { { \s * ( [ ^ { } ] + ?) \s * } } / g;
64
- const placeholdersInMessage = new Set ( ) ;
52
+ const reportMessagesAndDataArray = utils . collectReportViolationAndSuggestionData ( reportInfo ) . filter ( obj => obj . message ) ;
53
+ for ( const { message, data } of reportMessagesAndDataArray ) {
54
+ const messageStaticValue = getStaticValue ( message , context . getScope ( ) ) ;
55
+ if (
56
+ (
57
+ ( message . type === 'Literal' && typeof message . value === 'string' ) ||
58
+ ( messageStaticValue && typeof messageStaticValue . value === 'string' )
59
+ ) &&
60
+ data &&
61
+ data . type === 'ObjectExpression'
62
+ ) {
63
+ const messageValue = message . value || messageStaticValue . value ;
64
+ // https://github.com/eslint/eslint/blob/2874d75ed8decf363006db25aac2d5f8991bd969/lib/linter.js#L986
65
+ const PLACEHOLDER_MATCHER = / { { \s * ( [ ^ { } ] + ?) \s * } } / g;
66
+ const placeholdersInMessage = new Set ( ) ;
65
67
66
- message . replace ( PLACEHOLDER_MATCHER , ( fullMatch , term ) => {
67
- placeholdersInMessage . add ( term ) ;
68
- } ) ;
68
+ messageValue . replace ( PLACEHOLDER_MATCHER , ( fullMatch , term ) => {
69
+ placeholdersInMessage . add ( term ) ;
70
+ } ) ;
69
71
70
- reportInfo . data . properties . forEach ( prop => {
71
- const key = utils . getKeyName ( prop ) ;
72
- if ( ! placeholdersInMessage . has ( key ) ) {
73
- context . report ( {
74
- node : reportInfo . message ,
75
- messageId : 'placeholderUnused' ,
76
- data : { unusedKey : key } ,
77
- } ) ;
78
- }
79
- } ) ;
72
+ data . properties . forEach ( prop => {
73
+ const key = utils . getKeyName ( prop ) ;
74
+ if ( ! placeholdersInMessage . has ( key ) ) {
75
+ context . report ( {
76
+ node : message ,
77
+ messageId : 'placeholderUnused' ,
78
+ data : { unusedKey : key } ,
79
+ } ) ;
80
+ }
81
+ } ) ;
82
+ }
80
83
}
81
84
}
82
85
} ,
0 commit comments