Skip to content

Commit 3c7fd34

Browse files
build: add oxfmt for code formatting and import sorting
Adds oxfmt as a devDependency alongside oxlint and wires it into the lint pipeline. The .oxfmtrc.json config matches Electron's current JS style (single quotes, semicolons, 2-space indent, trailing commas off, printWidth 100) and configures sortImports with custom groups that mirror the import/order pathGroups previously enforced by ESLint: @electron/internal, @electron/*, and {electron,electron/**} each get their own ordered group ahead of external modules. - `yarn lint:fmt` runs `oxfmt --check` over JS/TS sources and is chained into `yarn lint` so CI enforces it automatically. - `yarn format` runs `oxfmt --write` for local fix-up. - lint-staged invokes `oxfmt --write` on staged .js/.ts/.mjs/.cjs files before oxlint, so formatting is applied at commit time. The next commit applies the formatter to the existing codebase so the check actually passes.
1 parent dcb844c commit 3c7fd34

3 files changed

Lines changed: 266 additions & 2 deletions

File tree

‎.oxfmtrc.json‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"printWidth": 120,
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"trailingComma": "none",
7+
"sortImports": {
8+
"newlinesBetween": true,
9+
"groups": [
10+
"electron-internal",
11+
"electron-scoped",
12+
"electron",
13+
"external",
14+
"builtin",
15+
["sibling", "parent"],
16+
"index",
17+
"type",
18+
"unknown"
19+
],
20+
"customGroups": [
21+
{
22+
"groupName": "electron-internal",
23+
"elementNamePattern": ["@electron/internal", "@electron/internal/**"]
24+
},
25+
{
26+
"groupName": "electron-scoped",
27+
"elementNamePattern": ["@electron/**"]
28+
},
29+
{
30+
"groupName": "electron",
31+
"elementNamePattern": ["electron", "electron/**"]
32+
}
33+
]
34+
},
35+
"ignorePatterns": [
36+
"node_modules",
37+
"out",
38+
"ts-gen",
39+
"spec/node_modules",
40+
"spec/fixtures/native-addon",
41+
".github/workflows/node_modules",
42+
"docs/fiddles",
43+
"shell/browser/resources/win/resource.h",
44+
"shell/common/node_includes.h",
45+
"spec/fixtures/pages/jquery-3.6.0.min.js"
46+
]
47+
}

