Skip to content

Commit 9e6e08b

Browse files
committed
Merge branch 'release/1.1.0' into master
2 parents 0c72f88 + 654cb69 commit 9e6e08b

File tree

10 files changed

+337
-109
lines changed

10 files changed

+337
-109
lines changed

bin/cli.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ const prettierFormatterGitlab = require('../src/index.js');
44

55
const [, , cmd] = process.argv;
66

7-
exec(cmd, (error) => {
7+
exec(cmd, async (error) => {
88
if (error) {
9-
prettierFormatterGitlab(error);
10-
console.log(error.toString());
9+
await prettierFormatterGitlab(error);
1110
process.exit(1);
1211
}
1312
});

package-lock.json

+107-72
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@studiometa/prettier-formatter-gitlab",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "A Prettier formatter for the GitLab Code Quality report",
55
"main": "src/index.js",
66
"bin": {
@@ -35,10 +35,13 @@
3535
"@studiometa/eslint-config": "^2.1.3",
3636
"@studiometa/prettier-config": "^2.0.1",
3737
"eslint": "^7.11.0",
38-
"jest": "^26.6.0",
39-
"prettier": "^2.1.2"
38+
"jest": "^26.6.0"
4039
},
4140
"dependencies": {
42-
"js-yaml": "^3.14.0"
41+
"chalk": "^4.1.0",
42+
"jest-diff": "^26.6.2",
43+
"js-yaml": "^3.14.0",
44+
"prettier-linter-helpers": "^1.0.0",
45+
"prettier": "^2.2.0"
4346
}
4447
}

src/formatters/diff.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const chalk = require('chalk');
2+
const { diffStringsUnified } = require('jest-diff');
3+
const getFileInfo = require('../utils/get-file-info.js');
4+
5+
/**
6+
* Format Prettier formatting errors in diff format.
7+
* @param {Object} { filename, input, output } A file Prettier informations.
8+
*/
9+
function formatDiff({ filename, input, output }) {
10+
console.log(`----------------------------------------------------
11+
${filename}
12+
----------------------------------------------------`);
13+
console.log(
14+
diffStringsUnified(input || '', output || '', {
15+
aColor: chalk.red,
16+
bColor: chalk.green,
17+
omitAnnotationLines: true,
18+
contextLines: 2,
19+
expand: false,
20+
})
21+
);
22+
console.log('');
23+
}
24+
25+
module.exports = async (files) => {
26+
const infos = await Promise.all(files.map(getFileInfo));
27+
infos.forEach(formatDiff);
28+
};

0 commit comments

Comments
 (0)