Skip to content

Commit

Permalink
fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Apr 25, 2024
1 parent 830f8d8 commit ae8a723
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions packages/@biomejs/js-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type {
PullDiagnosticsResult,
Workspace,
} from "@biomejs/wasm-nodejs";
import { Distribution, type WasmModule, loadModule, wrapError } from "./wasm";
import {Distribution, type WasmModule, loadModule, wrapError} from "./wasm";

// Re-export of some useful types for users
export type Configuration = PartialConfiguration;
export type { Diagnostic };
export { Distribution };
export type {Diagnostic};
export {Distribution};

export interface FormatContentDebugOptions extends FormatContentOptions {
/**
Expand Down Expand Up @@ -93,15 +93,18 @@ export class Biome {
private constructor(
private readonly module: WasmModule,
private readonly workspace: Workspace,
) {}
) {
}

/**
* It creates a new instance of the class {Biome}.
*/
public static async create(options: BiomeCreate): Promise<Biome> {
const module = await loadModule(options.distribution);
const workspace = new module.Workspace();
return new Biome(module, workspace);
const biome = new Biome(module, workspace);
biome.registerProjectFolder();
return biome
}

/**
Expand All @@ -123,18 +126,24 @@ export class Biome {
*/
public applyConfiguration(configuration: Configuration): void {
try {
this.workspace.registerProjectFolder({
setAsCurrentWorkspace: true,
});
this.workspace.updateSettings({
configuration,
gitignore_matches: [],
workspace_directory: "./"
});
} catch (e) {
throw wrapError(e);
}
}

public registerProjectFolder(): void;
public registerProjectFolder(path?: String): void {

Check failure on line 140 in packages/@biomejs/js-api/src/index.ts

View workflow job for this annotation

GitHub Actions / Check JS Files

Don't use 'String' as a type.
this.workspace.registerProjectFolder({
path,
setAsCurrentWorkspace: true
})
}

private tryCatchWrapper<T>(func: () => T): T {
try {
return func();
Expand Down Expand Up @@ -188,7 +197,7 @@ export class Biome {
return this.withFile(options.filePath, content, (path) => {
let code = content;

const { diagnostics } = this.workspace.pullDiagnostics({
const {diagnostics} = this.workspace.pullDiagnostics({
path,
categories: ["Syntax"],
max_diagnostics: Number.MAX_SAFE_INTEGER,
Expand Down Expand Up @@ -239,26 +248,26 @@ export class Biome {
*/
lintContent(
content: string,
{ filePath, fixFileMode }: LintContentOptions,
{filePath, fixFileMode}: LintContentOptions,
): LintResult {
const maybeFixedContent = fixFileMode
? this.withFile(filePath, content, (path) => {
let code = content;
let code = content;

const result = this.workspace.fixFile({
path,
fix_file_mode: fixFileMode,
should_format: false,
});
const result = this.workspace.fixFile({
path,
fix_file_mode: fixFileMode,
should_format: false,
});

code = result.code;
code = result.code;

return code;
})
return code;
})
: content;

return this.withFile(filePath, maybeFixedContent, (path) => {
const { diagnostics } = this.workspace.pullDiagnostics({
const {diagnostics} = this.workspace.pullDiagnostics({
path,
categories: ["Syntax", "Lint"],
max_diagnostics: Number.MAX_SAFE_INTEGER,
Expand Down

0 comments on commit ae8a723

Please sign in to comment.