‎package.json‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"minimist": "^1.2.8",
3535
"node-gyp": "^11.4.2",
3636
"null-loader": "^4.0.1",
37+
"oxfmt": "^0.42.0",
3738
"oxlint": "^1.57.0",
3839
"pre-flight": "^2.0.0",
3940
"process": "^0.11.10",
@@ -54,8 +55,10 @@
5455
"scripts": {
5556
"asar": "asar",
5657
"generate-version-json": "node script/generate-version-json.js",
57-
"lint": "node ./script/lint.js && npm run lint:docs && npm run lint:chromium-roller",
58+
"lint": "node ./script/lint.js && npm run lint:fmt && npm run lint:docs && npm run lint:chromium-roller",
5859
"lint:js": "node ./script/lint.js --js",
60+
"lint:fmt": "oxfmt --check \"{lib,spec,script,build,default_app,npm}/**/*.{js,ts,mjs,cjs}\"",
61+
"format": "oxfmt --write \"{lib,spec,script,build,default_app,npm}/**/*.{js,ts,mjs,cjs}\"",
5962
"lint:clang-format": "python3 script/run-clang-format.py -r -c shell/ || (echo \"\\nCode not formatted correctly.\" && exit 1)",
6063
"lint:clang-tidy": "ts-node ./script/run-clang-tidy.ts",
6164
"lint:cpp": "node ./script/lint.js --cc",
@@ -96,8 +99,12 @@
9699
"*": [
97100
"npm run lint:chromium-roller"
98101
],
102+
"*.{js,ts,mjs,cjs}": [
103+
"oxfmt --write"
104+
],
99105
"*.{js,ts}": [
100-
"node script/lint.js --js --fix --only --"
106+
"node script/lint.js --js --fix --only --",
107+
"oxfmt --write"
101108
],
102109
"*.{js,ts,d.ts}": [
103110
"ts-node script/gen-filenames.ts"

‎yarn.lock‎

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ __metadata:
603603
minimist: "npm:^1.2.8"
604604
node-gyp: "npm:^11.4.2"
605605
null-loader: "npm:^4.0.1"
606+
oxfmt: "npm:^0.42.0"
606607
oxlint: "npm:^1.57.0"
607608
pre-flight: "npm:^2.0.0"
608609
process: "npm:^0.11.10"
@@ -1514,6 +1515,139 @@ __metadata:
15141515
languageName: node
15151516
linkType: hard
15161517

1518+
"@oxfmt/binding-android-arm-eabi@npm:0.42.0":
1519+
version: 0.42.0
1520+
resolution: "@oxfmt/binding-android-arm-eabi@npm:0.42.0"
1521+
conditions: os=android & cpu=arm
1522+
languageName: node
1523+
linkType: hard
1524+
1525+
"@oxfmt/binding-android-arm64@npm:0.42.0":
1526+
version: 0.42.0
1527+
resolution: "@oxfmt/binding-android-arm64@npm:0.42.0"
1528+
conditions: os=android & cpu=arm64
1529+
languageName: node
1530+
linkType: hard
1531+
1532+
"@oxfmt/binding-darwin-arm64@npm:0.42.0":
1533+
version: 0.42.0
1534+
resolution: "@oxfmt/binding-darwin-arm64@npm:0.42.0"
1535+
conditions: os=darwin & cpu=arm64
1536+
languageName: node
1537+
linkType: hard
1538+
1539+
"@oxfmt/binding-darwin-x64@npm:0.42.0":
1540+
version: 0.42.0
1541+
resolution: "@oxfmt/binding-darwin-x64@npm:0.42.0"
1542+
conditions: os=darwin & cpu=x64
1543+
languageName: node
1544+
linkType: hard
1545+
1546+
"@oxfmt/binding-freebsd-x64@npm:0.42.0":
1547+
version: 0.42.0
1548+
resolution: "@oxfmt/binding-freebsd-x64@npm:0.42.0"
1549+
conditions: os=freebsd & cpu=x64
1550+
languageName: node
1551+
linkType: hard
1552+
1553+
"@oxfmt/binding-linux-arm-gnueabihf@npm:0.42.0":
1554+
version: 0.42.0
1555+
resolution: "@oxfmt/binding-linux-arm-gnueabihf@npm:0.42.0"
1556+
conditions: os=linux & cpu=arm
1557+
languageName: node
1558+
linkType: hard
1559+
1560+
"@oxfmt/binding-linux-arm-musleabihf@npm:0.42.0":
1561+
version: 0.42.0
1562+
resolution: "@oxfmt/binding-linux-arm-musleabihf@npm:0.42.0"
1563+
conditions: os=linux & cpu=arm
1564+
languageName: node
1565+
linkType: hard
1566+
1567+
"@oxfmt/binding-linux-arm64-gnu@npm:0.42.0":
1568+
version: 0.42.0
1569+
resolution: "@oxfmt/binding-linux-arm64-gnu@npm:0.42.0"
1570+
conditions: os=linux & cpu=arm64 & libc=glibc
1571+
languageName: node
1572+
linkType: hard
1573+
1574+
"@oxfmt/binding-linux-arm64-musl@npm:0.42.0":
1575+
version: 0.42.0
1576+
resolution: "@oxfmt/binding-linux-arm64-musl@npm:0.42.0"
1577+
conditions: os=linux & cpu=arm64 & libc=musl
1578+
languageName: node
1579+
linkType: hard
1580+
1581+
"@oxfmt/binding-linux-ppc64-gnu@npm:0.42.0":
1582+
version: 0.42.0
1583+
resolution: "@oxfmt/binding-linux-ppc64-gnu@npm:0.42.0"
1584+
conditions: os=linux & cpu=ppc64 & libc=glibc
1585+
languageName: node
1586+
linkType: hard
1587+
1588+
"@oxfmt/binding-linux-riscv64-gnu@npm:0.42.0":
1589+
version: 0.42.0
1590+
resolution: "@oxfmt/binding-linux-riscv64-gnu@npm:0.42.0"
1591+
conditions: os=linux & cpu=riscv64 & libc=glibc
1592+
languageName: node
1593+
linkType: hard
1594+
1595+
"@oxfmt/binding-linux-riscv64-musl@npm:0.42.0":
1596+
version: 0.42.0
1597+
resolution: "@oxfmt/binding-linux-riscv64-musl@npm:0.42.0"
1598+
conditions: os=linux & cpu=riscv64 & libc=musl
1599+
languageName: node
1600+
linkType: hard
1601+
1602+
"@oxfmt/binding-linux-s390x-gnu@npm:0.42.0":
1603+
version: 0.42.0
1604+
resolution: "@oxfmt/binding-linux-s390x-gnu@npm:0.42.0"
1605+
conditions: os=linux & cpu=s390x & libc=glibc
1606+
languageName: node
1607+
linkType: hard
1608+
1609+
"@oxfmt/binding-linux-x64-gnu@npm:0.42.0":
1610+
version: 0.42.0
1611+
resolution: "@oxfmt/binding-linux-x64-gnu@npm:0.42.0"
1612+
conditions: os=linux & cpu=x64 & libc=glibc
1613+
languageName: node
1614+
linkType: hard
1615+
1616+
"@oxfmt/binding-linux-x64-musl@npm:0.42.0":
1617+
version: 0.42.0
1618+
resolution: "@oxfmt/binding-linux-x64-musl@npm:0.42.0"
1619+
conditions: os=linux & cpu=x64 & libc=musl
1620+
languageName: node
1621+
linkType: hard
1622+
1623+
"@oxfmt/binding-openharmony-arm64@npm:0.42.0":
1624+
version: 0.42.0
1625+
resolution: "@oxfmt/binding-openharmony-arm64@npm:0.42.0"
1626+
conditions: os=openharmony & cpu=arm64
1627+
languageName: node
1628+
linkType: hard
1629+
1630+
"@oxfmt/binding-win32-arm64-msvc@npm:0.42.0":
1631+
version: 0.42.0
1632+
resolution: "@oxfmt/binding-win32-arm64-msvc@npm:0.42.0"
1633+
conditions: os=win32 & cpu=arm64
1634+
languageName: node
1635+
linkType: hard
1636+
1637+
"@oxfmt/binding-win32-ia32-msvc@npm:0.42.0":
1638+
version: 0.42.0
1639+
resolution: "@oxfmt/binding-win32-ia32-msvc@npm:0.42.0"
1640+
conditions: os=win32 & cpu=ia32
1641+
languageName: node
1642+
linkType: hard
1643+
1644+
"@oxfmt/binding-win32-x64-msvc@npm:0.42.0":
1645+
version: 0.42.0
1646+
resolution: "@oxfmt/binding-win32-x64-msvc@npm:0.42.0"
1647+
conditions: os=win32 & cpu=x64
1648+
languageName: node
1649+
linkType: hard
1650+
15171651
"@oxlint/binding-android-arm-eabi@npm:1.57.0":
15181652
version: 1.57.0
15191653
resolution: "@oxlint/binding-android-arm-eabi@npm:1.57.0"
@@ -8837,6 +8971,75 @@ __metadata:
88378971
languageName: node
88388972
linkType: hard
88398973

8974+
"oxfmt@npm:^0.42.0":
8975+
version: 0.42.0
8976+
resolution: "oxfmt@npm:0.42.0"
8977+
dependencies:
8978+
"@oxfmt/binding-android-arm-eabi": "npm:0.42.0"
8979+
"@oxfmt/binding-android-arm64": "npm:0.42.0"
8980+
"@oxfmt/binding-darwin-arm64": "npm:0.42.0"
8981+
"@oxfmt/binding-darwin-x64": "npm:0.42.0"
8982+
"@oxfmt/binding-freebsd-x64": "npm:0.42.0"
8983+
"@oxfmt/binding-linux-arm-gnueabihf": "npm:0.42.0"
8984+
"@oxfmt/binding-linux-arm-musleabihf": "npm:0.42.0"
8985+
"@oxfmt/binding-linux-arm64-gnu": "npm:0.42.0"
8986+
"@oxfmt/binding-linux-arm64-musl": "npm:0.42.0"
8987+
"@oxfmt/binding-linux-ppc64-gnu": "npm:0.42.0"
8988+
"@oxfmt/binding-linux-riscv64-gnu": "npm:0.42.0"
8989+
"@oxfmt/binding-linux-riscv64-musl": "npm:0.42.0"
8990+
"@oxfmt/binding-linux-s390x-gnu": "npm:0.42.0"
8991+
"@oxfmt/binding-linux-x64-gnu": "npm:0.42.0"
8992+
"@oxfmt/binding-linux-x64-musl": "npm:0.42.0"
8993+
"@oxfmt/binding-openharmony-arm64": "npm:0.42.0"
8994+
"@oxfmt/binding-win32-arm64-msvc": "npm:0.42.0"
8995+
"@oxfmt/binding-win32-ia32-msvc": "npm:0.42.0"
8996+
"@oxfmt/binding-win32-x64-msvc": "npm:0.42.0"
8997+
tinypool: "npm:2.1.0"
8998+
dependenciesMeta:
8999+
"@oxfmt/binding-android-arm-eabi":
9000+
optional: true
9001+
"@oxfmt/binding-android-arm64":
9002+
optional: true
9003+
"@oxfmt/binding-darwin-arm64":
9004+
optional: true
9005+
"@oxfmt/binding-darwin-x64":
9006+
optional: true
9007+
"@oxfmt/binding-freebsd-x64":
9008+
optional: true
9009+
"@oxfmt/binding-linux-arm-gnueabihf":
9010+
optional: true
9011+
"@oxfmt/binding-linux-arm-musleabihf":
9012+
optional: true
9013+
"@oxfmt/binding-linux-arm64-gnu":
9014+
optional: true
9015+
"@oxfmt/binding-linux-arm64-musl":
9016+
optional: true
9017+
"@oxfmt/binding-linux-ppc64-gnu":
9018+
optional: true
9019+
"@oxfmt/binding-linux-riscv64-gnu":
9020+
optional: true
9021+
"@oxfmt/binding-linux-riscv64-musl":
9022+
optional: true
9023+
"@oxfmt/binding-linux-s390x-gnu":
9024+
optional: true
9025+
"@oxfmt/binding-linux-x64-gnu":
9026+
optional: true
9027+
"@oxfmt/binding-linux-x64-musl":
9028+
optional: true
9029+
"@oxfmt/binding-openharmony-arm64":
9030+
optional: true
9031+
"@oxfmt/binding-win32-arm64-msvc":
9032+
optional: true
9033+
"@oxfmt/binding-win32-ia32-msvc":
9034+
optional: true
9035+
"@oxfmt/binding-win32-x64-msvc":
9036+
optional: true
9037+
bin:
9038+
oxfmt: bin/oxfmt
9039+
checksum: 10c0/0fe0e0d1f2330b66a3e3df2dfeb013493831d7312a9c66f51a2a0814dfb2468f9d6cfd3a58d763dfd4a004db14baa157ada9645205b350af799c665f67d271d5
9040+
languageName: node
9041+
linkType: hard
9042+
88409043
"oxlint@npm:^1.57.0":
88419044
version: 1.57.0
88429045
resolution: "oxlint@npm:1.57.0"
@@ -11106,6 +11309,13 @@ __metadata:
1110611309
languageName: node
1110711310
linkType: hard
1110811311

11312+
"tinypool@npm:2.1.0":
11313+
version: 2.1.0
11314+
resolution: "tinypool@npm:2.1.0"
11315+
checksum: 10c0/9fb1c760558c6264e0f4cfde96a63b12450b43f1730fbe6274aa24ddbdf488745c08924d0dea7a1303b47d555416a6415f2113898c69b6ecf731e75ac95238a5
11316+
languageName: node
11317+
linkType: hard
11318+
1110911319
"to-regex-range@npm:^5.0.1":
1111011320
version: 5.0.1
1111111321
resolution: "to-regex-range@npm:5.0.1"

0 commit comments

Comments
 (0)