From 01056723f0ce19934add248e6ff0c7ce97fbc3a3 Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Thu, 10 Oct 2024 10:49:01 +0200 Subject: [PATCH] lint: more prettier linting...... --- crates/bitwarden-wasm-internal/src/error.js | 2 +- support/docs/docs.ts | 52 +++++++------- support/scripts/schemas.ts | 80 ++++++++++----------- 3 files changed, 67 insertions(+), 67 deletions(-) diff --git a/crates/bitwarden-wasm-internal/src/error.js b/crates/bitwarden-wasm-internal/src/error.js index c214d61ab..092040ca5 100644 --- a/crates/bitwarden-wasm-internal/src/error.js +++ b/crates/bitwarden-wasm-internal/src/error.js @@ -6,6 +6,6 @@ export class WasmError extends Error { constructor(message) { super(message); - this.name = 'WasmError'; + this.name = "WasmError"; } } diff --git a/support/docs/docs.ts b/support/docs/docs.ts index 067ff0827..ca8385dde 100644 --- a/support/docs/docs.ts +++ b/support/docs/docs.ts @@ -2,36 +2,36 @@ // // Do note that this script follows no best practices and will not handle anything many edge cases. -import fs from "fs"; -import path from "path"; -import Handlebars from "handlebars"; +import fs from 'fs'; +import path from 'path'; +import Handlebars from 'handlebars'; -import { Input, InputType } from "./rustdoc"; +import { Input, InputType } from './rustdoc'; -const doc = JSON.parse(fs.readFileSync("./target/doc/bitwarden_uniffi.json", "utf8")); +const doc = JSON.parse(fs.readFileSync('./target/doc/bitwarden_uniffi.json', 'utf8')); const command = JSON.parse( - fs.readFileSync("./support/schemas/bitwarden_uniffi/DocRef.json", "utf8"), + fs.readFileSync('./support/schemas/bitwarden_uniffi/DocRef.json', 'utf8'), ); const template = Handlebars.compile( - fs.readFileSync(path.resolve(__dirname, "template.hbs"), "utf8"), + fs.readFileSync(path.resolve(__dirname, 'template.hbs'), 'utf8'), ); // Modify this to include more root elements const rootElements = [ - "Client", - "ClientAuth", - "ClientAttachments", - "ClientCiphers", - "ClientCollections", - "ClientCrypto", - "ClientExporters", - "ClientFolders", - "ClientGenerators", - "ClientPasswordHistory", - "ClientPlatform", - "ClientSends", - "ClientVault", + 'Client', + 'ClientAuth', + 'ClientAttachments', + 'ClientCiphers', + 'ClientCollections', + 'ClientCrypto', + 'ClientExporters', + 'ClientFolders', + 'ClientGenerators', + 'ClientPasswordHistory', + 'ClientPlatform', + 'ClientSends', + 'ClientVault', ]; const localIndexArray = Object.values(doc.index).filter((entry: any) => entry.crate_id == 0); @@ -66,10 +66,10 @@ const out = rootElements.map((rootElement) => { }); function stripDef(str: string) { - return str.replace(/#\/definitions\//g, ""); + return str.replace(/#\/definitions\//g, ''); } -Handlebars.registerHelper("stripDef", (str: string) => { +Handlebars.registerHelper('stripDef', (str: string) => { return stripDef(str); }); @@ -83,7 +83,7 @@ for (let i = 0; i < usedDefinitions.length; i++) { Object.entries(cmd.properties ?? {}).forEach((prop: any) => { prop[1].allOf?.forEach((e: any) => { - usedDefinitions.push(stripDef(e["$ref"] as string)); + usedDefinitions.push(stripDef(e['$ref'] as string)); }); }); } @@ -112,7 +112,7 @@ function map_type(t: InputType) { const args = t.resolved_path?.args; const name = t.resolved_path?.name; - let out = ""; + let out = ''; if (name) { usedDefinitions.push(name); @@ -125,7 +125,7 @@ function map_type(t: InputType) { } if (args != null && args.angle_bracketed.args.length > 0) { - out += "<"; + out += '<'; out += args.angle_bracketed.args.map((t: any) => { if (t.type.generic) { return t.type.generic; @@ -133,7 +133,7 @@ function map_type(t: InputType) { return t.type.resolved_path.name; } }); - out += ">"; + out += '>'; } return out; } diff --git a/support/scripts/schemas.ts b/support/scripts/schemas.ts index 3eaad1903..accbf788b 100644 --- a/support/scripts/schemas.ts +++ b/support/scripts/schemas.ts @@ -4,10 +4,10 @@ import { InputData, JSONSchemaInput, FetchingJSONSchemaStore, -} from "quicktype-core"; +} from 'quicktype-core'; -import fs from "fs"; -import path from "path"; +import fs from 'fs'; +import path from 'path'; async function* walk(dir: string): AsyncIterable { for await (const d of await fs.promises.opendir(dir)) { @@ -25,92 +25,92 @@ async function main() { const inputData = new InputData(); inputData.addInput(schemaInput); inputData.addSource( - "schema", + 'schema', { - name: "SchemaTypes", - uris: ["support/schemas/schema_types/SchemaTypes.json#/definitions/"], + name: 'SchemaTypes', + uris: ['support/schemas/schema_types/SchemaTypes.json#/definitions/'], }, () => new JSONSchemaInput(new FetchingJSONSchemaStore()), ); const ts = await quicktype({ inputData, - lang: "typescript", + lang: 'typescript', rendererOptions: {}, }); - writeToFile("./languages/js/sdk-client/src/schemas.ts", ts.lines); - writeToFile("./crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts", ts.lines); + writeToFile('./languages/js/sdk-client/src/schemas.ts', ts.lines); + writeToFile('./crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts', ts.lines); const python = await quicktype({ inputData, - lang: "python", + lang: 'python', rendererOptions: { - "python-version": "3.7", + 'python-version': '3.7', }, }); - writeToFile("./languages/python/bitwarden_sdk/schemas.py", python.lines); + writeToFile('./languages/python/bitwarden_sdk/schemas.py', python.lines); const ruby = await quicktype({ inputData, - lang: "ruby", + lang: 'ruby', rendererOptions: { - "ruby-version": "3.0", + 'ruby-version': '3.0', }, }); - writeToFile("./languages/ruby/bitwarden_sdk_secrets/lib/schemas.rb", ruby.lines); + writeToFile('./languages/ruby/bitwarden_sdk_secrets/lib/schemas.rb', ruby.lines); const csharp = await quicktype({ inputData, - lang: "csharp", + lang: 'csharp', rendererOptions: { - namespace: "Bitwarden.Sdk", - framework: "SystemTextJson", - "csharp-version": "6", + namespace: 'Bitwarden.Sdk', + framework: 'SystemTextJson', + 'csharp-version': '6', }, }); - writeToFile("./languages/csharp/Bitwarden.Sdk/schemas.cs", csharp.lines); + writeToFile('./languages/csharp/Bitwarden.Sdk/schemas.cs', csharp.lines); const cpp = await quicktype({ inputData, - lang: "cpp", + lang: 'cpp', rendererOptions: { - namespace: "Bitwarden::Sdk", - "include-location": "global-include", + namespace: 'Bitwarden::Sdk', + 'include-location': 'global-include', }, }); cpp.lines.forEach((line, idx) => { // Replace DOMAIN for URI_DOMAIN, because DOMAIN is an already defined macro - cpp.lines[idx] = line.replace(/DOMAIN/g, "URI_DOMAIN"); + cpp.lines[idx] = line.replace(/DOMAIN/g, 'URI_DOMAIN'); }); - writeToFile("./languages/cpp/include/schemas.hpp", cpp.lines); + writeToFile('./languages/cpp/include/schemas.hpp', cpp.lines); const go = await quicktype({ inputData, - lang: "go", + lang: 'go', rendererOptions: { - package: "sdk", - "omit-empty": true, + package: 'sdk', + 'omit-empty': true, }, }); - writeToFile("./languages/go/schema.go", go.lines); + writeToFile('./languages/go/schema.go', go.lines); const java = await quicktypeMultiFile({ inputData, - lang: "java", + lang: 'java', rendererOptions: { - package: "com.bitwarden.sdk.schema", - "java-version": "8", + package: 'com.bitwarden.sdk.schema', + 'java-version': '8', }, }); - const javaDir = "./languages/java/src/main/java/com/bitwarden/sdk/schema/"; + const javaDir = './languages/java/src/main/java/com/bitwarden/sdk/schema/'; if (!fs.existsSync(javaDir)) { fs.mkdirSync(javaDir); } @@ -120,23 +120,23 @@ async function main() { const php = await quicktype({ inputData, - lang: "php", + lang: 'php', inferUuids: false, inferDateTimes: false, rendererOptions: { - "acronym-style": "camel", - "with-get": false, + 'acronym-style': 'camel', + 'with-get': false, }, }); - const phpDir = "./languages/php/src/Schemas/"; + const phpDir = './languages/php/src/Schemas/'; if (!fs.existsSync(phpDir)) { fs.mkdirSync(phpDir); } - php.lines.splice(1, 0, "namespace Bitwarden\\Sdk\\Schemas;", "use stdClass;", "use Exception;"); + php.lines.splice(1, 0, 'namespace Bitwarden\\Sdk\\Schemas;', 'use stdClass;', 'use Exception;'); - writeToFile("./languages/php/src/Schemas/Schemas.php", php.lines); + writeToFile('./languages/php/src/Schemas/Schemas.php', php.lines); } main(); @@ -144,7 +144,7 @@ main(); function writeToFile(filename: string, lines: string[]) { const output = fs.createWriteStream(filename); lines.forEach((line) => { - output.write(line + "\n"); + output.write(line + '\n'); }); output.close(); }