@@ -377,7 +377,9 @@ impl DisableDirectivesBuilder {
377377 // `eslint-disable`
378378 if text. trim ( ) . is_empty ( ) {
379379 if self . disable_all_start . is_none ( ) {
380- self . disable_all_start = Some ( ( comment_span. end , comment_span) ) ;
380+ // Start coverage at the beginning of the directive comment so
381+ // top-of-file headers can suppress file-start diagnostics.
382+ self . disable_all_start = Some ( ( comment. span . start , comment_span) ) ;
381383 }
382384 self . disable_rule_comments . push ( DisableRuleComment {
383385 span : comment_span,
@@ -493,7 +495,7 @@ impl DisableDirectivesBuilder {
493495 let mut rules = vec ! [ ] ;
494496 Self :: get_rule_names ( text, rule_name_start, |rule_name, name_span| {
495497 self . disable_start_map . entry ( rule_name. to_string ( ) ) . or_insert ( (
496- comment_span . end ,
498+ comment . span . start ,
497499 name_span,
498500 comment_span,
499501 ) ) ;
@@ -1391,4 +1393,20 @@ function test() {
13911393 "eslint-disable-next-line should NOT suppress diagnostics on lines after the next line"
13921394 ) ;
13931395 }
1396+
1397+ #[ test]
1398+ fn test_disable_file_header_suppresses_file_start_diagnostic ( ) {
1399+ test_directives (
1400+ |prefix| {
1401+ format ! (
1402+ "/* {prefix}-disable no-console */\n console.log('still disabled by header');\n "
1403+ )
1404+ } ,
1405+ |_, directives| {
1406+ // Some rules report at file start (line 1, column 0), e.g. Program-level diagnostics.
1407+ // A header disable should still suppress those diagnostics.
1408+ assert ! ( directives. contains( "no-console" , Span :: new( 0 , 1 ) ) ) ;
1409+ } ,
1410+ ) ;
1411+ }
13941412}
0 commit comments