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

VSCODE onFormatSave inserting custom spaces and not detecting indentation #17079

Closed
basickarl opened this issue Dec 12, 2016 · 11 comments
Closed
Assignees
Labels
formatting Source formatter issues info-needed Issue requires more information from poster javascript JavaScript support issues

Comments

@basickarl
Copy link

basickarl commented Dec 12, 2016

Steps to Reproduce: I have no idea but I'll give you how the project is setup.

My issue is that vscode is automatically inserting 4 spaces into my code with formatOnSave when I open a new file which is already indented with 2 spaces.

settings.json

// Place your settings in this file to overwrite the default settings
{
  "editor.formatOnSave": true,
  "editor.fontSize": 13,
  "editor.insertSpaces": true,
  "editor.detectIndentation": true,
  "terminal.integrated.shell.linux": "/bin/bash"
}

working space:

// Place your settings in this file to overwrite default and user settings.
{
}

My files otherwise run on eslint with the following .eslintrc file:

{
  "root": true,
  "extends": "./node_modules/eslint-config-airbnb/base.js",
  "env": {
    "node": true,
    "es6": true
  },
  "rules": {
    // Relaxing, should remove them eventually
    "func-names": 0,
    "comma-dangle": 0,
    "no-unused-vars": [
      2,
      {
        "vars": "local",
        "args": "none"
      }
    ],
    "new-cap": 0,
    // Restricting
    "max-len": [
      2,
      100,
      2
    ],
    "arrow-parens": [
      2,
      "as-needed"
    ],
    "prefer-const": 2,
    "strict": 0
  },
  "globals": {
    "__rootDir": true,
    "describe": true,
    "before": true,
    "after": true,
    "it": true,
    "beforeEach": true,
    "afterEach": true
  },
  "parser": "babel-eslint"
}

I tried turning eslint off but the problem persists.

How do i fix this? I first click on "Indent Using spaces" and choose "3". I then edit the file and save, this fixes the spacing from 4 to 3. Then I redo the step and select "2", edit and save and the file then rejumps to 2 spaces.

It states that my tab is set to 4 spaces.

I don't understand as I have auto indentation set to true. Rest of the people in my project do not have any issues. Then again, none of them are using vscode.

Anymore info? Please ask!

@mjbvz mjbvz added formatting Source formatter issues javascript JavaScript support issues labels Dec 12, 2016
@waderyan
Copy link

@basickarl thank you for opening this issue and for the impeccable detail!

I believe this is a duplicate of microsoft/TypeScript#10335

@waderyan waderyan added the *duplicate Issue identified as a duplicate of another issue(s) label Jan 12, 2017
@manast
Copy link

manast commented Jan 13, 2017

I do not think this is a duplicate, I am suffering the same issue and it really is a PITA... I have been using Code for several years, and suddenly today this thing happens. Every time I save a modified file all the code is automatically indented to 4 spaces, even if the settings is explicitly set to 2 spaces, and also, why would the code be reformatted when saving? I don't want that... My user settings:

// Place your settings in this file to overwrite the default settings
{
    "editor.renderWhitespace": true,
    "javascript.validate.lint.comparisonOperatorsNotStrict": "warning",
    // Controls if the editor will insert spaces for tabs. If set to auto, the value will be guessed based on the opened file.
    "editor.insertSpaces": "true",
    "editor.tabSize": 2,
}

I am having the same issue when editing javascript or java... Code version 1.8.1

@manast
Copy link

manast commented Jan 13, 2017

workaround for me was to roll back to code 1.5.3.

@basickarl
Copy link
Author

@manast I'll try a rollback and get back, see if it works.

@basickarl
Copy link
Author

@waderyan I checked the other issue and it's not related. We don't use TypeScript and the issue isn't affecting consistency. The formatting is consistent but it inserts 4 spaces instead of 2.

@waderyan
Copy link

@basickarl understood. Thank you for investigating further. My mistake. Let me take a look at it again.

@waderyan waderyan reopened this Jan 18, 2017
@waderyan waderyan removed the *duplicate Issue identified as a duplicate of another issue(s) label Jan 18, 2017
@basickarl
Copy link
Author

@waderyan No worries! Just ask if you need any information about my setup/build!

This affects me on both my laptops I must add. Both are running Linux (Ubuntu 16.04 [as stated above] and ElementaryOS Freya [which itself is based off of Ubuntu 14.04])

@mjbvz mjbvz added the info-needed Issue requires more information from poster label Apr 11, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Apr 11, 2017

@basickarl Are you still running into this issue with the latest VSCode release?

If you are, please try collecting the TypeScript server log:

  1. In VSCode 1.11, add a setting"typescript.tsserver.log": "verbose"
  2. Reload VSCode and reproduce the issue
  3. Run the Open TS Server Log file command
  4. Share the output from there.

TypeScript powers both our JavaScript and TypeScript language features and provides document formatting functionality

@basickarl
Copy link
Author

@mjbvz I'll have a look into it!

@waderyan waderyan removed their assignment Jul 13, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented Oct 27, 2017

Closing this out. If anyone is still running into this issue on the latest VS Code insiders builds, please open a new issue and I will take a look

@mjbvz mjbvz closed this as completed Oct 27, 2017
@manast
Copy link

manast commented Oct 27, 2017

As a complementary note, I managed to resolve my issue removing all config directories of VSCode in my mac, such as ~.vscode. After that the issue disappeared. Maybe some setting from version 1.5.3 that was incompatible with newer versions.

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
formatting Source formatter issues info-needed Issue requires more information from poster javascript JavaScript support issues
Projects
None yet
Development

No branches or pull requests

4 participants