@@ -37,7 +37,7 @@ const ALLOW_OPTIONS = Object.freeze([
3737 * Folds test items to `{valid: [], invalid: []}`.
3838 * One item would be converted to 4 valid patterns and 8 invalid patterns.
3939 * @param {{valid: Object[], invalid: Object[]} } patterns The result.
40- * @param {{code: string, message : string, allow: string|string[]} } item A test item.
40+ * @param {{code: string, messageId : string, allow: string|string[]} } item A test item.
4141 * @returns {{valid: Object[], invalid: Object[]} } The result.
4242 */
4343function toValidInvalid ( patterns , item ) {
@@ -69,23 +69,42 @@ function toValidInvalid(patterns, item) {
6969 } ) ) ,
7070 ) ;
7171
72- const error = item . message || {
73- messageId : item . messageId ,
74- data : item . data ,
75- } ;
76-
7772 // Invalid Patterns.
7873 patterns . invalid . push ( {
7974 code : item . code ,
80- errors : [ error ] ,
75+ errors : [
76+ {
77+ messageId : item . messageId ,
78+ data : item . data ,
79+ suggestions : [
80+ {
81+ messageId : "suggestComment" ,
82+ data : item . data ,
83+ output : item . code . replace ( "{}" , "{ /* empty */ }" ) ,
84+ } ,
85+ ] ,
86+ } ,
87+ ] ,
8188 languageOptions : { ecmaVersion } ,
8289 } ) ;
8390 ALLOW_OPTIONS . filter ( allow => ! allowOptions . includes ( allow ) ) . forEach (
8491 allow => {
8592 // non related "allow" option has no effect.
8693 patterns . invalid . push ( {
8794 code : `${ item . code } // allow: ${ allow } ` ,
88- errors : [ error ] ,
95+ errors : [
96+ {
97+ messageId : item . messageId ,
98+ data : item . data ,
99+ suggestions : [
100+ {
101+ messageId : "suggestComment" ,
102+ data : item . data ,
103+ output : `${ item . code . replace ( "{}" , "{ /* empty */ }" ) } // allow: ${ allow } ` ,
104+ } ,
105+ ] ,
106+ } ,
107+ ] ,
89108 options : [ { allow : [ allow ] } ] ,
90109 languageOptions : { ecmaVersion } ,
91110 } ) ;
@@ -333,6 +352,13 @@ ruleTester.run(
333352 column : 16 ,
334353 endLine : 1 ,
335354 endColumn : 18 ,
355+ suggestions : [
356+ {
357+ messageId : "suggestComment" ,
358+ data : { name : "function 'foo'" } ,
359+ output : "function foo() { /* empty */ }" ,
360+ } ,
361+ ] ,
336362 } ,
337363 ] ,
338364 } ,
@@ -346,6 +372,13 @@ ruleTester.run(
346372 column : 23 ,
347373 endLine : 2 ,
348374 endColumn : 2 ,
375+ suggestions : [
376+ {
377+ messageId : "suggestComment" ,
378+ data : { name : "function" } ,
379+ output : "var foo = function () { /* empty */ }" ,
380+ } ,
381+ ] ,
349382 } ,
350383 ] ,
351384 } ,
@@ -360,6 +393,13 @@ ruleTester.run(
360393 column : 17 ,
361394 endLine : 3 ,
362395 endColumn : 4 ,
396+ suggestions : [
397+ {
398+ messageId : "suggestComment" ,
399+ data : { name : "arrow function" } ,
400+ output : "var foo = () => { /* empty */ }" ,
401+ } ,
402+ ] ,
363403 } ,
364404 ] ,
365405 } ,
@@ -374,6 +414,13 @@ ruleTester.run(
374414 column : 8 ,
375415 endLine : 3 ,
376416 endColumn : 3 ,
417+ suggestions : [
418+ {
419+ messageId : "suggestComment" ,
420+ data : { name : "method 'foo'" } ,
421+ output : "var obj = {\n\tfoo() { /* empty */ }\n}" ,
422+ } ,
423+ ] ,
377424 } ,
378425 ] ,
379426 } ,
@@ -388,6 +435,13 @@ ruleTester.run(
388435 column : 17 ,
389436 endLine : 1 ,
390437 endColumn : 20 ,
438+ suggestions : [
439+ {
440+ messageId : "suggestComment" ,
441+ data : { name : "method 'foo'" } ,
442+ output : "class A { foo() { /* empty */ } }" ,
443+ } ,
444+ ] ,
391445 } ,
392446 ] ,
393447 } ,
0 commit comments