You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//Exit code 0 if inputs are the same, 1 if different, 2 if trouble.
if(diffProc.code!==0&&diffProc.code!==1){
thrownewError(diffProc.stderr);
}
return{
file,
diff: diffProc.stdout,
};
}
functionextractRangeInformation(range){
//eg;
// @@ -54 +54,2 @@
// @@ -1,3 +1,9 @@
constregex=/^@@[-+](\d+,?\d+)[-+](\d+,?\d+)@@$/;
constmatch=regex.exec(range);
if(match){
constoriginal=match[1].split(',');
constupdated=match[2].split(',');
return{
original: {
line: parseInt(original[0],10),
lineCount: parseInt(original[1],10)||1,
},
updated: {
line: parseInt(updated[0],10),
lineCount: parseInt(updated[1],10)||1,
},
};
}
}
functionparseChanges(file,diff){
letgroup=null;
constgroups=[];
diff.split('\n').forEach(line=>{
constrange=extractRangeInformation(line);
if(range){
group={
range,
description: [line],
};
groups.push(group);
}elseif(group){
group.description.push(line);
}
});
returngroups.map(x=>({
file,
line: x.range.original.line,
lineCount: x.range.original.lineCount,
description: x.description.join('\n'),
}));
}
asyncfunctionmain(){
const{argv}=yargs
.scriptName('lint-java')
.usage('Usage: $0 [options]')
.command(
'$0',
'Downloads the google-java-format package and reformats Java source code to comply with Google Java Style.\n\nSee https://github.com/google/google-java-format',
)
.option('check',{
type: 'boolean',
description:
'Outputs a list of files with lint violations.\nExit code is set to 1 if there are violations, otherwise 0.\nDoes not reformat lint issues.',
})
.option('diff',{
type: 'boolean',
description:
'Outputs a diff of the lint fix changes in json format.\nDoes not reformat lint issues.',