Skip to content

Commit

Permalink
chore: update formatting config to match main repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed Aug 8, 2024
1 parent b6d5aab commit 1172836
Show file tree
Hide file tree
Showing 46 changed files with 159 additions and 159 deletions.
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingComma": "es5"
"trailingComma": "all"
}
},
"json": {
Expand Down
6 changes: 3 additions & 3 deletions packages/astro-check/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export async function check(flags: Partial<Flags>): Promise<boolean | void> {
// Dynamically get the list of extensions to watch from the files already included in the project
const checkedExtensions = Array.from(
new Set(
checker.linter.projectHost.getScriptFileNames().map((fileName) => path.extname(fileName))
)
checker.linter.projectHost.getScriptFileNames().map((fileName) => path.extname(fileName)),
),
);
createWatcher(workspaceRoot, checkedExtensions)
.on('add', (fileName) => {
Expand Down Expand Up @@ -90,7 +90,7 @@ export async function check(flags: Partial<Flags>): Promise<boolean | void> {
: undefined,
]
.filter(Boolean)
.join(`\n${dim('-')} `)
.join(`\n${dim('-')} `),
);

if (flags.watch) {
Expand Down
8 changes: 4 additions & 4 deletions packages/language-server/src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class AstroCheck {
constructor(
private readonly workspacePath: string,
private readonly typescriptPath: string | undefined,
private readonly tsconfigPath: string | undefined
private readonly tsconfigPath: string | undefined,
) {
this.initialize();
}
Expand Down Expand Up @@ -115,13 +115,13 @@ export class AstroCheck {
});

result.errors += fileDiagnostics.filter(
(diag) => diag.severity === DiagnosticSeverity.Error
(diag) => diag.severity === DiagnosticSeverity.Error,
).length;
result.warnings += fileDiagnostics.filter(
(diag) => diag.severity === DiagnosticSeverity.Warning
(diag) => diag.severity === DiagnosticSeverity.Warning,
).length;
result.hints += fileDiagnostics.filter(
(diag) => diag.severity === DiagnosticSeverity.Hint
(diag) => diag.severity === DiagnosticSeverity.Hint,
).length;
}

Expand Down
6 changes: 3 additions & 3 deletions packages/language-server/src/core/astro2tsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function safeConvertToTSX(content: string, options: ConvertToTSXOptions)
return tsx;
} catch (e) {
console.error(
`There was an error transforming ${options.filename} to TSX. An empty file will be returned instead. Please create an issue: https:/withastro/language-tools/issues\nError: ${e}.`
`There was an error transforming ${options.filename} to TSX. An empty file will be returned instead. Please create an issue: https:/withastro/language-tools/issues\nError: ${e}.`,
);

return {
Expand Down Expand Up @@ -71,11 +71,11 @@ export function getTSXRangesAsLSPRanges(tsx: TSXResult): LSPTSXRanges {
return {
frontmatter: Range.create(
textDocument.positionAt(tsx.metaRanges.frontmatter.start),
textDocument.positionAt(tsx.metaRanges.frontmatter.end)
textDocument.positionAt(tsx.metaRanges.frontmatter.end),
),
body: Range.create(
textDocument.positionAt(tsx.metaRanges.body.start),
textDocument.positionAt(tsx.metaRanges.body.end)
textDocument.positionAt(tsx.metaRanges.body.end),
),
scripts: tsx.metaRanges.scripts ?? [],
styles: tsx.metaRanges.styles ?? [],
Expand Down
20 changes: 10 additions & 10 deletions packages/language-server/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { extractScriptTags } from './parseJS.js';

export function getAstroLanguagePlugin(
astroInstall: AstroInstall | undefined,
ts: typeof import('typescript')
ts: typeof import('typescript'),
): LanguagePlugin<URI, AstroVirtualCode> {
return {
getLanguageId(uri) {
Expand Down Expand Up @@ -76,8 +76,8 @@ export function getAstroLanguagePlugin(
if (astroInstall) {
addedFileNames.push(
...['./env.d.ts', './astro-jsx.d.ts'].map((filePath) =>
ts.sys.resolvePath(path.resolve(astroInstall.path, filePath))
)
ts.sys.resolvePath(path.resolve(astroInstall.path, filePath)),
),
);

// If Astro version is < 4.0.8, add jsx-runtime-augment.d.ts to the files to fake `JSX` being available from "astro/jsx-runtime".
Expand All @@ -90,17 +90,17 @@ export function getAstroLanguagePlugin(
) {
addedFileNames.push(
...['./jsx-runtime-augment.d.ts'].map((filePath) =>
ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, filePath))
)
ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, filePath)),
),
);
}
} else {
// If we don't have an Astro installation, add the fallback types from the language server.
// See the README in packages/language-server/types for more information.
addedFileNames.push(
...['./env.d.ts', './astro-jsx.d.ts', './jsx-runtime-fallback.d.ts'].map((f) =>
ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, f))
)
ts.sys.resolvePath(path.resolve(languageServerTypesDirectory, f)),
),
);
}

Expand Down Expand Up @@ -141,7 +141,7 @@ export class AstroVirtualCode implements VirtualCode {

constructor(
public fileName: string,
public snapshot: ts.IScriptSnapshot
public snapshot: ts.IScriptSnapshot,
) {
this.mappings = [
{
Expand All @@ -162,14 +162,14 @@ export class AstroVirtualCode implements VirtualCode {
const tsx = astro2tsx(this.snapshot.getText(0, this.snapshot.getLength()), this.fileName);
const astroMetadata = getAstroMetadata(
this.fileName,
this.snapshot.getText(0, this.snapshot.getLength())
this.snapshot.getText(0, this.snapshot.getLength()),
);

const { htmlDocument, virtualCode: htmlVirtualCode } = parseHTML(
this.snapshot,
astroMetadata.frontmatter.status === 'closed'
? astroMetadata.frontmatter.position.end.offset
: 0
: 0,
);

this.htmlDocument = htmlDocument;
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/core/parseAstro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type AstroMetadata = ParseResult & {
export function getAstroMetadata(
fileName: string,
input: string,
options: ParseOptions = { position: true }
options: ParseOptions = { position: true },
): Omit<AstroMetadata, 'tsxRanges'> {
const parseResult = safeParseAst(fileName, input, options);

Expand All @@ -26,7 +26,7 @@ function safeParseAst(fileName: string, input: string, parseOptions: ParseOption
return parseResult;
} catch (e) {
console.error(
`There was an error parsing ${fileName}'s AST. An empty AST will be returned instead to avoid breaking the server. Please create an issue: https:/withastro/language-tools/issues\nError: ${e}.`
`There was an error parsing ${fileName}'s AST. An empty AST will be returned instead to avoid breaking the server. Please create an issue: https:/withastro/language-tools/issues\nError: ${e}.`,
);

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/core/parseHTML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const htmlLs = html.getLanguageService();

export function parseHTML(
snapshot: ts.IScriptSnapshot,
frontmatterEnd: number
frontmatterEnd: number,
): { virtualCode: VirtualCode; htmlDocument: html.HTMLDocument } {
const htmlContent = preprocessHTML(snapshot.getText(0, snapshot.getLength()), frontmatterEnd);

Expand All @@ -20,7 +20,7 @@ export function parseHTML(
const createScanner = htmlLs.createScanner as (
input: string,
initialOffset?: number,
initialState?: html.ScannerState
initialState?: html.ScannerState,
) => html.Scanner;

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/language-server/src/core/parseJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function extractScriptTags(scripts: TSXExtractedScript[]): VirtualCode[]
// TODO: Change this at some point so that unknown scripts are not included
// We can't guarantee that they are JavaScript, so we shouldn't treat them as such, even if it might work in some cases
// Perhaps we should make it so that the user has to specify the language of the script if it's not a known type (ex: lang="js"), not sure.
script.type === 'event-attribute' || script.type === 'inline' || script.type === 'unknown'
script.type === 'event-attribute' || script.type === 'inline' || script.type === 'unknown',
)
.sort((a, b) => a.position.start - b.position.start);

Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/core/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class SvelteVirtualCode implements VirtualCode {

constructor(
public fileName: string,
public snapshot: ts.IScriptSnapshot
public snapshot: ts.IScriptSnapshot,
) {
this.mappings = [];

this.embeddedCodes = [];
this.embeddedCodes.push(
framework2tsx(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'svelte')
framework2tsx(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'svelte'),
);
}
}
4 changes: 2 additions & 2 deletions packages/language-server/src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { importSvelteIntegration, importVueIntegration } from '../importPackage'
export function framework2tsx(
filePath: string,
sourceCode: string,
framework: 'vue' | 'svelte'
framework: 'vue' | 'svelte',
): VirtualCode {
const integrationEditorEntrypoint =
framework === 'vue' ? importVueIntegration(filePath) : importSvelteIntegration(filePath);
Expand Down Expand Up @@ -44,7 +44,7 @@ function toPascalCase(string: string) {
.replace(new RegExp(/[^\w\s]/, 'g'), '')
.replace(
new RegExp(/\s+(.)(\w*)/, 'g'),
($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`
($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`,
)
.replace(new RegExp(/\w/), (s) => s.toUpperCase());
}
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/core/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class VueVirtualCode implements VirtualCode {

constructor(
public fileName: string,
public snapshot: ts.IScriptSnapshot
public snapshot: ts.IScriptSnapshot,
) {
this.mappings = [];

this.embeddedCodes = [];
this.embeddedCodes.push(
framework2tsx(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'vue')
framework2tsx(this.fileName, this.snapshot.getText(0, this.snapshot.getLength()), 'vue'),
);
}
}
6 changes: 3 additions & 3 deletions packages/language-server/src/importPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function setIsTrusted(_isTrusted: boolean) {
export function getPackagePath(
packageName: string,
fromPath: string[],
root = true
root = true,
): string | undefined {
const paths = [];
if (isTrusted) {
Expand All @@ -43,14 +43,14 @@ function importEditorIntegration<T>(packageName: string, fromPath: string): T |
return require(main) as T;
} catch (e) {
console.error(
`Couldn't load editor module from ${pkgPath}. Make sure you're using at least version v0.2.1 of the corresponding integration. Reason: ${e}`
`Couldn't load editor module from ${pkgPath}. Make sure you're using at least version v0.2.1 of the corresponding integration. Reason: ${e}`,
);

return undefined;
}
} else {
console.info(
`Couldn't find package ${packageName} (searching from ${fromPath}). Make sure it's installed. If you believe this to be an error, please open an issue.`
`Couldn't find package ${packageName} (searching from ${fromPath}). Make sure it's installed. If you believe this to be an error, please open an issue.`,
);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/language-server/src/languageServerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getLanguagePlugins(
connection: Connection,
ts: typeof import('typescript'),
serviceEnv: LanguageServiceEnvironment,
tsconfig: string | undefined
tsconfig: string | undefined,
) {
const languagePlugins: LanguagePlugin<URI>[] = [
getVueLanguagePlugin(),
Expand All @@ -52,7 +52,7 @@ export function getLanguagePlugins(
}

languagePlugins.unshift(
getAstroLanguagePlugin(typeof astroInstall === 'string' ? undefined : astroInstall, ts)
getAstroLanguagePlugin(typeof astroInstall === 'string' ? undefined : astroInstall, ts),
);

return languagePlugins;
Expand Down Expand Up @@ -120,7 +120,7 @@ export function getLanguageServicePlugins(connection: Connection, ts: typeof imp

const editorOptions = await context.env.getConfiguration<object>?.(
'prettier',
document.uri
document.uri,
);

// Return a config with the following cascade:
Expand Down Expand Up @@ -153,7 +153,7 @@ export function getLanguageServicePlugins(connection: Connection, ts: typeof imp
return hasPluginLoadedAlready ? [] : [prettierPluginPath];
}
},
}
},
);
}
}
4 changes: 2 additions & 2 deletions packages/language-server/src/nodeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ connection.onInitialize((params) => {

if (!tsdk) {
throw new Error(
'The `typescript.tsdk` init option is required. It should point to a directory containing a `typescript.js` or `tsserverlibrary.js` file, such as `node_modules/typescript/lib`.'
'The `typescript.tsdk` init option is required. It should point to a directory containing a `typescript.js` or `tsserverlibrary.js` file, such as `node_modules/typescript/lib`.',
);
}

Expand All @@ -31,7 +31,7 @@ connection.onInitialize((params) => {
};
}),
getLanguageServicePlugins(connection, typescript),
{ pullModelDiagnostics: params.initializationOptions?.pullModelDiagnostics }
{ pullModelDiagnostics: params.initializationOptions?.pullModelDiagnostics },
);
});

Expand Down
8 changes: 4 additions & 4 deletions packages/language-server/src/plugins/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin =

const { uriConverter } = context.project.typescript;
const languageService = context.inject<Provide, 'typescript/languageService'>(
'typescript/languageService'
'typescript/languageService',
);
if (!languageService) return;

Expand All @@ -102,8 +102,8 @@ export const create = (ts: typeof import('typescript')): LanguageServicePlugin =
getGlobResultAsCodeLens(
globArgument.getText().slice(1, -1),
dirname(uriConverter.asFileName(decoded[0])),
document.positionAt(node.arguments.pos)
)
document.positionAt(node.arguments.pos),
),
);
}
}
Expand Down Expand Up @@ -135,7 +135,7 @@ function getGlobResultAsCodeLens(globText: string, dir: string, position: Positi
function getFrontmatterCompletion(
file: AstroVirtualCode,
document: TextDocument,
position: Position
position: Position,
) {
const base: CompletionItem = {
kind: CompletionItemKind.Snippet,
Expand Down
4 changes: 2 additions & 2 deletions packages/language-server/src/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const create = (): LanguageServicePlugin => {
document,
position,
completionContext,
token
token,
);

if (!completions) {
Expand All @@ -66,7 +66,7 @@ export const create = (): LanguageServicePlugin => {

// We don't want completions for file references, as they're mostly invalid for Astro
completions.items = completions.items.filter(
(completion) => completion.kind !== CompletionItemKind.File
(completion) => completion.kind !== CompletionItemKind.File,
);

return completions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mapEdit } from './utils.js';

export function enhancedProvideCodeActions(
codeActions: CodeAction[],
context: LanguageServiceContext
context: LanguageServiceContext,
) {
return codeActions.map((codeAction) => mapCodeAction(codeAction, context));
}
Expand Down
Loading

0 comments on commit 1172836

Please sign in to comment.