Skip to content

Commit 019c35a

Browse files
committed
Merge branch 'release/2.0.0-alpha.1'
2 parents 9a06b42 + 903e702 commit 019c35a

File tree

6 files changed

+65
-7
lines changed

6 files changed

+65
-7
lines changed

.github/workflows/tests.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
pull_request:
9+
10+
jobs:
11+
unit:
12+
runs-on: macos-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 20
18+
cache: npm
19+
- name: Install modules
20+
run: npm install
21+
- name: Run tests
22+
run: npm run test -- --coverage

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## v2.0.0-alpha.1 - 2024.04.16
10+
11+
### Added
12+
13+
- Add support for both `-c` or `-l` flag from the Prettier command ([741f555](https://github.com/studiometa/prettier-formatter-gitlab/commit/741f555))
14+
915
## v2.0.0-alpha.0 - 2024.04.15
1016

1117
### Changed

package-lock.json

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

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@studiometa/prettier-formatter-gitlab",
3-
"version": "2.0.0-alpha.0",
3+
"version": "2.0.0-alpha.1",
44
"description": "A Prettier formatter for the GitLab Code Quality report",
55
"main": "src/index.js",
66
"type": "module",

src/index.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const {
1111
CI_CONFIG_PATH = '.gitlab-ci.yml',
1212
CI_JOB_NAME,
1313
CI_PROJECT_DIR = cwd(),
14-
PRETTIER_CODE_QUALITY_REPORT,
1514
} = env;
1615

1716
/**
@@ -39,9 +38,14 @@ function getOutputPath() {
3938
*/
4039
function parse(results) {
4140
return results
42-
.toString()
4341
.split('\n')
44-
.filter((line) => line);
42+
.filter(
43+
(line) =>
44+
Boolean(line) &&
45+
!line.startsWith('Checking formatting...') &&
46+
!line.includes('Code style issues found'),
47+
)
48+
.map((line) => line.replace('[warn] ', ''));
4549
}
4650

4751
/**
@@ -50,6 +54,7 @@ function parse(results) {
5054
* @returns {Promise<void>}
5155
*/
5256
export async function prettierFormatterGitLab(results) {
57+
const { PRETTIER_CODE_QUALITY_REPORT } = env;
5358
if (CI_JOB_NAME || PRETTIER_CODE_QUALITY_REPORT) {
5459
const files = parse(results);
5560

test/cli.spec.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { describe, it, expect, afterEach } from 'bun:test';
1+
import { describe, it, expect, afterEach, spyOn } from 'bun:test';
22
import { existsSync, unlinkSync, readFileSync } from 'node:fs';
33
import { execSync } from 'node:child_process';
4+
import { prettierFormatterGitLab } from '../src/index.js';
45

56
const CODE_QUALITY_FILENAME = 'gl-prettier-codequality.json';
67

@@ -24,4 +25,28 @@ describe('prettier-formatter-gitlab cli', () => {
2425
const content = readFileSync(CODE_QUALITY_FILENAME);
2526
expect(content.toString()).toMatchSnapshot();
2627
});
28+
29+
it('should work with the `-c` or `-l` flag', async () => {
30+
const consoleSpy = spyOn(console, 'log');
31+
consoleSpy.mockImplementation(() => null);
32+
process.env.PRETTIER_CODE_QUALITY_REPORT = CODE_QUALITY_FILENAME;
33+
34+
// prettier -c path/to/folder/
35+
const outputCheck = `Checking formatting...
36+
[warn] test/dirty-2.js
37+
[warn] test/dirty.js
38+
[warn] Code style issues found in 3 files. Run Prettier to fix.
39+
`;
40+
41+
// prettier -l path/to/folder/
42+
const outputList = `test/dirty-2.js
43+
test/dirty.js
44+
`;
45+
46+
await prettierFormatterGitLab(outputCheck);
47+
await prettierFormatterGitLab(outputList);
48+
expect(consoleSpy).toHaveBeenCalledTimes(12);
49+
expect(consoleSpy.mock.calls.slice(0, 6)).toEqual(consoleSpy.mock.calls.slice(6, 12));
50+
consoleSpy.mockRestore();
51+
});
2752
});

0 commit comments

Comments
 (0)