Skip to content

Commit 8be19c1

Browse files
Update prettier support to be more portable (#783)
* Update prettier support to be more portable * Update .gitignore * Enforce lf when possible and use auto otherwise * Use npx to run node commands * Set indent_size to 2 for md files * Fix js and css linting configuration * Fix unit test CRLF support
1 parent c550b22 commit 8be19c1

File tree

9 files changed

+35
-14
lines changed

9 files changed

+35
-14
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
indent_size = 2
14+
15+
[*.{js,css}]
16+
indent_size = 2

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Auto detect text files and perform LF normalization
2-
* text=auto
2+
* text=auto eol=lf

.github/workflows/prettier.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
uses: actions/checkout@v3
2929

3030
- name: Install prettier and plugin-php
31-
run: npm install --global [email protected] @prettier/[email protected]
31+
run: npm i
3232

3333
- name: Lint with Prettier
3434
continue-on-error: true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ package-lock.json
1212

1313
# Environment
1414
.env
15+
.php-version
1516
DOCKER_ENV
1617
docker_tag
1718

1819
# IDE
1920
.vscode/
20-
.idea/
21+
.idea/

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
vendor
2+
**/*.min.js

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"printWidth": 120,
3+
"endOfLine": "auto"
4+
}

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"php -S localhost:8000 -t src"
3232
],
3333
"test": "./vendor/bin/phpunit --testdox tests",
34-
"lint": "prettier --check *.md **/*.{php,md,js,css} !**/*.min.js --print-width 120",
35-
"lint-fix": "prettier --write *.md **/*.{php,md,js,css} !**/*.min.js --print-width 120"
34+
"lint": "npx prettier --check *.md **/*.{php,md,js,css}",
35+
"lint-fix": "npx prettier --write *.md **/*.{php,md,js,css}"
3636
}
3737
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"node": "18.x"
44
},
55
"devDependencies": {
6-
"@prettier/plugin-php": "^0.18.8",
7-
"prettier": "^2.6.2"
6+
"@prettier/plugin-php": "^0.18.9",
7+
"prettier": "^2.8.1"
88
}
99
}

tests/RenderTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,13 @@ public function testFirstAndThirdColumnsSwappedWhenDirectionIsRtl(): void
261261
{
262262
$this->testParams["locale"] = "he";
263263
$render = generateOutput($this->testStats, $this->testParams)["body"];
264-
$renderCollapsedSpaces = preg_replace("/(\s)\s*/", '$1', $render);
265-
$this->assertStringContainsString(
266-
"<!-- Total Contributions big number -->\n<g transform='translate(412.5, 48)'>",
267-
$renderCollapsedSpaces
264+
$this->assertMatchesRegularExpression(
265+
"/<!-- Total Contributions big number -->\\s*<g transform='translate\\(412\\.5, 48\\)'>/",
266+
$render
268267
);
269-
$this->assertStringContainsString(
270-
"<!-- Longest Streak big number -->\n<g transform='translate(82.5, 48)'>",
271-
$renderCollapsedSpaces
268+
$this->assertMatchesRegularExpression(
269+
"/<!-- Longest Streak big number -->\\s*<g transform='translate\\(82\\.5, 48\\)'>/",
270+
$render
272271
);
273272
}
274273

0 commit comments

Comments
 (0)