Skip to content

Commit f9c89c8

Browse files
committed
Add prettier for basic formatting lints compatible with .editorconfig
1 parent c936270 commit f9c89c8

File tree

10 files changed

+1966
-16
lines changed

10 files changed

+1966
-16
lines changed

.editorconfig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ root = true
55
[*]
66
charset = utf-8
77
end_of_line = lf
8-
# insert_final_newline = true
9-
# trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
1010

1111
[manifest/**.{json,xml}]
1212
indent_size = 4
13-
insert_final_newline = true
14-
trim_trailing_whitespace = true

.github/workflows/prettier.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: prettier
2+
permissions:
3+
contents: read
4+
pull-requests: write
5+
6+
on:
7+
push:
8+
branches:
9+
- 'master'
10+
- 'main'
11+
- 'release/*'
12+
- 'feature/*'
13+
- 'CBG*'
14+
- 'ci-*'
15+
pull_request:
16+
branches:
17+
- 'master'
18+
- 'main'
19+
- 'release/*'
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
23+
cancel-in-progress: ${{ !contains(github.ref, 'release/')}}
24+
25+
26+
jobs:
27+
prettier:
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
- name: Prettier validation
34+
uses: creyD/[email protected]
35+
with:
36+
dry: True
37+
- name: Find Comment
38+
if: failure() && github.event_name == 'pull_request'
39+
uses: peter-evans/find-comment@v3
40+
id: fc
41+
with:
42+
issue-number: ${{ github.event.pull_request.number }}
43+
comment-author: 'github-actions[bot]'
44+
body-includes: Prettier Formatting Validation
45+
- name: Create or update comment
46+
if: failure() && github.event_name == 'pull_request'
47+
uses: peter-evans/create-or-update-comment@v4
48+
with:
49+
comment-id: ${{ steps.fc.outputs.comment-id }}
50+
issue-number: ${{ github.event.pull_request.number }}
51+
edit-mode: replace
52+
body: |
53+
## Prettier Formatting Validation
54+
55+
The Prettier formatting check has identified files that do not conform to the project's coding style guidelines.
56+
57+
To automatically format locally, run:
58+
59+
```sh
60+
npm install
61+
prettier --write .
62+
```

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
*.idea
22
*.sublime-workspace
3-
*.walrus
43
**/git_info.go.bak
54
\#*
65
*~
@@ -10,14 +9,19 @@
109
/pkg
1110
*.exe
1211
*.iml
12+
__pycache__
13+
node_modules/
14+
15+
*.pb.gz
16+
*.walrus
17+
1318
sg_config.json
1419
coverage*.out
1520
coverage*.xml
1621
verbose*.out*
1722
verbose*.xml
23+
1824
sync_gateway
19-
*.pb.gz
20-
__pycache__
2125
tools/cache_perf_tool/cache_perf_tool
2226
cache_perf_tool
2327
tools/stats-definition-exporter/stats-definition-exporter

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# prettier barfs on `<?xml` in these files for some reason
2+
*.wxs
3+
4+
# The `db/functions/*.js` file is not strictly valid JS syntax - depends on Go embed and variable substitution to become valid
5+
*.fmt.js
6+
7+
go.mod
8+
go.sum

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"trailingComma": "es5",
3+
"singleQuote": true,
4+
"plugins": ["@prettier/plugin-xml"]
5+
}

db/functions/js_runner.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ const kUserFunctionCacheSize = 2
3535
// Maximum nesting of JS user function calls (not the JS stack depth)
3636
var kUserFunctionMaxCallDepth = 20
3737

38-
// The outermost JavaScript code. Evaluating it returns a function, which is then called by the
39-
// Runner every time it's invoked. Contains `%s` where the actual function source code goes.
38+
// kJavaScriptWrapperFormatString is the format string containing the outermost JavaScript code.
39+
// Evaluating it returns a function, which is then called by the runner every time it's invoked.
4040
//
41-
//go:embed js_wrapper.js
42-
var kJavaScriptWrapper string
41+
// Contains `%s` where the actual function source code goes.
42+
//
43+
//go:embed js_wrapper.fmt.js
44+
var kJavaScriptWrapperFormatString string
4345

4446
// Creates a JSServer instance wrapping a userJSRunner, for user JS functions.
4547
func newFunctionJSServer(ctx context.Context, name string, what string, sourceCode string) (*sgbucket.JSServer, error) {
46-
js := fmt.Sprintf(kJavaScriptWrapper, sourceCode)
48+
js := fmt.Sprintf(kJavaScriptWrapperFormatString, sourceCode)
4749
jsServer := sgbucket.NewJSServer(ctx, js, 0, kUserFunctionCacheSize,
4850
func(ctx context.Context, fnSource string, timeout time.Duration) (sgbucket.JSServerTask, error) {
4951
return newJSRunner(ctx, name, what, fnSource)

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"devDependencies": {
3+
"@prettier/plugin-xml": "^3.4.2",
4+
"@redocly/cli": "^2.2.3",
5+
"prettier": "3.6.2"
6+
}
7+
}

service/script_templates/com.couchbase.mobile.sync_gateway.plist

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<?xml version=1.0 encoding=UTF-8?>
2-
<!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
3-
<plist version=1.0>
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
3+
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
4+
<plist version="1.0">
45
<dict>
56
<key>Label</key>
67
<string>com.couchbase.mobile.sync_gateway</string>
@@ -16,6 +17,6 @@
1617
<string>${CONFIG_TEMPLATE_VAR}</string>
1718
</array>
1819
<key>KeepAlive</key>
19-
<true/>
20+
<true />
2021
</dict>
2122
</plist>

0 commit comments

Comments
 (0)