Skip to content

Commit

Permalink
chore: use bazel-super-formatter to format all source files (#4124)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrocat101 committed Jun 4, 2023
1 parent 3667a5f commit 362d740
Show file tree
Hide file tree
Showing 48 changed files with 150 additions and 706 deletions.
10 changes: 5 additions & 5 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const {sync: globSync} = require('fast-glob');
const types = require('@commitlint/config-angular-type-enum');
const {sync: globSync} = require('fast-glob')
const types = require('@commitlint/config-angular-type-enum')

const packages = globSync('./packages/*/package.json').map(
fn => require(fn).name
);
)
// Website is not in `packages`.
packages.push('website');
packages.push('website')

module.exports = {
extends: ['@commitlint/config-angular'],
Expand All @@ -16,4 +16,4 @@ module.exports = {
'header-max-length': [0, 'never', Infinity],
'type-enum': [1, 'always', [...types.value(), 'chore']],
},
};
}
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ assignees: ''
<!-- If this is more of a question on how i18n should work or you have not narrowed down the issue to be 1 of our packages, please use Discussions instead -->

## Which package?

Since this is a monorepo. Please specify which package this bug report is for.

## Describe the bug

A clear and concise description of what the bug is.

## To Reproduce
Expand All @@ -30,9 +32,11 @@ Steps to reproduce the behavior:
4. See error

## Expected behavior

A clear and concise description of what you expected to happen.

## Screenshots

If applicable, add screenshots to help explain your problem.

## Desktop (please complete the following information):
Expand All @@ -49,4 +53,5 @@ If applicable, add screenshots to help explain your problem.
- Version [e.g. 22]

## Additional context

Add any other context about the problem here.
33 changes: 4 additions & 29 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,7 @@

bazel run //:buildifier

# bazel run //packages/babel-plugin-formatjs:prettier
# bazel run //packages/cli-lib:prettier
# bazel run //packages/ecma376:prettier
# bazel run //packages/ecma402-abstract:prettier
# bazel run //packages/editor:prettier
# bazel run //packages/eslint-plugin-formatjs:prettier
# bazel run //packages/fast-memoize:prettier
# bazel run //packages/icu-messageformat-parser:prettier
# bazel run //packages/icu-skeleton-parser:prettier
# bazel run //packages/intl-datetimeformat:prettier
# bazel run //packages/intl-displaynames:prettier
# bazel run //packages/intl-durationformat:prettier
# bazel run //packages/intl-enumerator:prettier
# bazel run //packages/intl-getcanonicallocales:prettier
# bazel run //packages/intl-listformat:prettier
# bazel run //packages/intl-locale:prettier
# bazel run //packages/intl-localematcher:prettier
# bazel run //packages/intl-messageformat:prettier
# bazel run //packages/intl-numberformat:prettier
# bazel run //packages/intl-pluralrules:prettier
# bazel run //packages/intl-relativetimeformat:prettier
# bazel run //packages/intl-segmenter:prettier
# bazel run //packages/intl:prettier
# bazel run //packages/react-intl:prettier
# bazel run //packages/swc-plugin:prettier
# bazel run //packages/ts-transformer:prettier
# bazel run //packages/vue-intl:prettier
# bazel run //tools:prettier
# bazel run //website:prettier
files=$(git diff --diff-filter=d --cached --name-only)
if [ -n "$files" ]; then
echo "$files" | tr \\n \\0 | xargs -0 bazel run @aspect_rules_format//format --
fi
12 changes: 11 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ website/.docusaurus
website/.now
website/build
website/CHANGELOG.md
packages/intl-segmenter/unicodeFiles/*
packages/intl-segmenter/unicodeFiles/*
# This file intentionally has a syntax error
packages/cli/integration-tests/extract/typescript/err.tsx
# Ignore generated files
**/*.generated.*
# Let Bazel manage this
rust/cargo-bazel-lock.json
# Snapshots managed by Jest
**/__snapshots__/*
# Changelog managed by Lerna
**/CHANGELOG.md
10 changes: 3 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"**/.settings": true,
"**/.factorypath": true,
"dist": true,
".swc": true,
".swc": true
},
"files.watcherExclude": {
"**/.git/objects/**": true,
Expand All @@ -35,9 +35,7 @@
},
"json.schemas": [
{
"fileMatch": [
"/lerna.json"
],
"fileMatch": ["/lerna.json"],
"url": "http://json.schemastore.org/lerna"
}
],
Expand All @@ -46,9 +44,7 @@
"eslint.packageManager": "yarn",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"rust-analyzer.linkedProjects": [
"rust/Cargo.toml"
],
"rust-analyzer.linkedProjects": ["rust/Cargo.toml"],
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand Down
72 changes: 33 additions & 39 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ load("@buildifier_prebuilt//:rules.bzl", "buildifier")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//:karma/package_json.bzl", karma_bin = "bin")
load("@rules_multirun//:defs.bzl", "multirun")
load("//tools:index.bzl", "BUILDIFIER_WARNINGS")
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")

