mihai-vlc / sublime-jsfmt

jsfmt plugin for Sublime Text

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indentation issue

Shaked opened this issue · comments

Hey, I am not sure that this is a bug.

When formatting with the tool the following code:

define([
    'jquery',
    'underscore',
    'backbone'
], function(
    $,
    _,
    Backbone
) {
    'use strict';
    return {}
});

It ends up as:

define([
    'jquery',
    'underscore',
    'backbone'
], function(
    $,
    _,
    Backbone
) {
'use strict';
return {};
});

(Notice that the content of the function is not indented.
Is there a way to actually support that?

Thank you!
Shaked

I can't seem to reproduce that issue.
Do you have any jsfmt plugins installed ?

I disabled them but still the same result. Also tried to reinstall the plugin but no luck, this is my configuration file:

{
  // autoformat on save
  "autoformat": true,

  // array of extensions for autoformat
  "extensions": ["js", "sublime-settings"],

  // options for jsfmt
  "options": {
    "preset": "jquery",
    "indent": {
      "value": "    "
    },
    // plugins included
    "plugins": [
      // "esformatter-quotes",
      // "esformatter-semicolons",
      // "esformatter-braces",
      // "esformatter-dot-notation"
    ]
  },
  "options-JSON": {
    "plugins": [
      "esformatter-quotes"
    ],
    "quotes": {
      "type": "double"
    }
  },
  "node-path": "node",
  "alert-errors": true,
  "ignore-selection": false
}

I see you have the preset set to jquery.
If you have a look here you can see all the specific configuration.

The one that causes your problem is TopLevelFunctionBlock.

This is enabled by default, with no special behaviour. When disabled (set to 0), esformatter will not indent top level function blocks (used by the jQuery preset).

So enabling that option will fix your issue:

"options": {
        "preset": "jquery",
        "indent": {
            "value": "    ",
            "TopLevelFunctionBlock" : 1
        }
   }

Please let me know if this is fixed.

Works like a charm!