[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

@@ -16,7 +16,7 @@ jobs:
issue-number: ${{ github.event.issue.number }}
body: |
Thank you for taking the time to created this request!
We added it to our backlog but need to discuss design/architecture before we can accept a PR.
Please let us know if you would be interested in sending a PR once we approve the design.

View File

@@ -16,9 +16,9 @@ jobs:
issue-number: ${{ github.event.issue.number }}
comment: |
Thank you so much for filing this issue.
We do try to keep issues in this repository focused on the vercel command line and related code.
At this point we think that this issue is best handled by our friendly Vercel support team. They can be found by contacting them at: https://vercel.com/help#issues
If you think closing of this is a mistake, then please re-open this issue and we'll take another look :bow:

View File

@@ -16,9 +16,9 @@ jobs:
issue-number: ${{ github.event.issue.number }}
body: |
Thank you for taking the time to file this issue!
We have confirmed this is a bug and added it to our backlog.
We don't have a timeline for when this issue will be fixed, but we will accept a Pull Request with a fix and a test.
See the [contributing guidelines](https://github.com/vercel/vercel/blob/main/.github/CONTRIBUTING.md) for more info.

View File

@@ -3,9 +3,9 @@ name: Publish
on:
push:
branches:
- main
- main
tags:
- '!*'
- '!*'
env:
TURBO_REMOTE_ONLY: 'true'
@@ -17,50 +17,50 @@ jobs:
name: Publish
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check Release
id: check-release
run: |
tag="$(git describe --tags --exact-match 2> /dev/null || :)"
if [[ -z "$tag" ]];
then
echo "IS_RELEASE=false" >> $GITHUB_OUTPUT
else
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
fi
- name: Setup Go
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
uses: actions/setup-go@v3
with:
go-version: '1.13.15'
- name: Setup Node
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
uses: actions/setup-node@v3
with:
node-version: 16
- name: install npm@9
run: npm i -g npm@9
- name: install pnpm@7.24.2
run: npm i -g pnpm@7.24.2
- name: Install
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
run: pnpm install
- name: Build
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
run: pnpm build
env:
GA_TRACKING_ID: ${{ secrets.GA_TRACKING_ID }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Publish
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
run: pnpm publish-from-github
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}
GA_TRACKING_ID: ${{ secrets.GA_TRACKING_ID }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check Release
id: check-release
run: |
tag="$(git describe --tags --exact-match 2> /dev/null || :)"
if [[ -z "$tag" ]];
then
echo "IS_RELEASE=false" >> $GITHUB_OUTPUT
else
echo "IS_RELEASE=true" >> $GITHUB_OUTPUT
fi
- name: Setup Go
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
uses: actions/setup-go@v3
with:
go-version: '1.13.15'
- name: Setup Node
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
uses: actions/setup-node@v3
with:
node-version: 16
- name: install npm@9
run: npm i -g npm@9
- name: install pnpm@7.24.2
run: npm i -g pnpm@7.24.2
- name: Install
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
run: pnpm install
- name: Build
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
run: pnpm build
env:
GA_TRACKING_ID: ${{ secrets.GA_TRACKING_ID }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
- name: Publish
if: ${{ steps.check-release.outputs.IS_RELEASE == 'true' }}
run: pnpm publish-from-github
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}
GA_TRACKING_ID: ${{ secrets.GA_TRACKING_ID }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}

View File

@@ -3,9 +3,9 @@ name: CLI
on:
push:
branches:
- main
- main
tags:
- '!*'
- '!*'
pull_request:
env:

View File

@@ -3,9 +3,9 @@ name: Lint
on:
push:
branches:
- main
- main
tags:
- '!*'
- '!*'
pull_request:
env:
@@ -32,3 +32,4 @@ jobs:
run: npm i -g pnpm@7.24.2
- run: pnpm install
- run: pnpm run lint
- run: pnpm run prettier-check

View File

@@ -3,9 +3,9 @@ name: Tests
on:
push:
branches:
- main
- main
tags:
- '!*'
- '!*'
pull_request:
env:

View File

@@ -5,7 +5,7 @@ on:
inputs:
new-version:
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:
update-remix-run-dev:

View File

@@ -7,3 +7,28 @@ examples/sveltekit-1
# 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 { 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…
const rootDirectory = relative(repoRootPath, workPath);
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('/');
}
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
const example = data.subdir[1];
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-dev": "node utils/gen.js && turbo run test-dev",
"lint": "eslint . --cache --ext .ts,.js",
"prettier-check": "prettier --check .",
"prepare": "husky install",
"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 interfaceName = def.match(/interface (\w+)/)[1];
const lines = require(fnPath)
.toString()
.split('\n');
const lines = require(fnPath).toString().split('\n');
let errorHtmlStart = -1;
let errorHtmlEnd = -1;
for (let i = 0; i < lines.length; i++) {

View File

@@ -1,5 +1,9 @@
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 Client from '../../util/client';
import stamp from '../../util/output/stamp';

View File

@@ -1,7 +1,11 @@
import chalk from 'chalk';
import ms from 'ms';
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 formatTable from '../../util/format-table';
import getEnvRecords from '../../util/env/get-env-records';

View File

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

View File

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

View File

@@ -8,7 +8,7 @@ export default async function deleteDNSRecordById(
return client.fetch(
`/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) {
return {
domain,
data: null
data: null,
};
}
@@ -26,7 +26,7 @@ export default function parseAddArgs(
if (type === 'MX' && args.length === 5) {
return {
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),
weight: Number(args[4]),
port: Number(args[5]),
target: args[6]
}
}
target: args[6],
},
},
};
}
@@ -52,8 +52,8 @@ export default function parseAddArgs(
data: {
name,
type,
value
}
value,
},
};
}

View File

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

View File

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

View File

@@ -22,19 +22,23 @@ export default function formatNSTable(
sortedCurrent[i] || chalk.gray('-'),
sortedIntended[i] === sortedCurrent[i]
? chalk.green(chars.tick)
: chalk.red(chars.cross)
: chalk.red(chars.cross),
]);
}
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'],
hsep: ' '.repeat(4),
stringLength: strlen
stringLength: strlen,
}
).replace(/^(.*)/gm, `${extraSpace}$1`);
}

View File

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

View File

@@ -14,7 +14,9 @@ export function getPaginationOpts(opts: PaginationOptions) {
typeof limit === 'number' &&
(!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];

View File

@@ -14,6 +14,6 @@ export default function getSubcommand(
}
return {
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);
if (found.length) {
const highestRated = found.reduce((accu, curr) => {
return accu[0] > curr[0] ? accu : curr
return accu[0] > curr[0] ? accu : curr;
});
return highestRated[1];
}
@@ -23,6 +23,7 @@ function didYouMean(input: string, list: string[], threshold: number = 0.5) {
function dashAwareDistance(word: string, dashWord: string) {
const fullDistance = distance(word, dashWord);
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;
}

View File

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

View File

@@ -2,4 +2,4 @@ import chalk from 'chalk';
export default function highlight(text: string): string {
return chalk.bold.underline(text);
}
}

View File

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

View File

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

View File

@@ -30,19 +30,19 @@ export interface Deployment {
public: boolean;
ownerId: string;
readyState:
| 'INITIALIZING'
| 'ANALYZING'
| 'BUILDING'
| 'DEPLOYING'
| 'READY'
| 'ERROR';
| 'INITIALIZING'
| 'ANALYZING'
| 'BUILDING'
| 'DEPLOYING'
| 'READY'
| 'ERROR';
state?:
| 'INITIALIZING'
| 'ANALYZING'
| 'BUILDING'
| 'DEPLOYING'
| 'READY'
| 'ERROR';
| 'INITIALIZING'
| 'ANALYZING'
| 'BUILDING'
| 'DEPLOYING'
| 'READY'
| 'ERROR';
createdAt: string;
createdIn: string;
env: {

View File

@@ -30,7 +30,7 @@ export async function readConfigFile<T>(
if (name.endsWith('.json')) {
return JSON.parse(str) as T;
} 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')) {
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 = () => {
return (
<div>
Home
</div>
)
}
export default Home
return <div>Home</div>;
};
export default Home;
export const config = {
runtime: 'experimental-edge',
}
};

View File

@@ -1,4 +1,4 @@
const babel = require('@babel/core'); // eslint-disable-line @typescript-eslint/no-var-requires
const babel = require('@babel/core'); // eslint-disable-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires
const pluginTransformModulesCommonJs = require('@babel/plugin-transform-modules-commonjs');

View File

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

View File

@@ -3,7 +3,10 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
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);
if (!isValid(data)) {
// TODO: better error message

View File

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