Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
ignore=.cache,.git,.idea,__pycache__,messages,screenshots

[MESSAGES CONTROL]
disable=missing-docstring,too-many-branches,too-many-public-methods,unidiomatic-typecheck,len-as-condition,too-many-return-statements,too-many-statements,fixme,too-many-locals,too-many-arguments,invalid-name,inconsistent-return-statements,too-many-lines,relative-beyond-top-level,too-many-nested-blocks,no-self-use,too-few-public-methods,consider-using-in,no-else-continue,consider-using-with
disable=missing-docstring,too-many-branches,too-many-public-methods,unidiomatic-typecheck,len-as-condition,too-many-return-statements,too-many-statements,fixme,too-many-locals,too-many-arguments,too-many-positional-arguments,invalid-name,inconsistent-return-statements,too-many-lines,relative-beyond-top-level,too-many-nested-blocks,too-few-public-methods,consider-using-in,no-else-continue,no-else-return,consider-using-with,consider-using-f-string,useless-object-inheritance,cyclic-import,too-many-boolean-expressions,import-outside-toplevel,redundant-u-string-prefix,use-yield-from

[FORMAT]
max-line-length=120
expected-line-ending-format=LF

[TYPECHECK]
ignored-modules=sublime,sublime_plugin
ignored-modules=sublime,sublime_plugin,jsprettier.const,jsprettier.sthelper,jsprettier.util
37 changes: 14 additions & 23 deletions JsPrettier.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,29 +474,20 @@ def should_show_plugin(self):
return False
if self.allow_inline_formatting is True:
return True
if self.is_source_js(view) is True:
return True
if self.is_less(view) is True:
return True
if self.is_scss(view) is True:
return True
if self.is_css(view) is True:
return True
if self.is_angular_html(view) is True:
return True
if self.is_mdx(view) is True:
return True
if self.is_markdown(view) is True:
return True
if self.is_yaml(view) is True:
return True
if self.is_php(view) is True:
return True
if self.is_html(view) is True:
return True
if is_file_auto_formattable(view) is True:
return True
return False
is_supported_syntax = (
self.is_source_js,
self.is_less,
self.is_scss,
self.is_css,
self.is_angular_html,
self.is_mdx,
self.is_markdown,
self.is_yaml,
self.is_php,
self.is_html,
is_file_auto_formattable,
)
return any(check(view) for check in is_supported_syntax)

def is_visible(self):
return self.should_show_plugin()
Expand Down
21 changes: 10 additions & 11 deletions jsprettier/sthelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,17 @@ def get_st_project_path():
folders = window.folders()
if len(folders) == 1:
return folders[0]
active_view = window.active_view()
if active_view:
active_file_name = active_view.file_name()
else:
active_view = window.active_view()
if active_view:
active_file_name = active_view.file_name()
else:
active_file_name = None
if not active_file_name:
return folders[0] if len(folders) else os.path.expanduser('~')
for folder in folders:
if active_file_name.startswith(folder):
return folder
return os.path.dirname(active_file_name)
active_file_name = None
if not active_file_name:
return folders[0] if len(folders) else os.path.expanduser('~')
for folder in folders:
if active_file_name.startswith(folder):
return folder
return os.path.dirname(active_file_name)


def scroll_view_to(view, row_no, col_no):
Expand Down
16 changes: 5 additions & 11 deletions jsprettier/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@

from re import sub

from .const import IS_PY2
from .const import PLUGIN_NAME
from .const import PRETTIER_CONFIG_FILES
from .const import PRETTIER_IGNORE_FILE

if IS_PY2:
text_type = unicode
string_types = (str, unicode)
else:
text_type = str
string_types = (str,)
text_type = type(u'')
string_types = (str, text_type)


def is_windows():
Expand Down Expand Up @@ -139,7 +134,7 @@ def _prettier_opts_in_package_json(package_json_file):
try:
with open(package_json_file) as package_file:
json_data = json.load(package_file)
except Exception:
except (IOError, ValueError):
from .sthelper import log_warn
log_warn("Could not parse package.json file: '{0}'. Any Prettier options "
"defined in this file will be ignored.".format(package_json_file), True)
Expand Down Expand Up @@ -387,16 +382,15 @@ def format_error_message(error_message, error_code):
return '\nPrettier produced the following output:\n\n' \
'{0}\n' \
'\nPrettier process finished with exit code {1}.\n' \
.format(error_message, '{0}'.format(error_code))
.format(error_message, error_code)


def format_debug_message(label, message, debug_enabled=False):
if not debug_enabled:
return
header = ' {0} DEBUG - {1} '.format(PLUGIN_NAME, label)
horizontal_rule = repeat_str('-', len(header))
print('\n{0}\n{1}\n{2}\n\n''{3}'.format(
horizontal_rule, header, horizontal_rule, message))
print('\n{0}\n{1}\n{0}\n\n{2}'.format(horizontal_rule, header, message))


def get_cli_arg_value(additional_cli_args, arg_key, arg_val_can_be_empty=False, default=None):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
flake8
pep8-naming
pytest>=9.0.3
pylint==2.13.9
pylint==4.0.9
15 changes: 6 additions & 9 deletions tests/validate_json_format.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import codecs
import io
import json
import re

Expand Down Expand Up @@ -117,8 +117,7 @@ def evaluate(m):
txt = g["code"]
return txt

content = ''.join(
map(lambda m: evaluate(m), RE_COMMENT.finditer(text)))
content = ''.join(evaluate(m) for m in RE_COMMENT.finditer(text))
return content

def check_dangling_commas(self, text):
Expand All @@ -131,16 +130,14 @@ def check_comma(g, line):
self.log_failure(E_COMMA, line)
if g["square_comma"] is not None:
return g["square_ws"] + g["square_bracket"]
else:
return g["curly_ws"] + g["curly_bracket"]
return g["curly_ws"] + g["curly_bracket"]

def evaluate(m):
g = m.groupdict()
return check_comma(g, self.get_line(m.start(0))) \
if g["code"] is None else g["code"]

return ''.join(
map(lambda m: evaluate(m), RE_TRAILING_COMMA.finditer(text)))
return ''.join(evaluate(m) for m in RE_TRAILING_COMMA.finditer(text))

def log_failure(self, code, line=None):
"""Log failure.
Expand All @@ -156,7 +153,7 @@ def log_failure(self, code, line=None):
def check_format(self, file_name):
"""Initiate the check."""
self.fail = False
with codecs.open(file_name, encoding='utf-8') as f:
with io.open(file_name, encoding='utf-8') as f:
count = 1
for line in f:
if count == 1 and line.strip() == '':
Expand All @@ -179,7 +176,7 @@ def check_format(self, file_name):
text = self.check_dangling_commas(text)
try:
json.loads(text)
except Exception as e:
except ValueError as e:
self.log_failure(E_MALFORMED)
print(e)
return self.fail
Expand Down
Loading