Skip to content

Commit 5663ee5

Browse files
committed
fix(format): ESLint doesn't always provide an endLine
1 parent 6d23a79 commit 5663ee5

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

src/formatters/git-log.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,28 @@ export const createGitLogFormatter: CreateGitLogFormatter = (config) => {
119119
return results.reduce((output, { filePath, messages }) => {
120120
if (messages.length > 0) {
121121
output += `\n${styledFilePath(filePath)}\n`;
122-
messages.forEach(
123-
({ ruleId, severity, message, line, column, endLine }) => {
124-
const command = `git blame --date=relative --show-email -L ${line},${endLine} ${filePath}`;
125-
const blame = execSync(command, { encoding: 'utf8' });
126-
const rawLocation = `${line}:${column}`;
127-
const status = severity === 1 ? WARNING : ERROR;
128-
const commitMatch = blame.match(/^[^ ]+/) || [''];
129-
const dateMatch = blame.match(/> (.+ ago)/) || ['', ''];
130-
const emailMatch = blame.match(/<([^>]+)>/) || ['', ''];
131-
const rightAlignLocations = ' '.repeat(
132-
locationColumnWidth - rawLocation.length,
133-
);
134-
const leftAlignCommitsWithStatuses = ' '.repeat(
135-
rightAlignLocations.length + rawLocation.length + gutter.length,
136-
);
137-
const location = styledLocation(rawLocation);
138-
const rule = ruleId ? styledRule(ruleId) : '';
139-
const commit = styledCommit(`${commitMatch[0]}`);
140-
const date = styledDate(`(${dateMatch[1].trim()})`);
141-
const email = styledEmail(`<${emailMatch[1]}>`);
142-
output += `${rightAlignLocations}${location}${gutter}${status}${gutter}${message}${gutter}${rule}\n`;
143-
output += `${leftAlignCommitsWithStatuses}${commit} ${email} ${date}\n`;
144-
},
145-
);
122+
messages.forEach(({ ruleId, severity, message, line, column }) => {
123+
const command = `git blame --date=relative --show-email -L ${line},${line} -- "${filePath}"`;
124+
const blame = execSync(command, { encoding: 'utf8' });
125+
const rawLocation = `${line}:${column}`;
126+
const status = severity === 1 ? WARNING : ERROR;
127+
const commitMatch = blame.match(/^[^ ]+/) || [''];
128+
const dateMatch = blame.match(/> (.+ ago)/) || ['', ''];
129+
const emailMatch = blame.match(/<([^>]+)>/) || ['', ''];
130+
const rightAlignLocations = ' '.repeat(
131+
locationColumnWidth - rawLocation.length,
132+
);
133+
const leftAlignCommitsWithStatuses = ' '.repeat(
134+
rightAlignLocations.length + rawLocation.length + gutter.length,
135+
);
136+
const location = styledLocation(rawLocation);
137+
const rule = ruleId ? styledRule(ruleId) : '';
138+
const commit = styledCommit(`${commitMatch[0]}`);
139+
const date = styledDate(`(${dateMatch[1].trim()})`);
140+
const email = styledEmail(`<${emailMatch[1]}>`);
141+
output += `${rightAlignLocations}${location}${gutter}${status}${gutter}${message}${gutter}${rule}\n`;
142+
output += `${leftAlignCommitsWithStatuses}${commit} ${email} ${date}\n`;
143+
});
146144
}
147145
return output;
148146
}, '');

0 commit comments

Comments
 (0)