code cleanup
This commit is contained in:
parent
0907e45be7
commit
7aacb2de85
|
@ -19,5 +19,11 @@
|
|||
// Example: /usr/bin/local/jq
|
||||
// Example: jq
|
||||
"jq_binary": "jq",
|
||||
"jq_errors": false
|
||||
"jq_errors": false,
|
||||
"as_json":[
|
||||
"JSON",
|
||||
"Sublime Text Commands",
|
||||
"Sublime Text Settingss",
|
||||
"Sublime Text Menu"
|
||||
]
|
||||
}
|
|
@ -11,7 +11,7 @@ import sublime_plugin
|
|||
from .lib import simplejson as json
|
||||
from .lib.simplejson import OrderedDict
|
||||
|
||||
SUBLIME_MAJOR_VERSION = int(sublime.version()) / 1000
|
||||
|
||||
PREVIOUS_CONTENT = [str(), str()]
|
||||
PREVIOUS_QUERY_LEN = int()
|
||||
|
||||
|
@ -95,13 +95,8 @@ class PrettyJsonBaseCommand:
|
|||
if s.get("brace_newline", True):
|
||||
output_json = PrettyJsonBaseCommand.brace_newline.sub(r'\1\n\2\3', output_json)
|
||||
|
||||
|
||||
|
||||
return output_json
|
||||
|
||||
def brace_bracket_newline(json_data: str) -> str:
|
||||
better_json = PrettyJsonBaseCommand.brace_bracket_newline.sub(r'\1\n\2\3', json_data)
|
||||
return better_json
|
||||
|
||||
def reindent(self, text: str, selection: str):
|
||||
current_line = self.view.line(selection.begin())
|
||||
|
@ -221,7 +216,6 @@ class PrettyJsonValidate(PrettyJsonBaseCommand, sublime_plugin.TextCommand):
|
|||
return result
|
||||
|
||||
|
||||
|
||||
class PrettyJsonCommand(PrettyJsonBaseCommand, sublime_plugin.TextCommand):
|
||||
'''
|
||||
Description: Pretty Print JSON
|
||||
|
@ -328,7 +322,6 @@ class UnPrettyJsonCommand(PrettyJsonBaseCommand, sublime_plugin.TextCommand):
|
|||
class JqInsertPrettyJsonCommand(sublime_plugin.TextCommand):
|
||||
def run(self, edit, string):
|
||||
self.view.replace(edit, sublime.Region(0, self.view.size()), string)
|
||||
# self.view.sel().clear()
|
||||
|
||||
|
||||
class JqPrettyJsonCommand(sublime_plugin.TextCommand):
|
||||
|
|
|
@ -5,16 +5,18 @@ from .PrettyJson import PrettyJsonBaseCommand
|
|||
|
||||
s = sublime.load_settings("Pretty JSON.sublime-settings")
|
||||
|
||||
|
||||
class PrettyJsonLintListener(sublime_plugin.EventListener, PrettyJsonBaseCommand):
|
||||
def on_post_save(self, view):
|
||||
validate = s.get('validate_on_save', True)
|
||||
if not s.get('validate_on_save', True):
|
||||
return
|
||||
|
||||
as_json = s.get('as_json', ['JSON'])
|
||||
if validate and any(
|
||||
if any(
|
||||
syntax in view.settings().get("syntax") for syntax in as_json
|
||||
):
|
||||
self.view = view
|
||||
PrettyJsonBaseCommand.clear_phantoms(self)
|
||||
json_content = self.view.substr(sublime.Region(0, self.view.size()))
|
||||
json_content = view.substr(sublime.Region(0, view.size()))
|
||||
try:
|
||||
self.json_loads(json_content)
|
||||
except Exception as ex:
|
||||
|
@ -23,9 +25,11 @@ class PrettyJsonLintListener(sublime_plugin.EventListener, PrettyJsonBaseCommand
|
|||
|
||||
class PrettyJsonAutoPrettyOnSaveListener(sublime_plugin.EventListener):
|
||||
def on_pre_save(self, view):
|
||||
auto_pretty = s.get('pretty_on_save', False)
|
||||
if not s.get('pretty_on_save', False):
|
||||
return
|
||||
|
||||
as_json = s.get('as_json', ['JSON'])
|
||||
if auto_pretty and any(
|
||||
if any(
|
||||
syntax in view.settings().get('syntax') for syntax in as_json
|
||||
):
|
||||
sublime.active_window().run_command('pretty_json')
|
||||
|
|
Loading…
Reference in New Issue