Skip to content

Commit

Permalink
Update prettier config to format trailing commas to all (Default) (#…
Browse files Browse the repository at this point in the history
…4457)

fix #2159 
Long standing backlog issue that was split from an upgrade of prettier
as it created too much diff. Finally doing it
  • Loading branch information
timotheeguerin authored Sep 16, 2024
1 parent 9a65543 commit a336c93
Show file tree
Hide file tree
Showing 482 changed files with 3,821 additions and 3,792 deletions.
26 changes: 26 additions & 0 deletions .chronus/changes/format-trailling-commas-2024-8-16-18-56-35.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@typespec/bundler"
- "@typespec/compiler"
- "@typespec/eslint-plugin"
- "@typespec/html-program-viewer"
- "@typespec/http-server-csharp"
- "@typespec/http-server-javascript"
- "@typespec/http"
- "@typespec/internal-build-utils"
- "@typespec/json-schema"
- "@typespec/library-linter"
- "@typespec/openapi"
- "@typespec/openapi3"
- "@typespec/playground"
- "@typespec/protobuf"
- "@typespec/rest"
- typespec-vs
- typespec-vscode
- "@typespec/versioning"
- "@typespec/xml"
---

Update prettier config to format trailing commas to `all` (Default)
1 change: 0 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"arrowParens": "always",
"trailingComma": "es5",
"bracketSpacing": true,
"endOfLine": "lf",
"printWidth": 100,
Expand Down
2 changes: 1 addition & 1 deletion docs/extending-typespec/codefixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe("CodeFix: change-identifier", () => {
(node) => {
strictEqual(node.kind, SyntaxKind.Identifier);
return createChangeIdentifierCodeFix(node, "int32");
}
},
).toChangeTo(`
model Foo {
a: int32;
Expand Down
4 changes: 2 additions & 2 deletions docs/extending-typespec/diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function getRoutes(): [Route, readonly Diagnostic] {
createDiagnostic(program, {
code: "no-array",
target: diagnosticTarget,
})
}),
);
const result = diagnostic.pipe(getParameters()); // to pipe diagnostics returned by `getParameters`
return diagnostics.wrap(routes);
Expand All @@ -125,7 +125,7 @@ function getRoutes(): [Route, readonly Diagnostic] {
createDiagnostic(program, {
code: "no-array",
target: diagnosticTarget,
})
}),
);
return [routes, diagnostics];
}
Expand Down
4 changes: 2 additions & 2 deletions docs/extending-typespec/emitter-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MyCodeEmitter extends CodeTypeEmitter {

modelPropertyLiteral(property: ModelProperty): EmitterOutput<string> {
return code`a property named ${property.name} and a type of ${this.emitter.emitType(
property.type
property.type,
)}`;
}

Expand Down Expand Up @@ -243,7 +243,7 @@ class MyCodeEmitter extends CodeTypeEmitter {
targetDeclaration: Declaration<string>,
pathUp: Scope<string>[],
pathDown: Scope<string>[],
commonScope: Scope<string> | null
commonScope: Scope<string> | null,
): string | EmitEntity<string> {
const segments = pathDown.map((s) => s.name);
segments.push(targetDeclaration.name);
Expand Down
2 changes: 1 addition & 1 deletion docs/extending-typespec/linters.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ await tester
.expect(
`
model Foo {}
`
`,
)
.applyCodeFix("add-model-suffix").toEqual(`
model FooModel {}
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2e-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function testBasicLatest(packages) {
["compile", ".", "--emit", "@typespec/openapi3"],
{
cwd: basicLatestDir,
}
},
);
console.log("Completed tsp compile .");

Expand Down Expand Up @@ -121,7 +121,7 @@ async function testBasicCurrentTgz(packages) {
["compile", ".", "--emit", "@typespec/openapi3"],
{
cwd: basicCurrentDir,
}
},
);
console.log("Completed tsp compile .");

Expand Down
4 changes: 2 additions & 2 deletions eng/common/scripts/check-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function findMarkdownFiles(folder) {
} else {
return [];
}
})
}),
)
).flat();
}
Expand Down Expand Up @@ -54,7 +54,7 @@ async function main() {
"---",
"title: xyz",
"---",
].join("\n")
].join("\n"),
);
process.exit(1);
} else {
Expand Down
4 changes: 2 additions & 2 deletions eng/common/scripts/check-for-changed-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ if (proc.stdout || proc.stderr) {
if (process.argv[2] !== "publish") {
console.error(
`ERROR: Files above were changed during PR validation, but not included in the PR.
Include any automated changes such as sample output, spec.html, and ThirdPartyNotices.txt in your PR.`
Include any automated changes such as sample output, spec.html, and ThirdPartyNotices.txt in your PR.`,
);
} else {
console.error(
`ERROR: Changes have been made since this publish PR was prepared.
In the future, remember to alert coworkers to avoid merging additional changes while publish PRs are in progress.
Close this PR, run prepare-publish again.`
Close this PR, run prepare-publish again.`,
);
}
process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion eng/common/scripts/labels/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function defineConfig(config: RepoConfig) {
}

export function defineLabels<const T extends string>(
labels: Record<T, { color: string; description: string }>
labels: Record<T, { color: string; description: string }>,
) {
return labels;
}
28 changes: 14 additions & 14 deletions eng/common/scripts/labels/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ function prettyLabel(label: Label, padEnd: number = 0) {
async function syncGithubLabels(config: RepoConfig, labels: Label[], options: ActionOptions = {}) {
if (!options.dryRun && !process.env.GITHUB_TOKEN && !options.check) {
throw new Error(
"GITHUB_TOKEN environment variable is required when not running in dry-run mode or check mode."
"GITHUB_TOKEN environment variable is required when not running in dry-run mode or check mode.",
);
}
const octokit = new Octokit(
process.env.GITHUB_TOKEN ? { auth: `token ${process.env.GITHUB_TOKEN}` } : {}
process.env.GITHUB_TOKEN ? { auth: `token ${process.env.GITHUB_TOKEN}` } : {},
);

const existingLabels = await fetchAllLabels(octokit, config.repo);
Expand Down Expand Up @@ -161,8 +161,8 @@ async function checkLabelsToDelete(labels: GithubLabel[]) {
if (label.issues.totalCount > 0) {
console.log(
pc.red(
`Label ${label.name} has ${label.issues.totalCount} issues assigned to it, make sure to rename the label manually first to not lose assignment.`
)
`Label ${label.name} has ${label.issues.totalCount} issues assigned to it, make sure to rename the label manually first to not lose assignment.`,
),
);
hasError = true;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ async function fetchAllLabels(octokit: Octokit, repo: RepoConfig["repo"]): Promi
{
owner: repo.owner,
repo: repo.repo,
}
},
);

return repository.labels.nodes;
Expand All @@ -224,43 +224,43 @@ async function createLabels(
config: RepoConfig,
octokit: Octokit,
labels: Label[],
options: ActionOptions
options: ActionOptions,
) {
for (const label of labels) {
await doAction(
() => octokit.rest.issues.createLabel({ ...config.repo, ...label }),
`Created label ${label.name}, color: ${label.color}, description: ${label.description}`,
options
options,
);
}
}
async function updateLabels(
config: RepoConfig,
octokit: Octokit,
labels: Label[],
options: ActionOptions
options: ActionOptions,
) {
for (const label of labels) {
await doAction(
() => octokit.rest.issues.updateLabel({ ...config.repo, ...label }),
`Updated label ${label.name}, color: ${label.color}, description: ${label.description}`,
options
options,
);
}
}
async function deleteLabels(
config: RepoConfig,
octokit: Octokit,
labels: GithubLabel[],
options: ActionOptions
options: ActionOptions,
) {
checkLabelsToDelete(labels);

for (const label of labels) {
await doAction(
() => octokit.rest.issues.deleteLabel({ ...config.repo, name: label.name }),
`Deleted label ${label.name}`,
options
options,
);
console.log(`Deleted label ${label.name}`);
}
Expand Down Expand Up @@ -302,16 +302,16 @@ async function updateContributingFile(labels: LabelsResolvedConfig, options: Act
} else {
console.log(
pc.red(
"CONTRIBUTING.md file label section is not up to date, run pnpm sync-labels to update it"
)
"CONTRIBUTING.md file label section is not up to date, run pnpm sync-labels to update it",
),
);
process.exit(1);
}
} else {
await doAction(
() => writeFile(contributingFile, formatted),
"Updated contributing file",
options
options,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions eng/common/scripts/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export async function syncFile(filename: string, newContent: string, options: Ch
} else {
console.error(
pc.red(
`${filename} file label section is not up to date, run pnpm sync-labels to update it`
)
`${filename} file label section is not up to date, run pnpm sync-labels to update it`,
),
);
process.exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion eng/common/scripts/utils/exec-async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface ExecResult {
export function execAsync(
cmd: string,
args: string[],
opts: SpawnOptions = {}
opts: SpawnOptions = {},
): Promise<ExecResult> {
return new Promise((resolve, reject) => {
const child = spawn(cmd, args, opts);
Expand Down
4 changes: 2 additions & 2 deletions eng/common/scripts/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { execAsync, type ExecResult } from "./exec-async.js";

export async function listChangedFilesSince(
ref: string,
{ repositoryPath }: { repositoryPath: string }
{ repositoryPath }: { repositoryPath: string },
) {
return splitStdoutLines(await execGit(["diff", "--name-only", `${ref}...`], { repositoryPath }));
}

async function execGit(
args: string[],
{ repositoryPath }: { repositoryPath: string }
{ repositoryPath }: { repositoryPath: string },
): Promise<ExecResult> {
const result = await execAsync("git", args, { cwd: repositoryPath });

Expand Down
2 changes: 1 addition & 1 deletion eng/tsp-core/scripts/legacy-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function run(command, args, options) {
} else if (options.throwOnNonZeroExit && proc.status !== undefined && proc.status !== 0) {
throw new CommandFailedError(
`Command \`${command} ${args.join(" ")}\` failed with exit code ${proc.status}`,
proc
proc,
);
}

Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ export default tsEslint.config(
],
},
...TypeSpecCommonEslintConfigs,
...getTypeScriptProjectRules(import.meta.dirname)
...getTypeScriptProjectRules(import.meta.dirname),
);
2 changes: 1 addition & 1 deletion packages/bundle-uploader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getPackageVersion(repoRoot: string, pkgName: string) {
const project = projects.find((x) => x.manifest.name === pkgName);
if (project === undefined) {
throw new Error(
`Cannot get version for package: "${pkgName}", pnpm couldn't find a package with that name in the workspace`
`Cannot get version for package: "${pkgName}", pnpm couldn't find a package with that name in the workspace`,
);
}
const version = parse(project.manifest.version);
Expand Down
10 changes: 5 additions & 5 deletions packages/bundle-uploader/src/upload-browser-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TypeSpecBundledPackageUploader {
key,
this.#container.url + "/" + normalizePath(join(manifest.name, manifest.version, value)),
];
})
}),
);
const created = await this.#uploadManifest(manifest);
if (!created) {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class TypeSpecBundledPackageUploader {
async #uploadManifest(manifest: BundleManifest) {
try {
const blob = this.#container.getBlockBlobClient(
normalizePath(join(manifest.name, manifest.version, "manifest.json"))
normalizePath(join(manifest.name, manifest.version, "manifest.json")),
);
const content = JSON.stringify(manifest);
await blob.upload(content, content.length, {
Expand All @@ -100,7 +100,7 @@ export class TypeSpecBundledPackageUploader {

async #uploadJsFile(pkgName: string, version: string, file: TypeSpecBundleFile) {
const blob = this.#container.getBlockBlobClient(
normalizePath(join(pkgName, version, file.filename))
normalizePath(join(pkgName, version, file.filename)),
);
await blob.uploadData(Buffer.from(file.content), {
blobHTTPHeaders: {
Expand All @@ -115,11 +115,11 @@ export class TypeSpecBundledPackageUploader {

function getCoverageContainer(
storageAccountName: string,
credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential
credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential,
): ContainerClient {
const blobSvc = new BlobServiceClient(
`https://${storageAccountName}.blob.core.windows.net`,
credential
credential,
);
const containerClient = blobSvc.getContainerClient(pkgsContainer);
return containerClient;
Expand Down
10 changes: 5 additions & 5 deletions packages/bundler/src/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function createTypeSpecBundle(libraryPath: string): Promise<TypeSpe

export async function watchTypeSpecBundle(
libraryPath: string,
onBundle: (bundle: TypeSpecBundle) => void
onBundle: (bundle: TypeSpecBundle) => void,
) {
const definition = await resolveTypeSpecBundleDefinition(libraryPath);
const rollupOptions = await createRollupConfig(definition);
Expand Down Expand Up @@ -115,14 +115,14 @@ export async function bundleTypeSpecLibrary(libraryPath: string, outputDir: stri
}

async function resolveTypeSpecBundleDefinition(
libraryPath: string
libraryPath: string,
): Promise<TypeSpecBundleDefinition> {
libraryPath = normalizePath(await realpath(libraryPath));
const pkg = await readLibraryPackageJson(libraryPath);

const exports = pkg.exports
? Object.fromEntries(
Object.entries(pkg.exports).filter(([k, v]) => k !== "." && k !== "./testing")
Object.entries(pkg.exports).filter(([k, v]) => k !== "." && k !== "./testing"),
)
: {};

Expand Down Expand Up @@ -165,7 +165,7 @@ async function createRollupConfig(definition: TypeSpecBundleDefinition): Promise
key.replace("./", ""),
normalizePath(resolve(libraryPath, getExportEntryPoint(value))),
];
})
}),
);
return {
input: {
Expand Down Expand Up @@ -200,7 +200,7 @@ async function createRollupConfig(definition: TypeSpecBundleDefinition): Promise

async function generateTypeSpecBundle(
definition: TypeSpecBundleDefinition,
bundle: RollupBuild
bundle: RollupBuild,
): Promise<TypeSpecBundle> {
const { output } = await bundle.generate({
dir: "virtual",
Expand Down
Loading

0 comments on commit a336c93

Please sign in to comment.