Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ci] Biome formatter #6248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .prettierignore

This file was deleted.

7 changes: 0 additions & 7 deletions .prettierrc.json5

This file was deleted.

52 changes: 52 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"ignoreUnknown": true,
"ignore": [
"./src/api/entities/",
"./src/translations/",
"node_modules/",
"build/",
"dist/",
"libs/",
"app-android/",
"app-ios/",
"fdroid-metadata-workaround/",
"packages/tutanota-crypto/lib/internal/"
]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"formatter": {
"enabled": true,
"indentStyle": "tab",
"lineWidth": 160
},
"javascript": {
"formatter": {
"enabled": true,
"quoteStyle": "double",
"trailingComma": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always"
}
},
"json": {
"parser": {
"allowTrailingCommas": false,
"allowComments": false
},
"formatter": {
"enabled": true,
"indentStyle": "tab",
"lineWidth": 160
}
}
}
4 changes: 1 addition & 3 deletions buildSrc/buildWebapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ async function bundleServiceWorker(bundles, version, minify) {
// we still cache native-common even though we don't need it because worker has to statically depend on it
.concat(
bundles.filter(
(it) =>
it.startsWith("translation-en") ||
(!it.startsWith("translation") && !it.startsWith("native-main") && !it.startsWith("SearchInPageOverlay")),
(it) => it.startsWith("translation-en") || (!it.startsWith("translation") && !it.startsWith("native-main") && !it.startsWith("SearchInPageOverlay")),
),
)
.concat(["images/logo-favicon.png", "images/logo-favicon-152.png", "images/logo-favicon-196.png", "images/font.ttf"])
Expand Down
12 changes: 4 additions & 8 deletions buildSrc/fetchDictionaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ async function publishDebPackage() {

console.log("create", deb)
exitOnFail(
spawnSync(
"/usr/local/bin/fpm",
`${commonArgs} -n tutanota-desktop-dicts -v ${electronVersion} dictionaries/=${target}-desktop/dictionaries`.split(" "),
{
cwd: "build",
stdio: [process.stdin, process.stdout, process.stderr],
},
),
spawnSync("/usr/local/bin/fpm", `${commonArgs} -n tutanota-desktop-dicts -v ${electronVersion} dictionaries/=${target}-desktop/dictionaries`.split(" "), {
cwd: "build",
stdio: [process.stdin, process.stdout, process.stderr],
}),
)

// copy spell checker dictionaries.
Expand Down
5 changes: 1 addition & 4 deletions buildSrc/getNativeLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ if (process.argv[1] === fileURLToPath(import.meta.url)) {
.option("-r, --root-dir <rootDir>", "path to the root of the project", ".")
.option("-f, --force-rebuild", "force a rebuild (don't use the cache)")
.option("-e, --use-existing", "Use the existing built version (e.g. when using prebuild)")
.option(
"-c, --copy-target <copyTarget>",
"Which node-gyp target (specified in binding.gyp) to copy the output of. Defaults to the same name as the module",
)
.option("-c, --copy-target <copyTarget>", "Which node-gyp target (specified in binding.gyp) to copy the output of. Defaults to the same name as the module")
.action(async (module, opts) => {
validateOpts(opts)
await cli(module, opts)
Expand Down
16 changes: 8 additions & 8 deletions buildSrc/notarize.cjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// this is commonjs because it's called by electron-builder
const {notarize} = require('@electron/notarize');
const { notarize } = require("@electron/notarize")

exports.default = async function notarizing(context) {
const {electronPlatformName, appOutDir} = context;
if (electronPlatformName !== 'darwin') {
return;
const { electronPlatformName, appOutDir } = context
if (electronPlatformName !== "darwin") {
return
}

const appName = context.packager.appInfo.productFilename;
const appName = context.packager.appInfo.productFilename

console.log(`Notarizing ${appName} teamId:${process.env.APPLETEAMID}`)
return await notarize({
appBundleId: 'de.tutao.tutanota',
appBundleId: "de.tutao.tutanota",
appPath: `${appOutDir}/${appName}.app`,
appleId: process.env.APPLEID,
appleIdPassword: process.env.APPLEIDPASS,
teamId: process.env.APPLETEAMID,
tool: "notarytool", // notarytool is part of Xcode 13, default is "legacy", notarytool is much faster
});
};
})
}
4 changes: 1 addition & 3 deletions buildSrc/releaseNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ if (wasRunFromCli) {
program
.requiredOption("--milestone <milestone>", "Milestone to reference")
.addOption(
new Option("--platform <platform>", "label filter for the issues to include in the notes")
.choices(["android", "ios", "desktop", "web"])
.default("web"),
new Option("--platform <platform>", "label filter for the issues to include in the notes").choices(["android", "ios", "desktop", "web"]).default("web"),
)
.action(async (options) => {
await renderReleaseNotes(options)
Expand Down
68 changes: 42 additions & 26 deletions buildSrc/winsigner.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const path = require("path")
const fs = require("fs-extra")
const spawn = require('child_process').spawn
const spawn = require("child_process").spawn

/**
* sign a given file either with a private key taken from a pkcs12 signing certificate
Expand All @@ -10,9 +10,9 @@ const spawn = require('child_process').spawn
* argument names may be fixed by electron-builder
*/
function signer({
path: pathToSign, // path to the file to sign (string)
hash: hashAlgorithm // hash algorithm to use (string, defaults to "sha256")
}) {
path: pathToSign, // path to the file to sign (string)
hash: hashAlgorithm, // hash algorithm to use (string, defaults to "sha256")
}) {
const ext = path.extname(pathToSign)
// /thing/thong.AppImage -> /thing/thong-unsigned.AppImage
const unsignedFileName = pathToSign.slice(0, pathToSign.length - ext.length) + "-unsigned" + ext
Expand All @@ -29,12 +29,18 @@ function getSelfSignedArgs(unsignedFileName, hash, signedFileOutPath) {

return [
"sign",
"-in", unsignedFileName,
"-out", signedFileOutPath,
"-pkcs12", certificateFile,
"-h", hash ? hash : "sha256",
"-t", "http://timestamp.comodoca.com/authenticode",
"-n", "tutanota-desktop"
"-in",
unsignedFileName,
"-out",
signedFileOutPath,
"-pkcs12",
certificateFile,
"-h",
hash ? hash : "sha256",
"-t",
"http://timestamp.comodoca.com/authenticode",
"-n",
"tutanota-desktop",
]
}

Expand All @@ -55,37 +61,47 @@ function getHsmArgs(unsignedFileName, hash, signedFileOutPath) {
// http://timestamp.sectigo.com

if (!certificateFile) {
console.error("ERROR: " + signedFileOutPath.split(path.sep).pop() + "\" not signed! The NSIS installer may not work.")
console.error("ERROR: " + signedFileOutPath.split(path.sep).pop() + '" not signed! The NSIS installer may not work.')
console.log("\t• set WIN_CSC_FILE env var")
throw new Error(signedFileOutPath)
}

if (!hsmPin) {
console.log("ERROR: " + signedFileOutPath.split(path.sep).pop() + "\" not signed! The NSIS installer may not work.")
console.log("ERROR: " + signedFileOutPath.split(path.sep).pop() + '" not signed! The NSIS installer may not work.')
console.log("\t• set HSM_USER_PIN env var")
throw new Error(signedFileOutPath)
}

return [
"sign",
"-in", unsignedFileName,
"-out", signedFileOutPath,
"-pkcs11engine", "/usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so",
"-pkcs11module", "/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so",
"-certs", certificateFile,
"-key", "11", // this is the key corresponding to the Windows authenticode codesigning certificate
"-pass", hsmPin,
"-h", hash ? hash : "sha256",
"-t", "http://timestamp.comodoca.com/authenticode",
"-n", "tutanota-desktop"
"-in",
unsignedFileName,
"-out",
signedFileOutPath,
"-pkcs11engine",
"/usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so",
"-pkcs11module",
"/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so",
"-certs",
certificateFile,
"-key",
"11", // this is the key corresponding to the Windows authenticode codesigning certificate
"-pass",
hsmPin,
"-h",
hash ? hash : "sha256",
"-t",
"http://timestamp.comodoca.com/authenticode",
"-n",
"tutanota-desktop",
]
}

function signWithArgs(commandArguments, signedFileOutPath, unsignedFileName) {
const command = "/usr/bin/osslsigncode"

if (!fs.existsSync(command)) {
console.log("ERROR: " + signedFileOutPath.split(path.sep).pop() + "\" not signed! The NSIS installer may not work.")
console.log("ERROR: " + signedFileOutPath.split(path.sep).pop() + '" not signed! The NSIS installer may not work.')
console.log("\t• install osslsigncode")
return Promise.reject(new Error(signedFileOutPath))
}
Expand All @@ -94,11 +110,11 @@ function signWithArgs(commandArguments, signedFileOutPath, unsignedFileName) {
//console.log(`spawning "${command} ${commandArguments.join(" ")}"`)
let child = spawn(command, commandArguments, {
detached: false,
stdio: ['ignore', 'inherit', 'inherit'],
stdio: ["ignore", "inherit", "inherit"],
})

return new Promise((resolve, reject) => {
child.on('close', (exitCode) => {
child.on("close", (exitCode) => {
if (exitCode !== 0) {
reject(exitCode)
} else {
Expand Down
16 changes: 12 additions & 4 deletions githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@

# pre-commit hook to check & fix formatting. does not deal with spaces in paths.

# get staged files exclude deleted files | only match what prettier matches | transform newline & whitespace into spaces
CHG=$(git diff --name-only --diff-filter=d --cached | grep -E ".*\.(ts|js|json|json5)$" | tr [:space:] " ")
# run prettier fix on them
npx prettier -w $CHG > /dev/null
# get staged files exclude deleted files | only match what biome matches | remove ignored files from the list | transform newline & whitespace into spaces
CHG=$(git diff --name-only --diff-filter=d --cached | grep -E ".*\.(ts|js|json|json5)$" | grep -vE 'package\.json|package-lock\.json|tsconfig\.json' | tr [:space:] " ")
# exit if no files were added
REM=$(echo "$CHG" | wc -w)
if [ $REM -eq 0 ]; then
exit 0
else
echo formatting $REM files
fi

# run biome on them (if there are some left)
npx @biomejs/biome format --write $CHG > /dev/null
# re-add the fixed files
git add $CHG > /dev/null
7 changes: 1 addition & 6 deletions ipc-schema/facades/SearchTextInAppFacade.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@
"methods": {
"findInPage": {
"doc": "send a search request to the native search api on the current window",
"arg": [
{ "searchTerm": "string" },
{ "forward": "boolean" },
{ "matchCase": "boolean" },
{ "findNext": "boolean" }
],
"arg": [{ "searchTerm": "string" }, { "forward": "boolean" }, { "matchCase": "boolean" }, { "findNext": "boolean" }],
"ret": "Result?"
},
"stopFindInPage": {
Expand Down
Loading
Loading