exports_files(
Expand Down Expand Up @@ -150,41 +149,6 @@ karma_bin.karma_test(
tags = ["manual"],
)

multirun(
name = "prettier_all",
commands = [
"//packages/babel-plugin-formatjs:prettier",
"//packages/cli-lib:prettier",
"//packages/ecma376:prettier",
"//packages/ecma402-abstract:prettier",
"//packages/editor:prettier",
"//packages/eslint-plugin-formatjs:prettier",
"//packages/fast-memoize:prettier",
"//packages/icu-messageformat-parser:prettier",
"//packages/icu-skeleton-parser:prettier",
"//packages/intl-datetimeformat:prettier",
"//packages/intl-displaynames:prettier",
"//packages/intl-durationformat:prettier",
"//packages/intl-enumerator:prettier",
"//packages/intl-getcanonicallocales:prettier",
"//packages/intl-listformat:prettier",
"//packages/intl-locale:prettier",
"//packages/intl-localematcher:prettier",
"//packages/intl-messageformat:prettier",
"//packages/intl-numberformat:prettier",
"//packages/intl-pluralrules:prettier",
"//packages/intl-relativetimeformat:prettier",
"//packages/intl-segmenter:prettier",
"//packages/intl:prettier",
"//packages/react-intl:prettier",
"//packages/swc-plugin:prettier",
"//packages/ts-transformer:prettier",
"//packages/vue-intl:prettier",
"//tools:prettier",
"//website:prettier",
],
)

multirun(
name = "generated-test-files",
testonly = True,
Expand Down Expand Up @@ -225,16 +189,46 @@ buildifier(
name = "buildifier",
exclude_patterns = ["./node_modules/*"],
lint_mode = "fix",
lint_warnings = BUILDIFIER_WARNINGS,
lint_warnings = [
"attr-cfg",
"attr-license",
"attr-non-empty",
"attr-output-default",
"attr-single-file",
"constant-glob",
"ctx-actions",
"ctx-args",
"depset-iteration",
"depset-union",
"dict-concatenation",
"duplicated-name",
"filetype",
"git-repository",
"http-archive",
"integer-division",
"load",
"load-on-top",
"native-build",
"native-package",
"out-of-order-load",
"output-group",
"package-name",
"package-on-top",
"positional-args",
"redefined-variable",
"repository-name",
"same-origin-load",
"string-iteration",
"unsorted-dict-items",
"unused-variable",
],
verbose = True,
)

CONFIG_FILES = [
".prettierrc.json",
"jest.config.js",
"package.json",
"tsconfig.json",
".taplo.toml",
]

[
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ npx pnpm -r publish
```
bazel run //packages/intl-datetimeformat:generated_tz_data
```

4. Test to make sure everything passes

5. New TimeZones or renames of TimeZones are not updated using the Bazel script. You need to manually update `index.bzl`.
Expand Down
33 changes: 31 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ workspace(

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

# some rules such as bazel-super-formatter depends on rules_python.
http_archive(
name = "rules_python",
sha256 = "863ba0fa944319f7e3d695711427d9ad80ba92c6edd0b7c7443b84e904689539",
strip_prefix = "rules_python-0.22.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.22.0/rules_python-0.22.0.tar.gz",
)

# rules_js
http_archive(
name = "aspect_rules_js",
Expand Down Expand Up @@ -239,8 +247,7 @@ load("@io_buildbuddy_buildbuddy_toolchain//:rules.bzl", "buildbuddy")

buildbuddy(name = "buildbuddy_toolchain")

# Rust
# ----
# Rust# ----

# To find additional information on this release or newer ones visit:
# https://github.com/bazelbuild/rules_rust/releases
Expand Down Expand Up @@ -283,3 +290,25 @@ crates_repository(
load("@crate_index//:defs.bzl", "crate_repositories")

crate_repositories()

# Linter
# ------------------------------------------------------------------------------

http_archive(
name = "aspect_rules_format",
sha256 = "c8d04f68082c0eeac2777e15f65048ece2f17d632023bdcc511602f8c5faf177",
strip_prefix = "bazel-super-formatter-2.0.0",
url = "https://github.com/aspect-build/bazel-super-formatter/archive/refs/tags/v2.0.0.tar.gz",
)

load("@aspect_rules_format//format:repositories.bzl", "rules_format_dependencies")

rules_format_dependencies()

load("@aspect_rules_format//format:dependencies.bzl", "parse_dependencies")

parse_dependencies()

load("@aspect_rules_format//format:toolchains.bzl", "format_register_toolchains")

format_register_toolchains()
2 changes: 2 additions & 0 deletions buildbuddy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ actions:
resource_requests:
memory: 10GB
bazel_commands:
# Check if all files are properly formatted.
- 'run @aspect_rules_format//format -- --mode check'
- 'test //...'
14 changes: 7 additions & 7 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"auths": {
"ghcr.io": {},
"https://index.docker.io/v1/": {}
},
"credsStore": "desktop",
"experimental": "disabled"
}
"auths": {
"ghcr.io": {},
"https://index.docker.io/v1/": {}
},
"credsStore": "desktop",
"experimental": "disabled"
}
6 changes: 3 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = function (config) {
browserName: 'internet explorer',
version: '11',
},
};
}

config.set({
basePath: '',
Expand Down Expand Up @@ -59,5 +59,5 @@ module.exports = function (config) {
captureTimeout: 120000,
customLaunchers,
singleRun: true,
});
};
})
}
9 changes: 2 additions & 7 deletions lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@
"private": false,
"exact": true,
"createRelease": "github",
"ignoreChanges": [
"**/tests/**",
"**/*.md"
]
"ignoreChanges": ["**/tests/**", "**/*.md"]
},
"run": {
"stream": true
}
},
"packages": [
"packages/*"
]
"packages": ["packages/*"]
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
"url": "https://github.com/formatjs/formatjs"
},
"scripts": {
"bazel:lint": "bazel run //:buildifier",
"build": "bazel build //...",
"deploy": "NO_UPDATE_NOTIFIER=1 DEPLOYMENT_BRANCH=main USE_SSH=true bazel run //website:deploy",
"docs": "NO_UPDATE_NOTIFIER=1 bazel run //website:serve",
"examples": "bazel run //packages/react-intl/examples",
"format": "npm run bazel:lint && bazel run :prettier_all",
"format": "bazel run @aspect_rules_format//format",
"karma:ci": "bazel test :karma-ci",
"karma:local": "bazel test :karma",
"postinstall": "husky install",
Expand Down Expand Up @@ -109,7 +108,7 @@
"minimist": "^1.2.5",
"picomatch": "^2.3.1",
"pnpm": "^7.9.3",
"prettier": "^2.0.5",
"prettier": "^2.8.8",
"react": "^16.6.0 || 17 || 18",
"react-dom": "^16.6.0 || 17 || 18",
"regenerate": "^1.4.2",
Expand Down

0 comments on commit 362d740

Please sign in to comment.