[ci] yarn format
This commit is contained in:
parent
dbd2f5076b
commit
b1b564d03d
3 changed files with 23 additions and 31 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue