Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions example/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
// Allows comments!
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true,
"dynamicImport": true
},
"transform": {
"react": {
"runtime": "automatic"
}
},
"target": "es2022",
"loose": false,
"externalHelpers": true,
"keepClassNames": true
},
"module": {
"type": "es6",
"strict": true,
"strictMode": true,
"lazy": false,
"noInterop": false
},
"minify": false,
"sourceMaps": true
}
1 change: 1 addition & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ exports_files(
".ruff.toml",
".shellcheckrc",
".scalafmt.conf",
".swcrc",
".vale.ini",
".editorconfig",
"ktlint-baseline.xml",
Expand Down
6 changes: 5 additions & 1 deletion example/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@aspect_rules_lint//format:defs.bzl", "format_test")
load("@aspect_rules_swc//swc:defs.bzl", "swc")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project")
load("@bazel_skylib//lib:partial.bzl", "partial")
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
Expand Down Expand Up @@ -45,7 +46,10 @@ ts_project(
name = "ts",
srcs = ["file.ts"],
declaration = True,
transpiler = swc,
transpiler = partial.make(
swc,
swcrc = "//:.swcrc",
),
deps = [
":ts_dep",
"//:node_modules/dayjs",
Expand Down
12 changes: 12 additions & 0 deletions example/src/config.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// This is a comment - not allowed in JSON
trailingComma: "allowed in JSON5", // Trailing commas are allowed
singleQuotes: "valid in JSON5", // Single quotes are allowed
unquotedKeys: true, // Unquoted object keys are allowed
hex: 0x1f, // Hexadecimal numbers are allowed
infinity: Infinity, // Infinity is allowed
nan: NaN, // NaN is allowed
trailing_decimal: 1, // Trailing decimal point is allowed
"contains.periods": true, // Dots in keys don't need to be quoted
"can mix": "quote styles", // Mixing quote styles is allowed
}
1 change: 1 addition & 0 deletions example/src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
// A comment
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
Expand Down
6 changes: 4 additions & 2 deletions format/private/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function process_args_in_batches() {
function ls-files {
language="$1" && shift;
# Copied file patterns from
# https://github.com/github-linguist/linguist/blob/559a6426942abcae16b6d6b328147476432bf6cb/lib/linguist/languages.yml
# https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml
# using the ./mirror_linguist_languages.sh tool to transform to Bash code
case "$language" in
'C') patterns=('*.c' '*.cats' '*.h' '*.idc') ;;
Expand All @@ -123,6 +123,8 @@ function ls-files {
'GraphQL') patterns=('*.graphql' '*.gql' '*.graphqls') ;;
'HTML') patterns=('*.html' '*.hta' '*.htm' '*.html.hl' '*.inc' '*.xht' '*.xhtml') ;;
'JSON') patterns=('.all-contributorsrc' '.arcconfig' '.auto-changelog' '.c8rc' '.htmlhintrc' '.imgbotconfig' '.nycrc' '.tern-config' '.tern-project' '.watchmanconfig' 'Pipfile.lock' 'composer.lock' 'deno.lock' 'flake.lock' 'mcmod.info' '*.json' '*.4DForm' '*.4DProject' '*.avsc' '*.geojson' '*.gltf' '*.har' '*.ice' '*.JSON-tmLanguage' '*.jsonl' '*.mcmeta' '*.tfstate' '*.tfstate.backup' '*.topojson' '*.webapp' '*.webmanifest' '*.yy' '*.yyp') ;;
'JSON with Comments') patterns=( '*.jsonc' '*.code-snippets' '*.code-workspace' '*.sublime-build' '*.sublime-commands' '*.sublime-completions' '*.sublime-keymap' '*.sublime-macro' '*.sublime-menu' '*.sublime-mousemap' '*.sublime-project' '*.sublime-settings' '*.sublime-theme' '*.sublime-workspace' '*.sublime_metrics' '*.sublime_session' '.babelrc' '.devcontainer.json' '.eslintrc.json' '.jscsrc' '.jshintrc' '.jslintrc' '.swcrc' 'api-extractor.json' 'devcontainer.json' 'jsconfig.json' 'language-configuration.json' 'tsconfig.json' 'tslint.json') ;;
'JSON5') patterns=('*.json5') ;;
'Java') patterns=('*.java' '*.jav' '*.jsh') ;;
'JavaScript') patterns=('Jakefile' '*.js' '*._js' '*.bones' '*.cjs' '*.es' '*.es6' '*.frag' '*.gs' '*.jake' '*.javascript' '*.jsb' '*.jscad' '*.jsfl' '*.jslib' '*.jsm' '*.jspre' '*.jss' '*.jsx' '*.mjs' '*.njs' '*.pac' '*.sjs' '*.ssjs' '*.xsjs' '*.xsjslib') ;;
'Jsonnet') patterns=('*.jsonnet' '*.libsonnet') ;;
Expand Down Expand Up @@ -302,7 +304,7 @@ if [ "${BASH_SOURCE[0]}" -ef "$0" ]; then

# Handle additional languages for JavaScript and CSS
if [[ "$lang" == "JavaScript" ]]; then
for sublang in "JSON" "TSX" "TypeScript" "Vue"; do
for sublang in "JSON" "JSON5" "JSON with Comments" "TSX" "TypeScript" "Vue"; do
process_args_in_batches "$sublang" "$bin" "${flags:-""}" "$@"
done
fi
Expand Down
3 changes: 2 additions & 1 deletion format/private/formatter_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# Per the formatter design, each language can only have a single formatter binary
# Keys in this map must match the `case "$language" in` block in format.sh
TOOLS = {
# NB: includes TypeScript and JSON
# NB: includes TypeScript and some others
"JavaScript": "prettier",
"Markdown": "prettier",
# NB: includes LESS and SASS
"CSS": "prettier",
"GraphQL": "prettier",
"HTML": "prettier",
Expand Down
2 changes: 2 additions & 0 deletions format/test/format_test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ bats_load_library "bats-assert"
assert_output --partial "+ prettier --write example/src/hello.tsx"
assert_output --partial "+ prettier --write example/src/hello.vue"
assert_output --partial "+ prettier --write .bcr/metadata.template.json"
assert_output --partial "+ prettier --write example/.swcrc"
assert_output --partial "+ prettier --write example/src/config.json5"
}

# File arguments: will filter with find
Expand Down
Loading