Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 The formatter is removing a lot of code when saved with incorrect syntax. #1688

Closed
1 task done
franklinjavier opened this issue Jan 26, 2024 · 4 comments
Closed
1 task done
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@franklinjavier
Copy link

franklinjavier commented Jan 26, 2024

Environment information

CLI:
  Version:                      1.5.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           macos

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v21.6.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         unset

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

Workspace:
  Open Documents:               0


---

I tested with 1.5.0 and it happened too.

Configuration

{
  "$schema": "https://biomejs.dev/schemas/1.4.1/schema.json",
  "organizeImports": {
    "include": ["app/**"],
    "enabled": true
  },
  "files": {
    "ignoreUnknown": true
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true,
      "nursery": {
        "noUnusedImports": "error"
      },
      "style": {
        "noParameterAssign": "off"
      },
      "a11y": {
        "noSvgWithoutTitle": "off"
      },
      "suspicious": {
        "noExplicitAny": "off",
        "noImplicitAnyLet": "off",
        "noArrayIndexKey": "off"
      },
      "complexity": {
        "noForEach": "off"
      },
      "security": {
        "noDangerouslySetInnerHtml": "off"
      }
    }
  },
  "formatter": {
    "enabled": true,
    "formatWithErrors": false,
    "indentStyle": "space",
    "indentWidth": 2,
    "lineWidth": 100,
    "lineEnding": "lf"
  },
  "javascript": {
    "formatter": {
      "enabled": true,
      "arrowParentheses": "always",
      "jsxQuoteStyle": "double",
      "semicolons": "asNeeded",
      "trailingComma": "all",
      "quoteStyle": "single",
      "bracketSpacing": true,
      "bracketSameLine": false
    }
  },

  "vcs": {
    "enabled": true,
    "clientKind": "git",
    "useIgnoreFile": true
  }
}

settings.json

{
  "editor.codeActionsOnSave": {
    "quickfix.biome": "explicit",
    "source.organizeImports.biome": "explicit"
  },
  "editor.formatOnPaste": true,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "biomejs.biome",
  "tailwindCSS.includeLanguages": {
    "html": "html",
    "javascript": "javascript",
    "css": "css"
  },
  "editor.quickSuggestions": {
    "strings": true
  },
  "tailwindCSS.experimental.classRegex": [":\\s*?[\"'`]([^\"'`]*).*?,"],
  "[typescriptreact]": {
    "editor.defaultFormatter": "biomejs.biome"
  },
  "[typescript]": {
    "editor.defaultFormatter": "biomejs.biome"
  },
  "[javascript]": {
    "editor.defaultFormatter": "biomejs.biome"
  },
  "explorer.fileNesting.enabled": true,
  "explorer.fileNesting.patterns": {
    "package.json": ".eslint*, prettier*, tsconfig*, vite*, pnpm-lock*, bun.lockb, nest*, biome*, .editorconfig*, .nvmrc*, .gitignore*",
    "tailwind.config.*": "tailwind.config*, postcss.config*",
    ".env.local": ".env*",
    ".env": ".env*"
  }
}

Playground link

Screen.Recording.2024-01-26.at.21.27.29.mov

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@franklinjavier franklinjavier changed the title 📝 Formatter is getting rid of a lot of code when save with wrong syntax 📝 The formatter is removing a lot of code when saved with incorrect syntax. Jan 26, 2024
@ematipico ematipico added the S-Needs repro Status: needs a reproduction label Jan 27, 2024
@ematipico ematipico removed the S-Needs repro Status: needs a reproduction label Jan 29, 2024
@erickreutz
Copy link

This happens to me as well

@ematipico
Copy link
Member

I identified the issue. The issue comes from the rule noUnusedImports. If you turn it off, it won't break your code.

@ematipico ematipico added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Feb 2, 2024
@ematipico
Copy link
Member

Duplicate of #688

@ematipico ematipico marked this as a duplicate of #688 Feb 2, 2024
@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

No branches or pull requests

3 participants