[tests] Add prettier check (#9664)

This PR fixes the formatting on several files that were never run through `prettier`.

It also makes sure to run `prettier` in CI to to [fail fast](https://github.com/vercel/vercel/actions/runs/4408442998/jobs/7723453978) when the incorrect formatting is attempted.
This commit is contained in:
Steven
2023-03-13 15:55:59 -04:00
committed by GitHub
parent 7ec377757d
commit bada86b8d6
38 changed files with 172 additions and 140 deletions

View File

@@ -32,3 +32,4 @@ jobs:
run: npm i -g pnpm@7.24.2 run: npm i -g pnpm@7.24.2
- run: pnpm install - run: pnpm install
- run: pnpm run lint - run: pnpm run lint
- run: pnpm run prettier-check

View File

@@ -5,7 +5,7 @@ on:
inputs: inputs:
new-version: new-version:
type: string type: string
description: "Optional version to update @remix-run/dev to inside of @vercel/remix" description: 'Optional version to update @remix-run/dev to inside of @vercel/remix'
jobs: jobs:
update-remix-run-dev: update-remix-run-dev:

View File

@@ -7,3 +7,28 @@ examples/sveltekit-1
# gatsby-plugin-vercel-analytics # gatsby-plugin-vercel-analytics
packages/gatsby-plugin-vercel-analytics packages/gatsby-plugin-vercel-analytics
# ignore directories that are not source code
node_modules
dist
pnpm-lock.yaml
.vscode
.DS_Store
.next
.vercel
.turbo
.eslintcache
.output
.vercel_build_output
.vercel
coverage
turbo-cache-key.json
/examples
/public
packages/*/dist
packages/*/node_modules
packages/**/test/fixtures
packages/**/test/dev/fixtures
packages/**/test/build-fixtures
packages/**/test/cache-fixtures

View File

@@ -87,7 +87,10 @@ future builds.
import { relative } from 'path'; import { relative } from 'path';
import { glob, PrepareCache } from '@vercel/build-utils'; import { glob, PrepareCache } from '@vercel/build-utils';
export const prepareCache: PrepareCache = async ({ workPath, repoRootPath }) => { export const prepareCache: PrepareCache = async ({
workPath,
repoRootPath,
}) => {
// Create a mapping of file names and `File` object instances to cache here… // Create a mapping of file names and `File` object instances to cache here…
const rootDirectory = relative(repoRootPath, workPath); const rootDirectory = relative(repoRootPath, workPath);
const cache = await glob(`${rootDirectory}/some/dir/**`, repoRootPath); const cache = await glob(`${rootDirectory}/some/dir/**`, repoRootPath);

View File

@@ -51,8 +51,11 @@ export async function getGitHubRepoInfo(repo: Repo) {
data.subdir = repo.path.slice(subdirPath.length).split('/'); data.subdir = repo.path.slice(subdirPath.length).split('/');
} }
if (data.id === 'vercel/vercel' && data.subdir && data.subdir[0] === 'examples') { if (
data.id === 'vercel/vercel' &&
data.subdir &&
data.subdir[0] === 'examples'
) {
// from our examples, add `homepage` and `description` fields // from our examples, add `homepage` and `description` fields
const example = data.subdir[1]; const example = data.subdir[1];
const exampleList = await getExampleList(); const exampleList = await getExampleList();

View File

@@ -1,10 +0,0 @@
codecov:
require_ci_to_pass: yes
coverage:
status:
project: off
patch: off
fixes:
- "::packages/cli/" # move root e.g., "path/" => "after/path/"

View File

@@ -51,6 +51,7 @@
"test-e2e": "node utils/gen.js && turbo run test-e2e", "test-e2e": "node utils/gen.js && turbo run test-e2e",
"test-dev": "node utils/gen.js && turbo run test-dev", "test-dev": "node utils/gen.js && turbo run test-dev",
"lint": "eslint . --cache --ext .ts,.js", "lint": "eslint . --cache --ext .ts,.js",
"prettier-check": "prettier --check .",
"prepare": "husky install", "prepare": "husky install",
"pack": "cd utils && node -r ts-eager/register ./pack.ts" "pack": "cd utils && node -r ts-eager/register ./pack.ts"
}, },

View File

@@ -36,9 +36,7 @@ async function main() {
const def = await readFile(fnPath.replace(/\.js$/, '.tsdef'), 'utf8'); const def = await readFile(fnPath.replace(/\.js$/, '.tsdef'), 'utf8');
const interfaceName = def.match(/interface (\w+)/)[1]; const interfaceName = def.match(/interface (\w+)/)[1];
const lines = require(fnPath) const lines = require(fnPath).toString().split('\n');
.toString()
.split('\n');
let errorHtmlStart = -1; let errorHtmlStart = -1;
let errorHtmlEnd = -1; let errorHtmlEnd = -1;
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {

View File

@@ -1,5 +1,9 @@
import chalk from 'chalk'; import chalk from 'chalk';
import { ProjectEnvTarget, Project, ProjectEnvType } from '@vercel-internals/types'; import {
ProjectEnvTarget,
Project,
ProjectEnvType,
} from '@vercel-internals/types';
import { Output } from '../../util/output'; import { Output } from '../../util/output';
import Client from '../../util/client'; import Client from '../../util/client';
import stamp from '../../util/output/stamp'; import stamp from '../../util/output/stamp';

View File

@@ -1,7 +1,11 @@
import chalk from 'chalk'; import chalk from 'chalk';
import ms from 'ms'; import ms from 'ms';
import { Output } from '../../util/output'; import { Output } from '../../util/output';
import { Project, ProjectEnvVariable, ProjectEnvType } from '@vercel-internals/types'; import {
Project,
ProjectEnvVariable,
ProjectEnvType,
} from '@vercel-internals/types';
import Client from '../../util/client'; import Client from '../../util/client';
import formatTable from '../../util/format-table'; import formatTable from '../../util/format-table';
import getEnvRecords from '../../util/env/get-env-records'; import getEnvRecords from '../../util/env/get-env-records';

View File

@@ -20,10 +20,7 @@ export default function getWildcardCNSForAlias(alias: string) {
const secondLevel = const secondLevel =
subdomain && subdomain.includes('.') subdomain && subdomain.includes('.')
? subdomain ? subdomain.split('.').slice(1).join('.')
.split('.')
.slice(1)
.join('.')
: null; : null;
const root = secondLevel ? `${secondLevel}.${domain}` : domain; const root = secondLevel ? `${secondLevel}.${domain}` : domain;

View File

@@ -4,7 +4,7 @@ export default function createPollingFn<R>(
future: (...args: any[]) => Promise<R>, future: (...args: any[]) => Promise<R>,
sleepTime: number sleepTime: number
) { ) {
return async function*(...args: any[]) { return async function* (...args: any[]) {
while (true) { while (true) {
yield await future(...args); yield await future(...args);
await sleep(sleepTime); await sleep(sleepTime);

View File

@@ -8,7 +8,7 @@ export default async function deleteDNSRecordById(
return client.fetch( return client.fetch(
`/v3/domains/${encodeURIComponent(domain)}/records/${recordId}`, `/v3/domains/${encodeURIComponent(domain)}/records/${recordId}`,
{ {
method: 'DELETE' method: 'DELETE',
} }
); );
} }

View File

@@ -11,7 +11,7 @@ export default function parseAddArgs(
if (domain && rest.length === 0) { if (domain && rest.length === 0) {
return { return {
domain, domain,
data: null data: null,
}; };
} }
@@ -26,7 +26,7 @@ export default function parseAddArgs(
if (type === 'MX' && args.length === 5) { if (type === 'MX' && args.length === 5) {
return { return {
domain, domain,
data: { name, type, value, mxPriority: Number(args[4]) } data: { name, type, value, mxPriority: Number(args[4]) },
}; };
} }
@@ -40,9 +40,9 @@ export default function parseAddArgs(
priority: Number(value), priority: Number(value),
weight: Number(args[4]), weight: Number(args[4]),
port: Number(args[5]), port: Number(args[5]),
target: args[6] target: args[6],
} },
} },
}; };
} }
@@ -52,8 +52,8 @@ export default function parseAddArgs(
data: { data: {
name, name,
type, type,
value value,
} },
}; };
} }

View File

@@ -6,7 +6,7 @@ export default async function getAuthCode(code?: string) {
} }
return textInput({ return textInput({
label: `- Transfer auth code: `, label: `- Transfer auth code: `,
validateValue: isValidAuthCode validateValue: isValidAuthCode,
}); });
} }

