Skip to content

Commit

Permalink
fix(format): ESLint doesn't always provide an endLine
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMason committed Aug 3, 2019
1 parent 6d23a79 commit 5663ee5
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/formatters/git-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,30 +119,28 @@ export const createGitLogFormatter: CreateGitLogFormatter = (config) => {
return results.reduce((output, { filePath, messages }) => {
if (messages.length > 0) {
output += `\n${styledFilePath(filePath)}\n`;
messages.forEach(
({ ruleId, severity, message, line, column, endLine }) => {
const command = `git blame --date=relative --show-email -L ${line},${endLine} ${filePath}`;
const blame = execSync(command, { encoding: 'utf8' });
const rawLocation = `${line}:${column}`;
const status = severity === 1 ? WARNING : ERROR;
const commitMatch = blame.match(/^[^ ]+/) || [''];
const dateMatch = blame.match(/> (.+ ago)/) || ['', ''];
const emailMatch = blame.match(/<([^>]+)>/) || ['', ''];
const rightAlignLocations = ' '.repeat(
locationColumnWidth - rawLocation.length,
);
const leftAlignCommitsWithStatuses = ' '.repeat(
rightAlignLocations.length + rawLocation.length + gutter.length,
);
const location = styledLocation(rawLocation);
const rule = ruleId ? styledRule(ruleId) : '';
const commit = styledCommit(`${commitMatch[0]}`);
const date = styledDate(`(${dateMatch[1].trim()})`);
const email = styledEmail(`<${emailMatch[1]}>`);
output += `${rightAlignLocations}${location}${gutter}${status}${gutter}${message}${gutter}${rule}\n`;
output += `${leftAlignCommitsWithStatuses}${commit} ${email} ${date}\n`;
},
);
messages.forEach(({ ruleId, severity, message, line, column }) => {
const command = `git blame --date=relative --show-email -L ${line},${line} -- "${filePath}"`;
const blame = execSync(command, { encoding: 'utf8' });
const rawLocation = `${line}:${column}`;
const status = severity === 1 ? WARNING : ERROR;
const commitMatch = blame.match(/^[^ ]+/) || [''];
const dateMatch = blame.match(/> (.+ ago)/) || ['', ''];
const emailMatch = blame.match(/<([^>]+)>/) || ['', ''];
const rightAlignLocations = ' '.repeat(
locationColumnWidth - rawLocation.length,
);
const leftAlignCommitsWithStatuses = ' '.repeat(
rightAlignLocations.length + rawLocation.length + gutter.length,
);
const location = styledLocation(rawLocation);
const rule = ruleId ? styledRule(ruleId) : '';
const commit = styledCommit(`${commitMatch[0]}`);
const date = styledDate(`(${dateMatch[1].trim()})`);
const email = styledEmail(`<${emailMatch[1]}>`);
output += `${rightAlignLocations}${location}${gutter}${status}${gutter}${message}${gutter}${rule}\n`;
output += `${leftAlignCommitsWithStatuses}${commit} ${email} ${date}\n`;
});
}
return output;
}, '');
Expand Down

0 comments on commit 5663ee5

Please sign in to comment.