biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
13.98k stars 423 forks source link

šŸ“Invalid formatting when unexpected token hit #3522

Open anthony-murphy opened 1 month ago

anthony-murphy commented 1 month ago

Environment information

CLI:
  Version:                      1.8.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           windows

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         unset
  JS_RUNTIME_VERSION:           "v18.17.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "npm/9.6.7"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              true
  Organize imports disabled:    true
  VCS disabled:                 false

Formatter:
  Format with errors:           true
  Indent style:                 Tab
  Indent width:                 2
  Line ending:                  Lf
  Line width:                   95
  Attribute position:           Auto
  Ignore:                       ["**/dist/**", "**/lib/**"]
  Include:                      []

JavaScript Formatter:
  Enabled:                      false
  JSX quote style:              Double
  Quote properties:             Preserve
  Trailing commas:              All
  Semicolons:                   Always
  Arrow parentheses:            Always
  Bracket spacing:              true
  Bracket same line:            false
  Quote style:                  Double
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Attribute position:           Auto

JSON Formatter:
  Enabled:                      false
  Indent style:                 Tab
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Trailing Commas:              unset

CSS Formatter:
  Enabled:                      false
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Quote style:                  Double

Workspace:
  Open Documents:               0

Configuration

{
    "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
    "vcs": {
        "enabled": true,
        "clientKind": "git",
        "root": ".",
        "useIgnoreFile": true,
        "defaultBranch": "main"
    },
    "files": {
        "ignoreUnknown": true,

        "ignore": [
            // Build output
            "**/dist/*",
            "**/lib/*",
            "**/*.done.build.log",

            // test collateral
            "**/_package.json",
            "**/fluid-runner/src/test/localOdspSnapshots/**",
            "**/fluid-runner/src/test/telemetryExpectedOutputs/**",
            "**/snapshots/*.json",

            // Generated files
            "**/src/**/test/types/*.generated.ts",
            "**/src/packageVersion.ts",

            // Dependencies
            "**/node_modules/*",

            // Used by API-Extractor
            "**/_api-extractor-temp/*",
            "**/api-report/*",
            "**/*.api.md",

            // Templates
            ".changeset/templates/",
            "*.hbs",

            // Test json
            "build-tools/packages/build-tools/src/test/data/**",
            "experimental/dds/tree/src/test/documents/**",
            "packages/dds/map/src/test/mocha/snapshots/**/*.json",
            "packages/dds/matrix/src/test/results/**/*.json",
            "packages/dds/merge-tree/src/test/literature/*.txt",
            "packages/dds/merge-tree/src/test/results/*.json",
            "packages/dds/sequence/src/test/snapshots/**/*.json",
            "packages/dds/sequence/src/test/results/**/*.json",
            "packages/dds/sequence/src/test/fuzz/**/*.json",
            "packages/dds/tree/src/test/snapshots/**/*.json",
            "packages/dds/tree/src/test/shared-tree/fuzz/failures/**/*.json",
            "packages/drivers/odsp-driver/src/test/**/*.json",
            "packages/framework/attributor/src/test/attribution/documents/**/*.json",
            "packages/test/snapshots/content/**",
            "packages/tools/fluid-runner/src/test/localOdspSnapshots/**",
            "packages/tools/fluid-runner/src/test/telemetryExpectedOutputs/**",
            "tools/api-markdown-documenter/src/test/snapshots/**",

            // Generated type-tests
            "**/*.generated.ts",

            // Generated bundle analysis files
            "**/bundleAnalysis/**",

            // Generated oclif manifest files
            "**/oclif.manifest.json",

            // es5 build output
            "packages/framework/data-object-base/es5",

            // Test coverage reports
            "**/coverage/*",
            "**/nyc/*",

            // Git configuration file
            ".git-blame-ignore-revs",

            // Generated by policy-check
            "**/assertionShortCodesMap.ts",

            // This is a test file
            "tools/markdown-magic/test/include.md",

            // Autogenerated file
            ".github/fabricbot.json",

            // These are actually templates, not pure YAML files
            "**/templates/*.yaml",

            // These files are auto-generated according to the comments in the files
            "**/charts/**/Chart.yaml",

            // Reports generated by dependency-cruiser
            "**/.dependency-cruiser-known-violations.json",

            // Paths below are outside the client release group and aren't configured for biome.
            "common/build/**",
            "common/lib/**",
            "docs/**",
            "server/**",
            "tools/api-markdown-documenter/**",
            "tools/benchmark/**",
            "tools/changelog-generator-wrapper/**",
            "tools/getkeys/**",
            "tools/markdown-magic/**",
            "tools/pipelines/**",
            "tools/telemetry-generator/**",
            "tools/test-tools/**"
        ],
        "maxSize": 2097152
    },
    "organizeImports": {
        "enabled": false
    },
    "linter": {
        "enabled": false,
        "rules": {
            "recommended": true
        }
    },
    "formatter": {
        "enabled": true,
        "ignore": ["**/dist/**", "**/lib/**"],
        "formatWithErrors": true,
        "indentStyle": "tab",
        "lineWidth": 95,
        "lineEnding": "lf"
    },
    "javascript": {
        "formatter": {
            "arrowParentheses": "always",
            "jsxQuoteStyle": "double",
            "semicolons": "always",
            "trailingCommas": "all",
            "quoteProperties": "preserve",
            "quoteStyle": "double",
            "bracketSpacing": true
        }
    },
    "json": {
        "formatter": {
            "indentStyle": "tab"
        }
    },
    "overrides": [
        {
            // @fluid-experimental/tree FORMATTING
            // This configuration is used to format the @fluid-experimental/tree package, which uses different settings than
            // most projects. This override is needed to ensure that the formatter is applied correctly when run from the root
            // of the repo.
            //
            // This configuration should be kept up-to-date with the settings in `experimental/dds/tree/biome.jsonc`.
            "include": ["experimental/dds/tree/**"],
            "formatter": {
                "lineWidth": 120
            },
            "javascript": {
                "formatter": {
                    "jsxQuoteStyle": "single",
                    "trailingCommas": "es5",
                    "quoteStyle": "single"
                }
            }
        },
        {
            // JSONC WITHOUT TRAILING COMMAS JSONC is not a standard, and support for trailing commas is not universal. For
            // simplicity and safety, we parse most JSONC files in a liberal way -- allowing comments and trailing commas, but
            // format them conservatively without trailing commas.
            //
            // See also: https://github.com/microsoft/vscode/issues/102061
            "include": [
                "**/*.jsonc",

                // Tools reading api-extractor config files do not consistently support trailing commas.
                "**/api-extractor*.json",

                // Tools reading tsdoc config files do not consistently support trailing commas.
                "**/tsdoc*.json"
            ],
            "json": {
                "parser": {
                    "allowComments": true,
                    "allowTrailingCommas": true
                },
                "formatter": {
                    "trailingCommas": "none"
                }
            }
        },
        {
            // JSONC WITH TRAILING COMMAS
            // These JSONC files are known to support trailing commas.
            "include": [
                // vscode config files all support trailing commas.
                "**/.vscode/*.json",

                // tsconfig files support trailing commas.
                "**/tsconfig*.json"
            ],
            "json": {
                "parser": {
                    "allowComments": true,
                    "allowTrailingCommas": true
                },
                "formatter": {
                    "trailingCommas": "all"
                }
            }
        },
        {
            // PACKAGE.JSON
            // These settings are used to format package.json files in the way npm itself does, with the exception of using
            // tabs instead of spaces.
            "include": ["**/package.json"],
            "json": {
                "formatter": {
                    "lineWidth": 1
                }
            }
        }
    ]
}

Playground link

https://biomejs.dev/playground/?indentStyle=space&indentWidth=4&code=ZQB4AHAAbwByAHQAIABjAGwAYQBzAHMAIABmAG8AbwB7AAoAAyADIGMAbwBuAHMAdAAgAG8AbABkACAAPQAgADEAOwAKAAMgAyBjAG8AbgBzAHQAIAByAGUAbQBvAHQAZQAgAD0AIAAyADsACgB9AA%3D%3D&jsx=false

Code of Conduct

anthony-murphy commented 1 month ago

The playground link hits the issue, but it is a bit artificial. I've hit this for real due to missing an opening bracket on a condition, so the subsequent closing bracket closes the function scope, but leaves code dangling in the class scope. it would be better if biome did nothing like prettier does, rather than further corrupting the file.