@@ -17,24 +17,34 @@ pub fn check_copyright(path: &Path, fix: bool) -> anyhow::Result<()> {
1717 . and_then ( |e| e. to_str ( ) )
1818 . unwrap_or_default ( ) ;
1919
20- if !matches ! ( ext, "rs" | "c" | "proto" | "toml" | "ts" | "js" | "py" | "ps1" | "config" ) {
20+ if !matches ! (
21+ ext,
22+ "rs" | "c" | "proto" | "toml" | "ts" | "js" | "py" | "ps1" | "config"
23+ ) {
2124 return Ok ( ( ) ) ;
2225 }
2326
2427 let f = BufReader :: new ( File :: open ( path) ?) ;
2528 let mut lines = f. lines ( ) ;
26- let first_line = lines. next ( ) . unwrap_or ( Ok ( String :: new ( ) ) ) ?;
27- let second_line = lines. next ( ) . unwrap_or ( Ok ( String :: new ( ) ) ) ?;
28- let third_line = lines. next ( ) . unwrap_or ( Ok ( String :: new ( ) ) ) ?;
29+ let first_content_line = {
30+ let line = lines. next ( ) . unwrap_or ( Ok ( String :: new ( ) ) ) ?;
31+ if line. starts_with ( "#!" ) {
32+ lines. next ( ) . unwrap_or ( Ok ( String :: new ( ) ) ) ?
33+ } else {
34+ line
35+ }
36+ } ;
37+ let second_content_line = lines. next ( ) . unwrap_or ( Ok ( String :: new ( ) ) ) ?;
38+ let third_content_line = lines. next ( ) . unwrap_or ( Ok ( String :: new ( ) ) ) ?;
2939
3040 // Preserve any files which are copyright, but not by Microsoft.
31- if first_line . contains ( "Copyright" ) && !first_line . contains ( "Microsoft" ) {
41+ if first_content_line . contains ( "Copyright" ) && !first_content_line . contains ( "Microsoft" ) {
3242 return Ok ( ( ) ) ;
3343 }
3444
35- let mut missing_banner =
36- !first_line . contains ( HEADER_MIT_FIRST ) || !second_line . contains ( HEADER_MIT_SECOND ) ;
37- let mut missing_blank_line = !third_line . is_empty ( ) ;
45+ let mut missing_banner = !first_content_line . contains ( HEADER_MIT_FIRST )
46+ || !second_content_line . contains ( HEADER_MIT_SECOND ) ;
47+ let mut missing_blank_line = !third_content_line . is_empty ( ) ;
3848
3949 // TEMP: until we have more robust infrastructure for distinct
4050 // microsoft-internal checks, include this "escape hatch" for preserving
@@ -44,8 +54,9 @@ pub fn check_copyright(path: &Path, fix: bool) -> anyhow::Result<()> {
4454 let is_msft_internal = std:: env:: var ( "XTASK_FMT_COPYRIGHT_ALLOW_MISSING_MIT" ) . is_ok ( ) ;
4555 if is_msft_internal {
4656 // support both new and existing copyright banner styles
47- missing_banner = !( first_line. contains ( "Copyright" ) && first_line. contains ( "Microsoft" ) ) ;
48- missing_blank_line = !second_line. is_empty ( ) ;
57+ missing_banner =
58+ !( first_content_line. contains ( "Copyright" ) && first_content_line. contains ( "Microsoft" ) ) ;
59+ missing_blank_line = !second_content_line. is_empty ( ) ;
4960 }
5061
5162 if fix {
0 commit comments