Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding formatting on save for ts files #24646

Merged
merged 8 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"typescript.tsdk": "node_modules\\typescript\\lib",
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
mikeharder marked this conversation as resolved.
Show resolved Hide resolved
"editor.formatOnSave": true
}
30 changes: 15 additions & 15 deletions eng/tools/TypeSpecValidation/src/TypeSpecValidation.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {exec} from "child_process";
ckairen marked this conversation as resolved.
Show resolved Hide resolved
import {access} from "fs/promises"
import {parseArgs, ParseArgsConfig} from 'node:util';
import { exec } from "child_process";
import { access } from "fs/promises"
import { parseArgs, ParseArgsConfig } from 'node:util';
import path from "path";
import {simpleGit} from 'simple-git';
import { simpleGit } from 'simple-git';

async function runCmd(cmd:string, cwd:string) {
async function runCmd(cmd: string, cwd: string) {
console.log(`run command:${cmd}`)
const { err, stdout, stderr } = await new Promise((res) =>
exec(
cmd,
{ encoding: "utf8", maxBuffer: 1024 * 1024 * 64, cwd: cwd},
(err: unknown, stdout: unknown, stderr: unknown) =>
res({ err: err, stdout: stdout, stderr: stderr })
cmd,
{ encoding: "utf8", maxBuffer: 1024 * 1024 * 64, cwd: cwd },
(err: unknown, stdout: unknown, stderr: unknown) =>
res({ err: err, stdout: stdout, stderr: stderr })
)
) as any;
let resultString = stderr + stdout;
Expand All @@ -27,21 +27,21 @@ async function runCmd(cmd:string, cwd:string) {
return resultString as string;
}

async function checkFileExists(file:string) {
async function checkFileExists(file: string) {
return access(file)
.then(() => true)
.catch(() => false)
}

export async function main() {
const args = process.argv.slice(2);
const options = {
folder: {
type: 'string',
short: 'f',
type: 'string',
short: 'f',
},
};
const parsedArgs = parseArgs({ args, options, allowPositionals: true} as ParseArgsConfig);
const parsedArgs = parseArgs({ args, options, allowPositionals: true } as ParseArgsConfig);
const folder = parsedArgs.positionals[0];
console.log("Running TypeSpecValidation on folder:", folder);

Expand All @@ -50,7 +50,7 @@ export async function main() {
const actual_npm_prefix = (await runCmd(`npm prefix`, folder)).trim()
if (expected_npm_prefix !== actual_npm_prefix) {
console.log("ERROR: TypeSpec folders MUST NOT contain a package.json, and instead MUST rely on the package.json at repo root.")
throw new Error ("Expected npm prefix: " + expected_npm_prefix +"\nActual npm prefix: " + actual_npm_prefix)
throw new Error("Expected npm prefix: " + expected_npm_prefix + "\nActual npm prefix: " + actual_npm_prefix)
}

// Spec compilation check
Expand Down