summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/src/pages/reference/cli-reference.md2
-rw-r--r--packages/astro/src/check.ts50
-rw-r--r--packages/astro/src/cli.ts2
3 files changed, 23 insertions, 31 deletions
diff --git a/docs/src/pages/reference/cli-reference.md b/docs/src/pages/reference/cli-reference.md
index 26b165f48..0665b35a0 100644
--- a/docs/src/pages/reference/cli-reference.md
+++ b/docs/src/pages/reference/cli-reference.md
@@ -27,7 +27,7 @@ This command is meant for local testing only, and is not designed to be run in p
### `astro check`
-Runs diagnostics (such as type-checking) against your project and reports errors to the console. If any errors are found the process will exit with a code of __1__.
+Runs diagnostics (such as type-checking) against your project and reports errors to the console. If any errors are found the process will exit with a code of **1**.
This command is intended to be used in CI workflows.
diff --git a/packages/astro/src/check.ts b/packages/astro/src/check.ts
index 22bccd4f9..6df689d35 100644
--- a/packages/astro/src/check.ts
+++ b/packages/astro/src/check.ts
@@ -7,25 +7,19 @@ import * as path from 'path';
import { pathToFileURL } from 'url';
import * as fs from 'fs';
-async function openAllDocuments(
- workspaceUri: URL,
- filePathsToIgnore: string[],
- checker: AstroCheck
-) {
+async function openAllDocuments(workspaceUri: URL, filePathsToIgnore: string[], checker: AstroCheck) {
const files = await glob('**/*.astro', {
- cwd: workspaceUri.pathname,
- ignore: ['node_modules/**'].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`))
+ cwd: workspaceUri.pathname,
+ ignore: ['node_modules/**'].concat(filePathsToIgnore.map((ignore) => `${ignore}/**`)),
});
const absFilePaths = files.map((f) => path.resolve(workspaceUri.pathname, f));
for (const absFilePath of absFilePaths) {
- const text = fs.readFileSync(absFilePath, 'utf-8');
- checker.upsertDocument(
- {
- uri: pathToFileURL(absFilePath).toString(),
- text
- }
- );
+ const text = fs.readFileSync(absFilePath, 'utf-8');
+ checker.upsertDocument({
+ uri: pathToFileURL(absFilePath).toString(),
+ text,
+ });
}
}
@@ -34,17 +28,17 @@ interface Result {
warnings: number;
}
-function offsetAt({ line, character }: { line: number, character: number; }, text: string) {
+function offsetAt({ line, character }: { line: number; character: number }, text: string) {
let i = 0;
let l = 0;
let c = 0;
- while(i < text.length) {
- if(l === line && c === character) {
+ while (i < text.length) {
+ if (l === line && c === character) {
break;
}
let char = text[i];
- switch(char) {
+ switch (char) {
case '\n': {
l++;
c = 0;
@@ -66,9 +60,7 @@ function pad(str: string, len: number) {
return Array.from({ length: len }, () => str).join('');
}
-export async function run() {
-
-}
+export async function run() {}
export async function check(astroConfig: AstroConfig) {
const root = astroConfig.projectRoot;
@@ -79,18 +71,18 @@ export async function check(astroConfig: AstroConfig) {
let result: Result = {
errors: 0,
- warnings: 0
+ warnings: 0,
};
- diagnostics.forEach(diag => {
- diag.diagnostics.forEach(d => {
- switch(d.severity) {
+ diagnostics.forEach((diag) => {
+ diag.diagnostics.forEach((d) => {
+ switch (d.severity) {
case DiagnosticSeverity.Error: {
console.error(`${bold(cyan(path.relative(root.pathname, diag.filePath)))}:${bold(yellow(d.range.start.line))}:${bold(yellow(d.range.start.character))} - ${d.message}`);
let startOffset = offsetAt({ line: d.range.start.line, character: 0 }, diag.text);
let endOffset = offsetAt({ line: d.range.start.line + 1, character: 0 }, diag.text);
let str = diag.text.substring(startOffset, endOffset - 1);
- const lineNumStr = (d.range.start.line).toString();
+ const lineNumStr = d.range.start.line.toString();
const lineNumLen = lineNumStr.length;
console.error(`${bgWhite(black(lineNumStr))} ${str}`);
let tildes = pad('~', d.range.end.character - d.range.start.character);
@@ -107,10 +99,10 @@ export async function check(astroConfig: AstroConfig) {
});
});
- if(result.errors) {
- console.error(`Found ${result.errors} errors.`)
+ if (result.errors) {
+ console.error(`Found ${result.errors} errors.`);
}
const exitCode = result.errors ? 1 : 0;
return exitCode;
-} \ No newline at end of file
+}
diff --git a/packages/astro/src/cli.ts b/packages/astro/src/cli.ts
index d49381520..5c82f3af4 100644
--- a/packages/astro/src/cli.ts
+++ b/packages/astro/src/cli.ts
@@ -134,7 +134,7 @@ const cmdMap = new Map<string, (a: AstroConfig, opts?: any) => Promise<any>>([
['dev', devServer],
['preview', preview],
['reload', reloadAndExit],
- ['check', checkAndExit]
+ ['check', checkAndExit],
]);
/** The primary CLI action */