Skip to content

Extension removes final newline on save, conflicting with ESLint's eol-last rule #13

@mahmoudadel54

Description

@mahmoudadel54

📋 Summary

When customImportSort.sortOnSave is enabled, the extension strips the final newline character (\n) when rewriting the file after sorting imports. This directly conflicts with ESLint's eol-last rule (which requires files to end with exactly one newline) and creates a frustrating save loop:

  1. File saved with final \n
  2. Extension sorts imports → removes final \n
  3. ESLint reports eol-last error

Steps to Reproduce

  1. Install custom-import-sort extension
  2. Set "customImportSort.sortOnSave": true in VS Code settings
  3. Enable ESLint rule: "eol-last": ["error", "always"] in .eslintrc
  4. Enable ESLint auto-fix on save: "editor.codeActionsOnSave": ["source.fixAll.markdownlint", "source.fixAll.eslint"],
  5. Open a .js/.jsx file that ends with a newline
  6. Press Ctrl+S (or Cmd+S)
  7. Observe that the final newline is removed and ESLint triggers eol-last

✅ Expected Behavior

  • The extension should preserve the file's trailing newline when writing sorted imports
  • Files should continue to comply with eol-last after auto-sorting
  • No lint errors should appear after a normal save

❌ Actual Behavior

  • The extension overwrites the file without a trailing newline
  • ESLint immediately flags eol-last
  • Developers must manually re-add the newline or wait for ESLint's auto-fix, creating a broken workflow

🖥️ Environment

  • VS Code Version: 1.121.0
  • Extension Version: 1.0.6
  • OS: [Windows 11]
  • ESLint Version: 7.8.1
  • Node Version: 22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions