@@ -4,7 +4,7 @@ const spawn = require('child_process').spawnSync;
44const path = require ( 'path' ) ;
55
66const filesToCheck = [ '*.h' , '*.cc' ] ;
7- const CLANG_FORMAT_START = process . env . CLANG_FORMAT_START || 'main' ;
7+ const FORMAT_START = process . env . FORMAT_START || 'main' ;
88
99function main ( args ) {
1010 let fix = false ;
@@ -22,19 +22,17 @@ function main (args) {
2222 const clangFormatPath = path . dirname ( require . resolve ( 'clang-format' ) ) ;
2323 const options = [ '--binary=node_modules/.bin/clang-format' , '--style=file' ] ;
2424 if ( fix ) {
25- options . push ( CLANG_FORMAT_START ) ;
25+ options . push ( FORMAT_START ) ;
2626 } else {
27- options . push ( '--diff' , CLANG_FORMAT_START ) ;
27+ options . push ( '--diff' , FORMAT_START ) ;
2828 }
2929
30- const gitClangFormatPath = path . join ( clangFormatPath ,
31- 'bin/git-clang-format' ) ;
32- const result = spawn ( 'python' , [
33- gitClangFormatPath ,
34- ...options ,
35- '--' ,
36- ...filesToCheck
37- ] , { encoding : 'utf-8' } ) ;
30+ const gitClangFormatPath = path . join ( clangFormatPath , 'bin/git-clang-format' ) ;
31+ const result = spawn (
32+ 'python' ,
33+ [ gitClangFormatPath , ...options , '--' , ...filesToCheck ] ,
34+ { encoding : 'utf-8' }
35+ ) ;
3836
3937 if ( result . stderr ) {
4038 console . error ( 'Error running git-clang-format:' , result . stderr ) ;
@@ -48,17 +46,19 @@ function main (args) {
4846 return 0 ;
4947 }
5048 // Detect if there is any complains from clang-format
51- if ( clangFormatOutput !== '' &&
52- clangFormatOutput !== ( 'no modified files to format' ) &&
53- clangFormatOutput !== ( 'clang-format did not modify any files' ) ) {
49+ if (
50+ clangFormatOutput !== '' &&
51+ clangFormatOutput !== 'no modified files to format' &&
52+ clangFormatOutput !== 'clang-format did not modify any files'
53+ ) {
5454 console . error ( clangFormatOutput ) ;
5555 const fixCmd = 'npm run lint:fix' ;
5656 console . error ( `
5757 ERROR: please run "${ fixCmd } " to format changes in your commit
5858 Note that when running the command locally, please keep your local
5959 main branch and working branch up to date with nodejs/node-addon-api
6060 to exclude un-related complains.
61- Or you can run "env CLANG_FORMAT_START =upstream/main ${ fixCmd } ".` ) ;
61+ Or you can run "env FORMAT_START =upstream/main ${ fixCmd } ".` ) ;
6262 return 1 ;
6363 }
6464}
0 commit comments