View File

@@ -11,6 +11,6 @@ export default function formatDNSTable(
return table([HEADER, ...rows], { return table([HEADER, ...rows], {
align: ['l', 'l', 'l'], align: ['l', 'l', 'l'],
hsep: ' '.repeat(8), hsep: ' '.repeat(8),
stringLength: strlen stringLength: strlen,
}).replace(/^(.*)/gm, `${extraSpace}$1`); }).replace(/^(.*)/gm, `${extraSpace}$1`);
} }

View File

@@ -22,19 +22,23 @@ export default function formatNSTable(
sortedCurrent[i] || chalk.gray('-'), sortedCurrent[i] || chalk.gray('-'),
sortedIntended[i] === sortedCurrent[i] sortedIntended[i] === sortedCurrent[i]
? chalk.green(chars.tick) ? chalk.green(chars.tick)
: chalk.red(chars.cross) : chalk.red(chars.cross),
]); ]);
} }
return table( return table(
[ [
[chalk.gray('Intended Nameservers'), chalk.gray('Current Nameservers'), ''], [
...rows chalk.gray('Intended Nameservers'),
chalk.gray('Current Nameservers'),
'',
],
...rows,
], ],
{ {
align: ['l', 'l', 'l', 'l'], align: ['l', 'l', 'l', 'l'],
hsep: ' '.repeat(4), hsep: ' '.repeat(4),
stringLength: strlen stringLength: strlen,
} }
).replace(/^(.*)/gm, `${extraSpace}$1`); ).replace(/^(.*)/gm, `${extraSpace}$1`);
} }

