Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/usr/bin/env python2
import sys
from sys import stdout
import re
from jsbeautifier import beautify, default_options
tests_passed = 0
opts = default_options()
opts.indent_size = 4
opts.indent_char = ' '
opts.preserve_newlines = True
opts.jslint_happy = False
opts.keep_array_indentation = False
opts.brace_style = 'collapse'
def test_fragment(input, expectation = None):
global opts
if expectation == None:
expectation = input
res = beautify(input, opts)
if res != expectation:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import io
import os
import copy
import jsbeautifier
options = jsbeautifier.default_options()
options.wrap_line_length = 80
data = ''
data_min = ''
def beautifier_test_underscore():
jsbeautifier.beautify(data, options)
def beautifier_test_underscore_min():
jsbeautifier.beautify(data_min, options)
def beautifier_test_github_min():
jsbeautifier.beautify(github_min, options)
def style(self, code):
opts = jsbeautifier.default_options()
opts.end_with_newline = True
opts.operator_position = "preserve-newline"
opts.wrap_line_length = 132
opts.brace_style = "collapse,preserve-inline"
opts.keep_array_indentation = True
return jsbeautifier.beautify(code, opts)
def __call__(self, data, **metadata):
opts = jsbeautifier.default_options()
opts.indent_size = 2
data = data.decode("utf-8", "replace")
res = jsbeautifier.beautify(data, opts)
return "JavaScript", format_text(res)
# coding: u8
import jsbeautifier
opts = jsbeautifier.default_options()
opts.indent_size = 2
opts.break_chained_methods = True
opts.comma_first = True
min_js_file_path = '../wx7c8d593b2c3a7703_3.wxapkg.unpack/game.js'
res = jsbeautifier.beautify_file(min_js_file_path)
open('./game.beautified2.js', 'w').write(res)
def run(self, edit):
settings = self.view.settings()
opts = jsbeautifier.default_options()
for (k,v) in opts.__dict__.items():
if s.has(k):
setattr(opts,k,s.get(k))
# try to make it useful without any settings per project
if s.get('use_original_indentation',False):
setattr(opts,'indent_with_tabs',not settings.get('translate_tabs_to_spaces'))
setattr(opts,'indent_size',int(settings.get('tab_size', 8)))
selection = self.view.sel()[0]
formatSelection = False
# formatting a selection/highlighted area
if(len(selection) > 0):
formatSelection = True
if formatSelection:
self.format_selection(edit, opts)
else:
def content(self, data):
assert isinstance(data, (bytes, bytearray))
if not JSBEAUTIFIER:
LOGGER.warning('jsbeautifier is not available')
return
opts = jsbeautifier.default_options()
opts.unescape_strings = True
try:
data = jsbeautifier.beautify(data.decode(), opts)
except (UnicodeDecodeError, TypeError) as e:
self._error = e
return
self._content = bytearray(data.encode())
def get_js_formatted(self, codestr):
opts = jsbeautifier.default_options()
opts.eval_code = False
# pull indentation from user prefs
use_tab = self.user_settings.get('translate_tabs_to_spaces',False)
if use_tab:
opts.indent_with_tabs = True
else:
opts.indent_char = " "
opts.indent_size = int(self.user_settings.get('tab_size',False))
# pull the rest of settings from our config
for k,v in self.settings.get('jsformat', {}).iteritems():
setattr(opts, k, v)
return jsbeautifier.beautify(codestr, opts)