Giter Club home page Giter Club logo

jsformat's People

Contributors

aodev avatar badsyntax avatar bbaliguet avatar bitdeli-chef avatar bitwiseman avatar brice avatar burtbeckwith avatar chiefjester avatar ckknight avatar darkprogrammer16 avatar dasl- avatar dertseha avatar dustinchilson avatar gitter-badger avatar gsemet avatar jdavisclark avatar joecabezas avatar katiek2 avatar martijnr avatar mathieug avatar monte-hayward avatar robinjmurphy avatar sgerace avatar ticky avatar timonwong avatar titobouzout avatar tomfuertes avatar wuilliam321 avatar yangsu avatar zachary-kuhn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsformat's Issues

One-line if-statements

Could that formatting choice be disabled? I find it really ruins the readability of a simple if-else, e.g.

$(document).on("keyup", "#LocationsForm input", function () {
    if (locationsHaveChanged())
        $('#UpdateLocationsButton').prop('disabled', false);
    else
        $('#UpdateLocationsButton').prop('disabled', true);
});

VS

$(document).on("keyup", "#LocationsForm input", function() {
    if (locationsHaveChanged()) $('#UpdateLocationsButton').prop('disabled', false);
    else $('#UpdateLocationsButton').prop('disabled', true);
});

Or am I supposed to be curly bracing for reasons I haven't gotten into?

Allow method chaining option

The new version of the jsbeautifier library can detected multiple line method chaining and keeps them in separate lines.

Something like this:

textFrame
  .attr("width", 200)
  .attr("height", 200)
  .attr("x", 200)
  .attr("y", 200);

Can you update to the new version of jsbeautifier?

Best Nils

Bad Package Control Install Instructions

README.md states

Package Control
Add https://github.com/jdc0589/JsFormat.git as a Package Control repository. JsFormat will show up in the package install list.

That will return an error in SublimeText2 and will return a 404 in manually clicking on it. I was able to install using https://github.com/jdc0589/JsFormat (removed .git)

Should read:

Package Control
Add https://github.com/jdc0589/JsFormat as a Package Control repository. JsFormat will show up in the package install list.

Package Settings

Hi,
Are there any Package Settings for jsFormat? I can see there are some configurations near the start of the .py files, but are these exposed to the regular package settings files in Sublime Text > Preferences > Package Settings > ...?

Thanks a lot,

Jamie

can't get index_size to work

I don't know much about the sublime plugin system (or python) so I might be all wrong. However:

I want to indent my code with 2 spaces.

Looking at the provided default settings, I could find any such related setup. However, http://jsbeautifier.org/ is showing this as an option.

Looking at the jsbeautifier.py code, I could see the following:

self.indent_size = %d

and so, I added my user config as:

{
 "indent_size": 2
}

This didn't work, I suspect it is because in the plugin code:

        opts.indent_char = " " if settings.get("translate_tabs_to_spaces") else "\t"
        opts.indent_size = int(settings.get("tab_size")) if opts.indent_char == " " else 1

Should actually be:

        opts.indent_char = " " if settings.get("translate_tabs_to_spaces") else "\t"
        opts.indent_size = int(settings.get("indent_size")) if opts.indent_char == " " else 1

Note tab_size ==> indent_size.

Does this makes any sense?

I'm not PRing it because i'm far from being sure on this.

Line Width Limit

It would be awesome if we could get an usersetting that allows the line width to be set to an arbitrary number like 80, 100 or else.

Only User Settings Are Honored

I noticed that the jslint_happy flag wasn't being respected, and when I copied the settings I had configured for the Default user...

{
    // exposed jsbeautifier options
    "indent_with_tabs": false,
    "preserve_newlines": true,
    "max_preserve_newlines": 4,
    "jslint_happy": true,
    "brace_style": "collapse", //collapse, expand, end-expand
    "keep_array_indentation": false,
    "keep_function_indentation": false,
    "eval_code": false,
    "unescape_strings": false,
    "break_chained_methods": false,

    // jsformat options
    "format_on_save": false
}

...and pasted them into the User settings, the flag was honored. Also, I had to dig into the code to find the brace_style options since they weren't listed in the README.

Sublime Text 3: UnboundLocalError

Not sure whether this is Sublime Text 3 specific or not, and I can't verify because I tried throwing the package in Sublime Text 2 and got the following:

Traceback (most recent call last):
  File ".\sublime_plugin.py", line 62, in reload_plugin
  File ".\js_formatter.py", line 13, in <module>
    import jsbeautifier, jsbeautifier.unpackers
ImportError: No module named unpackers

My issue for Sublime Text 3 should be reproduceable, formatting the whole document (with all or no text selected) works fine, however formating a portion (select a line or two, and hit ctrl+alt+f) throws what I pasted below.

Traceback (most recent call last):
  File "D:\Downloads\Sublime Text 3\sublime_plugin.py", line 531, in run_
    return self.run(edit)
  File "D:\Downloads\Sublime Text 3\Data\Packages\Sublime-JS-Beautifier\js_formatter.py", line 83, in run
    _, err = merge_utils.merge_code(self.view, edit, orig, res)
  File "D:\Downloads\Sublime Text 3\Data\Packages\Sublime-JS-Beautifier\libs\merge_utils.py", line 84, in merge_code
    return (dirty, err)
