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

Add dprint code formatter #7263

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
]
}
}
}
}
28 changes: 28 additions & 0 deletions .dprint.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"typescript": {
"lineWidth": 150,
"quoteStyle": "preferDouble",
"newLineKind": "auto",
"useBraces": "maintain",
"bracePosition": "sameLine",
"nextControlFlowPosition": "maintain",
"operatorPosition": "maintain",
"arrowFunction.useParentheses": "force",
"module.sortExportDeclarations": "maintain",
"typeLiteral.separatorKind.singleLine": "comma"
},
"json": {
"trailingCommas": "never"
},
"excludes": [
// Note that everything gitignored is already excluded by default.
"**/*-lock.json",
"common/changes/**/*",
"common/config/rush/**/*",
"common/scripts/**/*"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.93.0.wasm",
"https://plugins.dprint.dev/json-0.19.3.wasm"
]
}
38 changes: 19 additions & 19 deletions .github/workflows/automation-scripts/invalidate-status-checks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@
// This is specifically to catch changes to @bentley/imodeljs-native and should only invalidate PRs that target master branch
// This will also invalidate PRs if there's a new nightly build, however our 3 hour rule should also invalidate the same PRs

import { Octokit, App } from "octokit"
import dotenv from 'dotenv'
import dotenv from "dotenv";
import { App, Octokit } from "octokit";

dotenv.config();

const octokit = new Octokit({
auth: `${process.env.GITHUB_TOKEN}`
auth: `${process.env.GITHUB_TOKEN}`,
});

