file author sigmaliu
  import { execSync } from 'child_process' ; import AutoFixAPI from '../libs/eslilnt-autofix-api' ; import { unknown , fileFilter , getAuthAndEmailMapping , log , globToFiles , } from '../utils/utils' ; let authEmailMapping = { } ; export default function fixFilesByAuth ( args ) { const autoFixAPI = new AutoFixAPI ( ) ; ( async ( ) => { let files = await globToFiles ( args ) ; files = fileFilter ( files ) ; while ( true ) { const { report , auther } = autoFixAPI . getESLintReportByAuth ( files ) ; if ( ! report ) { break ; } if ( ! ( report . fixableErrorCount + report . fixableWarningCount > 0 ) ) { break ; } const { results } = report ; const nextTasks = results . filter ( ( res ) => ( res . fixableErrorCount + res . fixableWarningCount ) > 0 ) ; const nextFiles = nextTasks . map ( ( task ) => task . filePath ) ; if ( ! nextTasks . length ) { break ; } autoFixAPI . applyAutoFixByReport ( report ) ; let email = authEmailMapping [ auther ] || '' ; if ( ! email ) { for ( const nextFile of nextFiles ) { authEmailMapping = Object . assign ( authEmailMapping , getAuthAndEmailMapping ( nextFile ) ) ; email = authEmailMapping [ auther ] ; if ( email ) { break ; } } } const fileAdd = `git add ${ files . join ( ' ' ) }` ; let fileCommit = `git commit -m "style: autofix for ${ auther } by alloylint" --author="${ auther } ${ email }"` ; if ( auther === unknown ) { fileCommit = 'git commit -m "style: autofix by alloylint"' ; } execSync ( `${ fileAdd } && ${ fileCommit }` ) ; files = nextFiles ; } log ( 'autofix done' ) ; } ) ( ) ; }