UnboundLocalError: local variable 'err' referenced before assignment

Please add space_before_conditional

Hi,

Just discovered your extension, pretty neat!
I'm a big fan of "Braces on own line" indentation style (aka Allman style, cf wikipedia).
First time an indentation plugin catch my attention outside Visual Studio. But with Sublime: it's light & neat!

Unfortunately, the "Space before conditional" option is missing from the sublime plugin :-(

I tried to look for undocumented option in the code and compared with jsbeautifier.org but this option only exists on the website.

Would be super cool to add this into the sublime plugin.
Thx in advance.

PS:
The documentation does not specify the possible values for brace_style (collapse,expand,end-expand), but I managed to find that in the sources so that's ok.

Multiple new lines before function ()

Hi, when running a perfectly valid code with default pref I get multiple new line before my function declaration. Is it normal ?

// Blablabla
function validateRules(rules, conditions, actions) {
    // code
};

gets indented to this:

// Blablabla


function validateRules(rules, conditions, actions) {
    // code
};

No newline at end of file after format

After format, there's no newline at end of file. Most code style check tool, editor, scm diff tool will give a warning like "\ No newline at end of file"
It would be better to preserve the newline at the end of time by default.

New Option : Non Dizzy Mode

Format long file with Textmate 2 beautifier in bundled Javascript package.

Format long file with Sublime Text JSFormat package

re-position the caret after formatting

currently the caret it is left at the end of the file after formatting. Would be nice to put it back wherever it was before the formatting took place.

Suggestions on the best way to do this? Everything im thinking of is Regex based and seems like it would be pretty unreliable.

how to get the lastest version in sublime text

i've upgraded repositories in package control, but is not downloading the last version:

installed version after upgrade:

package: JsFormat
installed_version: 2012.07.11.14.58.52

how to update jsformat in sublime text 2 in order to get the last version of this repo?, using sublime text 2

Indentation problem with the switch construction

for example i have such code:

switch (item) {
    case 1:
        alert('text-1');
        break;
    case 2:
        alert('text-2');
        break;
    default:
        alert('text-3');
}

after js_format i see such code:

switch (item) {
case 1:
    alert('text-1');
    break;
case 2:
    alert('text-2');
    break;
default:
    alert('text-3');
}

may be i am doing something wrong, but i can't find appropriate option in sublime-settings to fix this

Plugin doesn't load: Cannot import name evalbased

Recently, I started getting this error below on each startup. However, there is an evalbased.py in JsFormat/libs/jsbeautifier/unpackers/.

Reloading plugin /home/thomas/cloud/Dropbox/shared/sublime-text-2/Packages/JsFormat/js_formatter.py
Warning: finish not called
Traceback (most recent call last):
  File "./sublime_plugin.py", line 62, in reload_plugin
  File "./js_formatter.py", line 31, in <module>
    import jsbeautifier, jsbeautifier.unpackers
  File "/home/thomas/cloud/Dropbox/shared/sublime-text-2/Packages/JsFormat/libs/jsbeautifier/unpackers/__init__.py", line 10, in <module>
    from jsbeautifier.unpackers import evalbased
ImportError: cannot import name evalbased

Add .sublime-settings

Add a JsFormat.sublime-settings file with the default settings.

It's a lot quicker to check that in Sublime, than to find the readme.

Keep position

After formatting could the cursor and buffer return to the position you were at when you triggered the plugin?

Anonymous Function vs Named Function Paren Spacing

Hello.

I've noticed that with JsFormat, my anonymous functions are getting formatted like my named functions, as such:

var fn = function NamedFn() {
    // Code
};

var fn2 = function() {
    // More Code
};

On jsbeautifier.org, and the way I've learned/read/seen, anonymous functions have a space between the function keyword and the starting parens.

var fn = function () {
  // Code
};

ImportError: No module named unpackers

hi, I don't know why jsformat can't work. I am using sublime text 2.0.1.
The trace message likes below:

  Traceback (most recent call last):
  File ".\sublime_plugin.py", line 362, in run_
  File ".\js_formatter.py", line 58, in run
  File ".\jsbeautifier\__init__.py", line 99, in beautify

  File ".\jsbeautifier\__init__.py", line 218, in beautify

  File ".\jsbeautifier\__init__.py", line 255, in unpack

ImportError: No module named unpackers

I have checked that jsbeautifier is in the python's sys path.

Can you help me with this?

thanks

Wrongly formatted code

Hello,
when I try to format this code

var log = function(info) {
        var text = document.createTextNode("[Line %1, Column %2] %3".replace(/%[0-9]+/g, function(token) {
        return info[parseInt(token.substring(1), 10) - 1] || token;
    }));

    logsPanel.appendChild(text);
};

the lines inside the function's body get 2 tabs instead of just one

var log = function(info) {
        var text = document.createTextNode("[Line %1, Column %2] %3".replace(/%[0-9]+/g, function(token) {
            return info[parseInt(token.substring(1), 10) - 1] || token;
        }));

        logsPanel.appendChild(text);
    };

Probably something wrong with the inner function

Expected exactly one space between 'if' and '('

Is there a way to configure it to insert a space between

if(foo) vs if (foo) the latter being preferred -- this makes jslint/hint go berzerk and I can't see through all the noize -- plus it isn't a bad rule, since the former could be interpreted as a function invocation

better formatting support in html files?

When in HTML files, unless you highlight/select the contents of your script tag first, JsFormat will screw up your html formatting.

Is there a desire for better formatting support in html files?

"keep_array_indentation": true

When I set the property "keep_array_indentation": true, having a code as follows:

define (['jquery'
     'underscore'
     'backbone'
     'vm'], function ($, _, Backbone, Vm) ...

Every time I format code, it adds a space in my indentation.

Formatting the first time:
define (['jquery'
         'underscore'
         'backbone'
         'vm'], function ($, _, Backbone, Vm) ...

Formatting the second time:
define (['jquery'
             'underscore'
             'backbone'
             'vm'], function ($, _, Backbone, Vm) ...

And so on.

Plugin crash on startup

Hi,

I've installed JSFormat on Sublime Text 2 but it crashes on startup with this error on the console:

Reloading plugin C:\Documents and Settings\%username%\Application Data\Sublime Text 2\Packages\JsFormat\js_formatter.py
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 62, in reload_plugin
  File ".\js_formatter.py", line 27, in <module>
    add_lib_path(libs_path)
  File ".\js_formatter.py", line 21, in add_lib_path
    lib_path = _try_get_short_path(lib_path)
  File ".\js_formatter.py", line 17, in _try_get_short_path
    path = unicode(path)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 29: ordinal not in range(128)
Reloading plugin C:\Documents and Settings\%username%\Application Data\Sublime Text 2\Packages\Package Control\Package Control.py
.\Package Control.py:42: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

I got this error even with all other packages disabled.

Commit 576e6450a6d1e11d855c86592b07ea47ac16fcb5 breaks new line eof on auto save

With respect to commit 576e645

  • Turn on "ensure_newline_at_eof_on_save" in ST2 settings
    • Save a file, see new line is inserted correctly
  • Turn on "format_on_save" in plugin settings while "ensure_newline_at_eof_on_save" is still turned on in ST2 settings
    • Save a file, see no new line is inserted at the end of file and existing eof new lines are removed

Seems to be happening as JSFormat works after sublime save. So although sublime adds a newline, plugin removes it.

Suggested Fix
Restore deleted lines 82, 83 in js_formatter.py, but read sublime setting "ensure_newline_at_eof_on_save" to add newline. No need to read it from plugin settings.

A bit more documentation

It would be super cool if each option was a bit more documented in the README. It's nice to have default values, but some names are not explicit for everyone (me included). Could you add something like :

- "option1_name": "default_value"
  `option1_name` does this and that...
- "option2_name": "default_value"
  `option2_name` does foo and bar...

Thanks in advance.

Contextmenu implementation

What do you think about an implementation for the context menu (more specifically, the right-click menu)?

Does not work with Sublime Text 3 Beta

It seems to be an issue with working directory so that jsbeautifier module cannot be found. Adding the working folder into python's sys path should work.

indentation for chained methods

Would it be possible to add an option like
"method_chaining_indentation": "number"
where

  • number = 0 would mean keeping the current functionality
  • number = 4 would mean indent the chained command by 4 spaces

Examples:
Current:
someObject.doFoo(x).doBar(y).doBaz(z);
Indented (better readability):
someObject.doFoo(x)
.doBar(y)
.doBaz(z);

Thanks,
Chris

ImportError: No module named unpackers

Sublime Text 2 (OSX ML), from the console after a fresh install of JsFormat through Package Control:

Reloading plugin /Users/niko/Library/Application Support/Sublime Text 2/Packages/JsFormat/js_formatter.py
Traceback (most recent call last):
  File "./sublime_plugin.py", line 62, in reload_plugin
  File "./js_formatter.py", line 11, in <module>
    import jsbeautifier, jsbeautifier.unpackers
ImportError: No module named unpackers

"One var" declaration option

I want to write code like:

var a = 1,
    b = 2,
    c = function(){};

But after formatting I always get:

var a = 1,
  b = 2,
  c = function() {};

Sublime Text 3 Unable to open default preferences if different folder name

This is true for default preferences and default keymaps. The issue occurs when the JsFormat folder has been renamed. I don't know how common this is in ST plugins, or how possible it is to get the folder name in python / ST2 API, but implementing a simple lookup for the folder name shouldn't be impossible? (I may be wrong)

Unable to open /D/Downloads/Sublime Text 3/Data/Packages/JsFormat/JsFormat.sublime-settings

As a reference, my actual location is /D/Downloads/Sublime Text 3/Data/Packages/JsFormat-master/JsFormat.sublime-settings

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.