Skip to content

Commit

Permalink
lint: more prettier linting......
Browse files Browse the repository at this point in the history
  • Loading branch information
coroiu committed Oct 10, 2024
1 parent 6441cbc commit 919c591
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 67 deletions.
2 changes: 1 addition & 1 deletion crates/bitwarden-wasm-internal/src/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
export class WasmError extends Error {
constructor(message) {
super(message);
this.name = 'WasmError';
this.name = "WasmError";
}
}
52 changes: 26 additions & 26 deletions support/docs/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});

Expand All @@ -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));
});
});
}
Expand Down Expand Up @@ -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);
Expand All @@ -125,15 +125,15 @@ 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;
} else if (t.type.resolved_path) {
return t.type.resolved_path.name;
}
});
out += ">";
out += '>';
}
return out;
}
80 changes: 40 additions & 40 deletions support/scripts/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
for await (const d of await fs.promises.opendir(dir)) {
Expand All @@ -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);
}
Expand All @@ -120,31 +120,31 @@ 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();

function writeToFile(filename: string, lines: string[]) {
const output = fs.createWriteStream(filename);
lines.forEach((line) => {
output.write(line + "\n");
output.write(line + '\n');
});
output.close();
}

0 comments on commit 919c591

Please sign in to comment.