let pull_requests = await octokit.request('GET /repos/{owner}/{repo}/pulls', {
owner: 'iTwin',
repo: 'itwinjs-core',
let pull_requests = await octokit.request("GET /repos/{owner}/{repo}/pulls", {
owner: "iTwin",
repo: "itwinjs-core",
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
"X-GitHub-Api-Version": "2022-11-28",
},
});

for (let i = 0; i < pull_requests.data.length; i++) {
let pr_sha = pull_requests.data[i].head.sha;

if (!pull_requests.data[i].draft && pull_requests.data[i].base.ref === 'master') {
await octokit.request('POST /repos/{owner}/{repo}/statuses/{sha}', {
owner: 'iTwin',
repo: 'itwinjs-core',
if (!pull_requests.data[i].draft && pull_requests.data[i].base.ref === "master") {
await octokit.request("POST /repos/{owner}/{repo}/statuses/{sha}", {
owner: "iTwin",
repo: "itwinjs-core",
sha: `${pr_sha}`,
state: 'failure',
description: '@bentley/imodeljs-native may be out of date with master, please merge',
context: 'iTwin.js',
state: "failure",
description: "@bentley/imodeljs-native may be out of date with master, please merge",
context: "iTwin.js",
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
"X-GitHub-Api-Version": "2022-11-28",
},
});
}
}
62 changes: 31 additions & 31 deletions .github/workflows/automation-scripts/update-changelogs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

"use strict";

import 'zx/globals'
import "zx/globals";

/****************************************************************
* To run manually:
* install zx package
* git checkout target branch (master or latest release); git pull
* git checkout release/X.X.x; git pull (this is the branch that was just patched)
* uncomment git checkout -b cmd and fix branch name
* run this file using `zx --install .github/workflows/automation-scripts/update-changelogs.mjs`
* open PR into target branch
*****************************************************************/
* To run manually:
* install zx package
* git checkout target branch (master or latest release); git pull
* git checkout release/X.X.x; git pull (this is the branch that was just patched)
* uncomment git checkout -b cmd and fix branch name
* run this file using `zx --install .github/workflows/automation-scripts/update-changelogs.mjs`
* open PR into target branch
*****************************************************************/

// Sort entries based on version numbers formatted as 'major.minor.patch'
function sortByVersion(entries) {
return entries.sort((a, b) => {
const versionA = a.version.split('.').map(Number);
const versionB = b.version.split('.').map(Number);
const versionA = a.version.split(".").map(Number);
const versionB = b.version.split(".").map(Number);

for (let i = 0; i < 3; i++) {
if (versionA[i] < versionB[i]) return 1;
Expand All @@ -35,7 +35,7 @@ function fixChangeLogs(files) {
const currentJson = fs.readJsonSync(`temp-target-changelogs/${files[i]}`);
const incomingJson = fs.readJsonSync(`temp-incoming-changelogs/${files[i]}`);
// .map creates an array of [changelog version string, changelog entry] tuples, which is passed into Map and creates a key value pair of the two elements.
let combinedEntries = [...currentJson.entries, ...incomingJson.entries].map((obj) => [obj['version'], obj]);
let combinedEntries = [...currentJson.entries, ...incomingJson.entries].map((obj) => [obj["version"], obj]);
// Map objects do not allow duplicate keys, so this will remove duplicate version numbers
let completeEntries = new Map(combinedEntries);
// convert entries back into an array and sort by version number
Expand All @@ -48,21 +48,21 @@ function fixChangeLogs(files) {

function editFileInPlaceSynchronously(filePath, stringToSearch, stringToReplace) {
try {
const contentRead = fs.readFileSync(filePath, { encoding: 'utf-8' });
const contentRead = fs.readFileSync(filePath, { encoding: "utf-8" });
const contentToWrite = contentRead.replace(stringToSearch, stringToReplace);
fs.writeFileSync(filePath, contentToWrite, { encoding: 'utf-8' });
fs.writeFileSync(filePath, contentToWrite, { encoding: "utf-8" });
}
catch (err) {
console.log(`Error while reading or writing to "${filePath}": ${err}`)
console.log(`Error while reading or writing to "${filePath}": ${err}`);
}
}

const targetPath = "./temp-target-changelogs"
const incomingPath = "./temp-incoming-changelogs"
const targetPath = "./temp-target-changelogs";
const incomingPath = "./temp-incoming-changelogs";

// To run shell commands using zx use "await $`cmd`"
await $`mkdir ${targetPath}`
await $`mkdir ${incomingPath}`
await $`mkdir ${targetPath}`;
await $`mkdir ${incomingPath}`;

// find the latest release branch, and make that the target for the changelogs
let targetBranch = await $`git branch -a --list "origin/release/[0-9]*.[0-9]*.x" | tail -n1 | sed 's/ remotes\\///'`;
Expand All @@ -71,23 +71,23 @@ let currentBranch = await $`git branch --show-current`;
let commitMessage = await $`git log --grep="^[0-9]\\+\\.[0-9]\\+\\.[0-9]\\+[^-]*$" -n 1 --pretty=format:%s`;

// remove extra null and new line characters from git cmds
targetBranch = String(targetBranch).replace(/\n/g, '');
currentBranch = String(currentBranch).replace(/\n/g, '');
commitMessage = String(commitMessage).replace(/\n/g, '');
targetBranch = String(targetBranch).replace(/\n/g, "");
currentBranch = String(currentBranch).replace(/\n/g, "");
commitMessage = String(commitMessage).replace(/\n/g, "");
const substring = " Changelogs";
if (commitMessage.includes(substring)) {
commitMessage = commitMessage.replace(substring, '');
commitMessage = commitMessage.replace(substring, "");
}

console.log(`target branch: ${targetBranch}`);
console.log(`current branch: ${currentBranch}`);
console.log(`commit msg: ${commitMessage}`);

if (targetBranch === `origin/${currentBranch}`) {
console.log("The current branch is the latest release, so the target will be master branch")
targetBranch = 'master'
console.log("The current branch is the latest release, so the target will be master branch");
targetBranch = "master";
} else {
console.log(`The current branch is ${currentBranch}, so the target will be ${targetBranch} branch`)
console.log(`The current branch is ${currentBranch}, so the target will be ${targetBranch} branch`);
}
// copy all changelogs from the current branch to ./temp-incoming-changelogs, the files will be named: package_name_CHANGELOG.json
await $`find ./ -type f -name "CHANGELOG.json" -not -path "*/node_modules/*" -exec sh -c 'cp "{}" "./temp-incoming-changelogs/$(echo "{}" | sed "s/^.\\///; s/\\//_/g")"' \\;`;
Expand Down Expand Up @@ -118,7 +118,7 @@ const targetFiles = allTargetFiles.filter((file) => {
else {
console.log(`${file} is not a package in ${currentBranch}. Skipping this package.`);
}
})
});

fixChangeLogs(targetFiles);

Expand All @@ -130,7 +130,7 @@ await $`rm -r ${incomingPath}`;
// after already checking out to target branch
// copy {release-version}.md to target branch if the commit that triggered this script run is from a major or minor version bump
if (commitMessage.endsWith(".0")) {
await $`git checkout ${currentBranch} docs/changehistory/${commitMessage}.md`
await $`git checkout ${currentBranch} docs/changehistory/${commitMessage}.md`;

// also need to add reference to this new md in leftNav.md
const leftNavMdPath = "docs/changehistory/leftNav.md";
Expand All @@ -139,9 +139,9 @@ if (commitMessage.endsWith(".0")) {
// # regen CHANGELOG.md
await $`rush publish --regenerate-changelogs`;
/*********************************************************************
* Uncomment For Manual runs and fix branch name to appropriate version
* the version should match your incoming branch
*********************************************************************/
* Uncomment For Manual runs and fix branch name to appropriate version
* the version should match your incoming branch
*********************************************************************/
// await $`git checkout -b finalize-release-X.X.X`;
// targetBranch = "finalize-release-X.X.X"
await $`git add .`;
Expand Down
2 changes: 1 addition & 1 deletion .mocharc.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
"reporter": "node_modules/@itwin/build-tools/mocha-reporter",
"reporter-options": "mochaFile=lib/test/junit_results.xml",
"timeout": 999999
}
}
4 changes: 2 additions & 2 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"streetsidesoftware.code-spell-checker",
"dbaeumer.vscode-eslint",
"davidanson.vscode-markdownlint",
"mike-co.import-sorter"
"dprint.dprint"
]
}
}
Loading
Loading