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
14.26k stars 440 forks source link

📝 Empty line with no indentation between strings in comment: .graphql files #3924

Open danielkaxis opened 2 days ago

danielkaxis commented 2 days ago

Environment information

CLI:
  Version:                      1.9.1
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v18.20.4"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "yarn/3.8.4"

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

Formatter:
  Format with errors:           false
  Indent style:                 Space
  Indent width:                 2
  Line ending:                  Lf
  Line width:                   80
  Attribute position:           Auto
  Bracket spacing:              BracketSpacing(true)
  Ignore:                       []
  Include:                      []

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

JSON Formatter:
  Enabled:                      true
  Indent style:                 Space
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Trailing Commas:              unset

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

GraphQL Formatter:
  Enabled:                      false
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Bracket spacing:              unset
  Quote style:                  unset

Workspace:
  Open Documents:               0

Configuration

{
  "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
  "organizeImports": {
    "enabled": true
  },
  "formatter": {
    "enabled": true,
    "indentStyle": "space",
    "indentWidth": 2
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true,
      "a11y": {
        "useAltText": "off",
        "useKeyWithClickEvents": "off",
        "noSvgWithoutTitle": "off",
        "noAriaUnsupportedElements": "off",
        "noNoninteractiveTabindex": "off",
        "useHeadingContent": "off",
        "useValidAriaRole": "off",
        "noLabelWithoutControl": "off",
        "useSemanticElements": "off"
      },
      "complexity": {
        "noForEach": "off",
        "useLiteralKeys": "off",
        "useSimpleNumberKeys": "off",
        "useArrowFunction": "off",
        "noUselessTernary": "off",
        "useRegexLiterals": "off"
      },
      "correctness": {
        "useIsNan": "off",
        "useHookAtTopLevel": "error",
        "noUnusedImports": "error"
      },
      "performance": {
        "noAccumulatingSpread": "off"
      },
      "style": {
        "useExponentiationOperator": "off",
        "noParameterAssign": "off",
        "useEnumInitializers": "off",
        "useFragmentSyntax": "error",
        "useLiteralEnumMembers": "off",
        "useNamingConvention": "off",
        "useImportType": "off",
        "useNumberNamespace": "off",
        "noUselessElse": "off",
        "useExportType": "off"
      },
      "suspicious": {
        "noArrayIndexKey": "off",
        "noConsoleLog": "off",
        "noImplicitAnyLet": "off",
        "noThenProperty": "off",
        "noExportsInTest": "off"
      }
    }
  },
  "javascript": {
    "formatter": {
      "quoteStyle": "single",
      "jsxQuoteStyle": "single",
      "semicolons": "asNeeded",
      "trailingCommas": "es5",
      "quoteProperties": "preserve"
    }
  },
  "json": {
    "formatter": {
      "enabled": true,
      "indentStyle": "space"
    },
    "parser": {
      "allowComments": true
    }
  }
}

Playground link

https://github.com/danielkaxis/biome-graphql-issue

Code of Conduct

ematipico commented 2 days ago

Any chance you can use the playground?

Tigge commented 2 days ago

Any chance you can use the playground?

https://biomejs.dev/playground/?files.main.graphql=dAB5AHAAZQAgAEYAbwBvACAAewAKACAAIAAiACIAIgAKACAAIABJACcAbQAgAGEAbgAgAGkAbgBkAGUAbgB0AGUAZAAgAGwAbwBuAGcAIABzAHQAcgBpAG4AZwAuAAoACgAgACAAVwBpAHQAaAAgAHQAdwBvACAAZQBtAHAAdAB5ACAAbABpAG4AZQBzAC4ACgAgACAAIgAiACIACgAgACAAYgBhAHIAOgAgAEkAbgB0AAoAfQA%3D

Here is a playground. Doesn't show any Biome output since it encounters this error:

Biome encountered an unexpected error

This is a bug in Biome, not an error in your code, and we would appreciate it if you could report it to https://github.com/biomejs/biome/issues/ along with the following information to help us fixing the issue:

Source Location: crates/biome_graphql_formatter/src/graphql/value/string_value.rs:45:51
Thread Name: biome::worker_5
Message: byte index 2 is out of bounds of ``
ematipico commented 2 days ago

Awesome, thank you. It seems there's a parsing error

ematipico commented 1 day ago

cc @vohoanglong0107

vohoanglong0107 commented 1 day ago

I think I've found out the cause. In this line

https://github.com/biomejs/biome/blob/2578a23631bfeeb41674e5507429afb6dd54496e/crates/biome_graphql_formatter/src/graphql/value/string_value.rs#L45

It's trying to remove the indentation from the comment by the minimum indent level of the entire block comment.

But at the same time, in this line

https://github.com/biomejs/biome/blob/2578a23631bfeeb41674e5507429afb6dd54496e/crates/biome_graphql_formatter/src/graphql/value/string_value.rs#L30

The formatter explicitly ignores empty lines, so min_indent does not factor in empty lines in its calculation. So when the formatter encounters an empty line, it still tries to extract min_indent from that line, which causes it to panic.

I will push a fix for this sometime tomorrow.