View File

@@ -7,4 +7,3 @@ export function getDistTag(version: string): string {
} }
return 'latest'; return 'latest';
} }

View File

@@ -14,7 +14,9 @@ export function getPaginationOpts(opts: PaginationOptions) {
typeof limit === 'number' && typeof limit === 'number' &&
(!Number.isInteger(limit) || limit > 100 || limit < 1) (!Number.isInteger(limit) || limit > 100 || limit < 1)
) { ) {
throw new Error('Please provide an integer from 1 to 100 for option --limit'); throw new Error(
'Please provide an integer from 1 to 100 for option --limit'
);
} }
return [nextTimestamp, limit]; return [nextTimestamp, limit];

View File

@@ -14,6 +14,6 @@ export default function getSubcommand(
} }
return { return {
subcommand: config.default, subcommand: config.default,
args: cliArgs args: cliArgs,
}; };
} }

View File

@@ -11,7 +11,7 @@ function didYouMean(input: string, list: string[], threshold: number = 0.5) {
const found = rated.filter(item => item[0] > threshold); const found = rated.filter(item => item[0] > threshold);
if (found.length) { if (found.length) {
const highestRated = found.reduce((accu, curr) => { const highestRated = found.reduce((accu, curr) => {
return accu[0] > curr[0] ? accu : curr return accu[0] > curr[0] ? accu : curr;
}); });
return highestRated[1]; return highestRated[1];
} }
@@ -23,6 +23,7 @@ function didYouMean(input: string, list: string[], threshold: number = 0.5) {
function dashAwareDistance(word: string, dashWord: string) { function dashAwareDistance(word: string, dashWord: string) {
const fullDistance = distance(word, dashWord); const fullDistance = distance(word, dashWord);
const distances = dashWord.split('-').map(w => distance(w, word)); const distances = dashWord.split('-').map(w => distance(w, word));
const meanDistance = distances.reduce((accu, curr) => accu + curr) / distances.length; const meanDistance =
distances.reduce((accu, curr) => accu + curr) / distances.length;
return fullDistance > meanDistance ? fullDistance : meanDistance; return fullDistance > meanDistance ? fullDistance : meanDistance;
} }

View File

@@ -5,7 +5,7 @@ export class NowError<C, Meta> extends Error {
constructor({ constructor({
code, code,
message, message,
meta meta,
}: { }: {
code: C; code: C;
message: string; message: string;

View File

@@ -1,5 +1,5 @@
import chalk from 'chalk'; import chalk from 'chalk';
export default function success (msg: string): string { export default function success(msg: string): string {
return `${chalk.cyan('> Success!')} ${msg}`; return `${chalk.cyan('> Success!')} ${msg}`;
} }

View File

@@ -6,7 +6,7 @@ export default async function* raceAsyncGenerators(...args: any[]) {
yield new Promise(resolve => { yield new Promise(resolve => {
let resolved = false; let resolved = false;
nextPromises.forEach((nextPromise, idx) => { nextPromises.forEach((nextPromise, idx) => {
nextPromise.then(({ value, done }: { value: any, done: boolean }) => { nextPromise.then(({ value, done }: { value: any; done: boolean }) => {
if (!resolved) { if (!resolved) {
resolved = true; resolved = true;
resolve(value); resolve(value);
@@ -15,7 +15,7 @@ export default async function* raceAsyncGenerators(...args: any[]) {
} else { } else {
nextPromises = [ nextPromises = [
...nextPromises.slice(0, idx), ...nextPromises.slice(0, idx),
...nextPromises.slice(idx + 1) ...nextPromises.slice(idx + 1),
]; ];
} }
} }

View File

@@ -30,7 +30,7 @@ export async function readConfigFile<T>(
if (name.endsWith('.json')) { if (name.endsWith('.json')) {
return JSON.parse(str) as T; return JSON.parse(str) as T;
} else if (name.endsWith('.toml')) { } else if (name.endsWith('.toml')) {
return (toml.parse(str) as unknown) as T; return toml.parse(str) as unknown as T;
} else if (name.endsWith('.yaml') || name.endsWith('.yml')) { } else if (name.endsWith('.yaml') || name.endsWith('.yml')) {
return yaml.safeLoad(str, { filename: name }) as T; return yaml.safeLoad(str, { filename: name }) as T;
} }

View File

@@ -1,16 +1,11 @@
import type { NextPage } from 'next' import type { NextPage } from 'next';
const Home: NextPage = () => { const Home: NextPage = () => {
return ( return <div>Home</div>;
<div> };
Home
</div>
)
}
export default Home
export default Home;
export const config = { export const config = {
runtime: 'experimental-edge', runtime: 'experimental-edge',
} };

View File

@@ -22,9 +22,11 @@ function getBuilderRoutesMapping(builds: Build[]) {
return builderRoutes; return builderRoutes;
} }
function getCheckAndContinue( function getCheckAndContinue(routes: Route[]): {
routes: Route[] checks: Route[];
): { checks: Route[]; continues: Route[]; others: Route[] } { continues: Route[];
others: Route[];
} {
const checks: Route[] = []; const checks: Route[] = [];
const continues: Route[] = []; const continues: Route[] = [];
const others: Route[] = []; const others: Route[] = [];

View File

@@ -3,7 +3,10 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const ajv = new Ajv(); const ajv = new Ajv();
export function validate<T extends JSONSchema>(schema: T, data: any): FromSchema<T> { export function validate<T extends JSONSchema>(
schema: T,
data: any
): FromSchema<T> {
const isValid = ajv.compile(schema); const isValid = ajv.compile(schema);
if (!isValid(data)) { if (!isValid(data)) {
// TODO: better error message // TODO: better error message

View File

@@ -1,11 +1,11 @@
const retry = require('async-retry'); const retry = require('async-retry');
function canRetry (error) { function canRetry(error) {
error.dontBail = true; error.dontBail = true;
return error; return error;
} }
async function retryBailByDefault (fn, opts) { async function retryBailByDefault(fn, opts) {
return await retry(async () => { return await retry(async () => {
try { try {
return await fn(canRetry); return await fn(canRetry);