Skip to content

Commit

Permalink
Revert prettier upgrade and fix formatting (#7891)
Browse files Browse the repository at this point in the history
The version upgrade in
#7741 is causing
unexpected prettier diffs whenever we change certain files. This is
because prettier 3.x introduced new formatting rules, but our prettier
script only checks/formats changed files. So, in the upgrade PR,
Checkstyle didn't complain about the formatting now being incorrect
after the upgrade, and the latent formatting errors are being surfaced
in PRs only as the files are edited.

This PR reverts prettier back to 2.1.1 and updates Checkstyle to catch
this error in CI - if the prettier version in yarn.lock changes, then
all files are checked/formatted, not just changed files.
  • Loading branch information
bduffany authored Nov 13, 2024
1 parent 2f80f1e commit 195b423
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"semi": true,
"singleQuote": false,
"printWidth": 120,
"bracketSameLine": true
"jsxBracketSameLine": true
}
5 changes: 2 additions & 3 deletions app/target/target_test_log_card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ export default class TargetTestLogCardComponent extends React.Component<Props, S
}

fetchTestLog() {
let testLogUrl = this.props.buildEvent?.testResult?.testActionOutput.find(
(log: any) => log.name == "test.log"
)?.uri;
let testLogUrl = this.props.buildEvent?.testResult?.testActionOutput.find((log: any) => log.name == "test.log")
?.uri;

if (!testLogUrl) {
return;
Expand Down
8 changes: 4 additions & 4 deletions docs/cli-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,16 @@ if __name__ == "__main__":

The CLI exposes certain environment variables to your plugins.

#### $BUILD_WORKSPACE_DIRECTORY
#### \$BUILD_WORKSPACE_DIRECTORY

This is the path to the Bazel workspace in which the CLI is run. It is the
root path, containing the bazel `WORKSPACE`, `WORKSPACE.bazel`, `MODULE`, or `MODULE.bazel` file.

#### $PLUGIN_TEMPDIR
#### \$PLUGIN_TEMPDIR

This is a temporary directory that can be used by your plugin to store temporary files. These files will be cleaned up after the invocation is complete.

#### $USER_CONFIG_DIR
#### \$USER_CONFIG_DIR

This is a long-lived directory you can use to store user preferences, like whether or not a user always wants to automatically apply a particular fix.

Expand All @@ -343,7 +343,7 @@ config dir, if needed, using something like
you'll need to decide how to handle differences in preferences across
different versions of your plugin.

#### $EXEC_ARGS_FILE
#### \$EXEC_ARGS_FILE

This is the path of a file that contains the args that would be passed to an
executable built by bazel as a result of a `bazel run` command. Specifically,
Expand Down
6 changes: 1 addition & 5 deletions enterprise/app/code/code.css
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,7 @@
background-color: #fff;
padding: 8px 0;
border-radius: 8px;
box-shadow:
0 0 0 1px #0000000f,
0 1px 1px -0.5px #0000000f,
0 3px 3px -1.5px #0000000f,
0 6px 6px -3px #0000000f;
box-shadow: 0 0 0 1px #0000000f, 0 1px 1px -0.5px #0000000f, 0 3px 3px -1.5px #0000000f, 0 6px 6px -3px #0000000f;
}

.code-editor .context-menu div {
Expand Down
4 changes: 2 additions & 2 deletions enterprise/app/filter/filter_util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ export function statusToString(status: invocation_status.OverallStatus) {
}

export function statusFromString(value: string) {
return invocation_status.OverallStatus[
return (invocation_status.OverallStatus[
value.toUpperCase().replace(/-/g, "_") as any
] as unknown as invocation_status.OverallStatus;
] as unknown) as invocation_status.OverallStatus;
}

export function parseRoleParam(paramValue: string | null): string[] {
Expand Down
2 changes: 1 addition & 1 deletion enterprise/app/tap/flakes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export default class FlakesComponent extends React.Component<Props, State> {
);
}

let tableData = singleTarget ? [] : (this.state.tableData?.stats ?? []);
let tableData = singleTarget ? [] : this.state.tableData?.stats ?? [];
let sortFn: (a: target.AggregateTargetStats, b: target.AggregateTargetStats) => number;
if (this.state.tableSort === "Flakes") {
sortFn = (a, b) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"moment": "^2.29.4",
"monaco-editor": "0.47.0",
"path-browserify": "^1.0.1",
"prettier": "3.3.3",
"prettier": "2.1.1",
"protobufjs": "^7.2.5",
"react": "^16.8.6",
"react-date-range": "^1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion tools/checkstyle/checkstyle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ run ProtoFormat \

run PrettierFormat \
env PRETTIER_PATH="$PRETTIER_PATH" \
tools/prettier/prettier.sh --log-level=warn --check
tools/prettier/prettier.sh --loglevel=warn --check

wait

Expand Down
25 changes: 18 additions & 7 deletions tools/prettier/prettier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
set -e

: "${PRETTIER_PATH:=}"
: "${DIFF_BASE:=}"

# File patterns to format using prettier, using git's file pattern syntax.
GIT_FILE_PATTERNS=(
Expand All @@ -15,7 +16,6 @@ GIT_FILE_PATTERNS=(
'*.md'
'*.ts'
'*.tsx'
'*.xml'
'*.yaml'
)

Expand All @@ -31,14 +31,25 @@ realpath() {
# If we are on the master branch already, then look one commit back.
# This is needed to support workflows that run on push.
function paths_to_format() {
if [[ "$(git rev-parse --abbrev-ref HEAD)" == master ]]; then
DIFF_BASE='HEAD~1'
if ! [[ "$DIFF_BASE" ]]; then
if [[ "$(git rev-parse --abbrev-ref HEAD)" == master ]]; then
DIFF_BASE='HEAD~1'
else
# If on a feature branch, use GIT_BASE_BRANCH env var set by BB workflows,
# or fall back to master (which should usually work when running locally).
DIFF_BASE=$(git merge-base HEAD "origin/${GIT_BASE_BRANCH:-master}")
fi
fi

# If any of the following are changed, then all files need to be reformatted,
# not just changed files:
# - The prettier version in yarn.lock
# - Any prettier configuration in .prettierrc
if (git diff "$DIFF_BASE" -- yarn.lock | grep -q prettier) || (git diff "$DIFF_BASE" -- .prettierrc | grep -q .); then
git ls-files -- "${GIT_FILE_PATTERNS[@]}"
else
# If on a feature branch, use GIT_BASE_BRANCH env var set by BB workflows,
# or fall back to master (which should usually work when running locally).
DIFF_BASE=$(git merge-base HEAD "origin/${GIT_BASE_BRANCH:-master}")
git diff --name-only --diff-filter=AMRCT "$DIFF_BASE" -- "${GIT_FILE_PATTERNS[@]}"
fi
git diff --name-only --diff-filter=AMRCT "$DIFF_BASE" -- "${GIT_FILE_PATTERNS[@]}"
}

paths=()
Expand Down
2 changes: 1 addition & 1 deletion website/blog/redpoint-infrared-100.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ All companies included on the first annual InfraRed 100 are included [here](http

**About BuildBuddy:** BuildBuddy provides an open-core suite of enterprise features for Bazel, including a Remote Build Execution service, a shared build artifact cache, and a build & test result UI. It's available as a fully-managed cloud service or as an easy to deploy on-prem solution. BuildBuddy is based in San Francisco, backed by Y Combinator, and founded by two ex-Googlers deeply passionate about making developers more productive. For more information visit: https://buildbuddy.io/

**About Redpoint Ventures:** Redpoint has partnered with visionary founders to create new markets and redefine existing ones since 1999. We invest in startups across the seed, early and growth phases, and we’re proud to have backed over 578 companies—including Snowflake, Looker, Kustomer, Twilio, 2U, DraftKings, Duo Security, HashiCorp, Stripe, Guild, HomeAway, Heroku, Netflix, and Sonos—with 181 IPOs and M+A exits. Redpoint manages $7.2 billion across multiple funds. For more information visit: https://www.redpoint.com/
**About Redpoint Ventures:** Redpoint has partnered with visionary founders to create new markets and redefine existing ones since 1999. We invest in startups across the seed, early and growth phases, and we’re proud to have backed over 578 companies—including Snowflake, Looker, Kustomer, Twilio, 2U, DraftKings, Duo Security, HashiCorp, Stripe, Guild, HomeAway, Heroku, Netflix, and Sonos—with 181 IPOs and M+A exits. Redpoint manages \$7.2 billion across multiple funds. For more information visit: https://www.redpoint.com/
2 changes: 1 addition & 1 deletion website/blog/welcoming-george-li-head-of-sales.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tags: [company, team]

To fulfill our mission of bringing the world's best developer tools to every company, we're building a team that's ready to work with the world's best enterprises. That's why we're excited to share today that [**George Li**](https://www.linkedin.com/in/gli/) is joining BuildBuddy to lead our enterprise sales efforts as our Head of Sales.

George joins us from Looker where he served as Head of APAC Sales Engineering. He joined Google Cloud through their [acquisition](https://techcrunch.com/2020/02/13/google-closes-2-6b-looker-acquisition/) of Looker in February, having helped the company grow to a $2.6B valuation.
George joins us from Looker where he served as Head of APAC Sales Engineering. He joined Google Cloud through their [acquisition](https://techcrunch.com/2020/02/13/google-closes-2-6b-looker-acquisition/) of Looker in February, having helped the company grow to a \$2.6B valuation.

![](../static/img/blog/welcome-george.png)

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -862,10 +862,10 @@ path-key@^3.1.0:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==

prettier@3.3.3:
version "3.3.3"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.3.3.tgz#30c54fe0be0d8d12e6ae61dbb10109ea00d53105"
integrity sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==
prettier@2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.1.tgz#d9485dd5e499daa6cb547023b87a6cf51bee37d6"
integrity sha512-9bY+5ZWCfqj3ghYBLxApy2zf6m+NJo5GzmLTpr9FsApsfjriNnS2dahWReHMi7qNPhhHl9SYHJs2cHZLgexNIw==

prop-types@15, prop-types@^15.5.10, prop-types@^15.7.2:
version "15.7.2"
Expand Down

0 comments on commit 195b423

Please sign in to comment.