Skip to content

Commit 6312d4b

Browse files
authored
Enable reformat ci (#73)
We already have `reformat.mjs`, but it wasn't enabled in our CI pipeline. This pull request activates it. If there are any formatting differences, the CI will fail, providing very fast feedback.
1 parent 62e345e commit 6312d4b

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v3
15-
- name: Use Node.js ${{ matrix.node-version }}
15+
- name: Use Node.js
1616
uses: actions/setup-node@v3
1717
with:
1818
cache: 'npm'
@@ -27,7 +27,7 @@ jobs:
2727

2828
steps:
2929
- uses: actions/checkout@v3
30-
- name: Use Node.js ${{ matrix.node-version }}
30+
- name: Use Node.js
3131
uses: actions/setup-node@v3
3232
with:
3333
cache: 'npm'
@@ -41,3 +41,15 @@ jobs:
4141
java-version: 17
4242
architecture: x64
4343
- run: npx zx ./tools/generate-test.mjs
44+
45+
format-diff:
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- uses: actions/checkout@v3
50+
- uses: actions/setup-node@v3
51+
with:
52+
cache: 'npm'
53+
- run: npx zx ./tools/reformat.mjs
54+
- name: Check there is no diff (Run ./tools/reformat.mjs if there is a diff)
55+
run: git diff --exit-code

channel-access-token.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ paths:
3030
application/x-www-form-urlencoded:
3131
schema:
3232
oneOf:
33-
- $ref: '#/components/schemas/IssueStatelessChannelTokenByJWTAssertionRequest'
34-
- $ref: '#/components/schemas/IssueStatelessChannelTokenByClientSecretRequest'
33+
- $ref: "#/components/schemas/IssueStatelessChannelTokenByJWTAssertionRequest"
34+
- $ref: "#/components/schemas/IssueStatelessChannelTokenByClientSecretRequest"
3535
responses:
3636
"200":
3737
description: "OK"

manage-audience.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ paths:
442442
"$ref": "#/components/schemas/AudienceGroupCreateRoute"
443443
description: |+
444444
How the audience was created. If omitted, all audiences are included.
445-
445+
446446
`OA_MANAGER`: Return only audiences created with LINE Official Account Manager (opens new window).
447447
`MESSAGING_API`: Return only audiences created with Messaging API.
448448
responses:

messaging-api.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,7 +3319,7 @@ components:
33193319
unlink: "#/components/schemas/RichMenuBatchUnlinkOperation"
33203320
unlinkAll: "#/components/schemas/RichMenuBatchUnlinkAllOperation"
33213321
RichMenuBatchLinkOperation:
3322-
description: Replace the rich menu with the rich menu specified in the `to` property for all users linked to the rich menu specified in the `from` property.
3322+
description: "Replace the rich menu with the rich menu specified in the `to` property for all users linked to the rich menu specified in the `from` property."
33233323
type: object
33243324
required:
33253325
- from
@@ -3333,7 +3333,7 @@ components:
33333333
to:
33343334
type: string
33353335
RichMenuBatchUnlinkOperation:
3336-
description: Unlink the rich menu for all users linked to the rich menu specified in the `from` property.
3336+
description: "Unlink the rich menu for all users linked to the rich menu specified in the `from` property."
33373337
type: object
33383338
required:
33393339
- from
@@ -3344,7 +3344,7 @@ components:
33443344
from:
33453345
type: string
33463346
RichMenuBatchUnlinkAllOperation:
3347-
description: Unlink the rich menu from all users linked to the rich menu.
3347+
description: "Unlink the rich menu from all users linked to the rich menu."
33483348
type: object
33493349
allOf:
33503350
- "$ref": "#/components/schemas/RichMenuBatchOperation"
@@ -3583,7 +3583,7 @@ components:
35833583
type: object
35843584
additionalProperties:
35853585
$ref: "#/components/schemas/SubstitutionObject"
3586-
description: "A mapping that specifies substitutions for parts enclosed in {} within the 'text' field."
3586+
description: "A mapping that specifies substitutions for parts enclosed in {} within the `text` field."
35873587
quoteToken:
35883588
type: string
35893589
description: "Quote token of the message you want to quote."

module.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ components:
170170
The time it takes for initiative (Chat Control) to return to the Primary Channel (the time that the module channel stays on the Active Channel).
171171
The value is specified in seconds. The maximum value is one year (3600 * 24 * 365).
172172
The default value is 3600 (1 hour).
173-
173+
174174
* Ignored if the value of expired is false.
175175
example: 3600
176176
GetModulesResponse:

tools/reformat.mjs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@ const fs = require('fs');
55
for (let ymlFile of globby.globbySync("*.yml")) {
66
console.log(`Processing ${ymlFile}`);
77

8-
const src = fs.readFileSync(ymlFile, 'utf-8');
8+
await convertSingleQuotesToDoubleQuotes(ymlFile);
9+
await trimTrailingWhitespace(ymlFile);
10+
}
11+
12+
async function convertSingleQuotesToDoubleQuotes(ymlFile) {
13+
const content = fs.readFileSync(ymlFile, 'utf-8');
914

10-
// convert single quotes to double quotes.
11-
let dst = src.replace(/ '([^']+)'/g, ` "$1"`);
15+
let dst = content.replace(/ '([^']+)'/g, ` "$1"`);
1216
dst = dst.replace(/ (\/[^:\n]+):/g, ` "$1":`);
1317
dst = dst.replace(/(description|summary): ([^|"'][^\n]+)/g,
1418
(m, key, val) => `${key}: "${val.replace(/"/g, '`')}"`);
1519

16-
fs.writeFileSync(ymlFile, dst);
20+
await fs.writeFileSync(ymlFile, dst);
21+
}
22+
23+
24+
async function trimTrailingWhitespace(ymlFile) {
25+
const content = await fs.readFileSync(ymlFile, "utf8");
26+
27+
const trimmedContent = content
28+
.split("\n")
29+
.map((line) => line.replace(/\s+$/, ""))
30+
.join("\n");
31+
32+
await fs.writeFileSync(ymlFile, trimmedContent, "utf8");
1733
}

webhook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ components:
216216
description: "Type"
217217
id:
218218
type: string
219-
description: Message ID
219+
description: "Message ID"
220220
discriminator:
221221
propertyName: type
222222
mapping:

0 commit comments

Comments
 (0)