From e21fa29dc2f0ceedc986e995cc7884a90c110116 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Tue, 7 Feb 2023 08:53:38 -0600 Subject: [PATCH] fix(config): added error message print when config loading fails closes #531 --- src/djlint/__init__.py | 2 -- src/djlint/formatter/attributes.py | 1 - src/djlint/formatter/condense.py | 1 - src/djlint/formatter/css.py | 2 -- src/djlint/formatter/indent.py | 3 --- src/djlint/formatter/js.py | 1 - src/djlint/lint.py | 1 - src/djlint/output.py | 3 --- src/djlint/settings.py | 15 ++++++++------- .../test_config.py | 1 - .../test_preserve_blank_lines/test_config.py | 1 - .../test_preserve_leading_space/test_config.py | 1 - tests/test_html/test_aurelia.py | 1 - tests/test_html/test_basics.py | 6 ------ tests/test_html/test_comments.py | 3 --- tests/test_html/test_symbol_entities.py | 1 - tests/test_html/test_yaml.py | 5 ----- 17 files changed, 8 insertions(+), 40 deletions(-) diff --git a/src/djlint/__init__.py b/src/djlint/__init__.py index 3c10356..81e7afe 100644 --- a/src/djlint/__init__.py +++ b/src/djlint/__init__.py @@ -248,9 +248,7 @@ def main( ascii=progress_char, leave=False, ) as pbar: - for future in as_completed(futures): - file_errors.append(future.result()) pbar.update() elapsed = pbar.format_interval(pbar.format_dict["elapsed"]) diff --git a/src/djlint/formatter/attributes.py b/src/djlint/formatter/attributes.py index 00b0e77..6638b65 100644 --- a/src/djlint/formatter/attributes.py +++ b/src/djlint/formatter/attributes.py @@ -32,7 +32,6 @@ def format_template_tags(config: Config, attributes: str, spacing: int) -> str: indent_adder = spacing or 0 for line_number, line in enumerate(attributes.splitlines()): - # when checking for template tag, use "match" to force start of line check. if re.match( re.compile(config.template_unindent, re.I | re.X), line.strip() diff --git a/src/djlint/formatter/condense.py b/src/djlint/formatter/condense.py index afe9f77..6d1a049 100644 --- a/src/djlint/formatter/condense.py +++ b/src/djlint/formatter/condense.py @@ -136,7 +136,6 @@ def condense_html(html: str, config: Config) -> str: # should we add blank lines before load tags? if config.blank_line_before_tag: for tag in [x.strip() for x in config.blank_line_before_tag.split(",")]: - html = re.sub( re.compile( rf"(? str: # add indent back ignore_indent = False for line in beautified_lines: - if re.search( re.compile( r"\/\*[ ]*?beautify[ ]+?ignore:end[ ]*?\*\/", @@ -38,7 +37,6 @@ def format_css(html: str, config: Config) -> str: ignore_indent = False if ignore_indent is False and line: - beautified += "\n" + inner_indent + line else: beautified += "\n" + line diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index db2ae88..a980ed6 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -37,7 +37,6 @@ def indent_html(rawcode: str, config: Config) -> str: ignored_level = 0 for item in rawcode_flat_list: - # if a raw tag first line if not is_block_raw and is_ignored_block_opening(config, item): is_raw_first_line = True @@ -225,7 +224,6 @@ def indent_html(rawcode: str, config: Config) -> str: def fix_non_handlebars_template_tags( html: str, out_format: str, match: re.Match ) -> str: - if inside_ignored_block(config, html, match): return match.group() @@ -255,7 +253,6 @@ def indent_html(rawcode: str, config: Config) -> str: def fix_handlebars_template_tags( html: str, out_format: str, match: re.Match ) -> str: - if inside_ignored_block(config, html, match): return match.group() diff --git a/src/djlint/formatter/js.py b/src/djlint/formatter/js.py index b846686..d33e1c5 100644 --- a/src/djlint/formatter/js.py +++ b/src/djlint/formatter/js.py @@ -27,7 +27,6 @@ def format_js(html: str, config: Config) -> str: # add indent back ignore_indent = False for line in beautified_lines: - if re.search( re.compile( r"\/\*[ ]*?beautify[ ]+?(?:preserve|ignore):end[ ]*?\*\/", diff --git a/src/djlint/lint.py b/src/djlint/lint.py index e8f8bcf..cbf655e 100644 --- a/src/djlint/lint.py +++ b/src/djlint/lint.py @@ -71,7 +71,6 @@ def lint_file(config: Config, this_file: Path) -> Dict: # rule H025 is a special case where the output must be an even number. if rule["name"] == "H025": - open_tags: List[re.Match] = [] # for match in re.finditer( diff --git a/src/djlint/output.py b/src/djlint/output.py index 0edebc6..8a8bd44 100644 --- a/src/djlint/output.py +++ b/src/djlint/output.py @@ -114,7 +114,6 @@ def build_output(error: dict, config: Config) -> int: ) for message_dict in errors: - line = Fore.BLUE + message_dict["line"] + Style.RESET_ALL code = ( (Fore.RED if message_dict["code"][:1] == "E" else Fore.YELLOW) @@ -205,14 +204,12 @@ def build_stats_output(errors: List[Optional[Any]], config: Config) -> int: ) if messages and codes: - longest_code = len(max(messages.keys(), key=len)) longest_count = len( str(max(Counter(codes).values(), key=lambda x: len(str(x)))) ) for code in sorted(Counter(codes).items()): - code_space = (longest_code - len(str(code[0]))) * " " count_space = (longest_count - len(str(code[1]))) * " " diff --git a/src/djlint/settings.py b/src/djlint/settings.py index 49ff0dd..a89b2e7 100644 --- a/src/djlint/settings.py +++ b/src/djlint/settings.py @@ -29,7 +29,6 @@ logger = logging.getLogger(__name__) def find_project_root(src: Path) -> Path: """Attempt to get the project root.""" for directory in [src, *src.resolve().parents]: - if (directory / ".git").exists(): return directory @@ -108,9 +107,12 @@ def load_project_settings(src: Path, config: Optional[str]) -> Dict: ) # pylint: disable=broad-except - except BaseException: - logger.info( - "Failed to load config file. Ensure file exists and is in json format." + except BaseException as error: + logger.error( + "%sFailed to load config file %s. %s", + Fore.RED, + Path(config).resolve(), + error, ) pyproject_file = find_pyproject(src) @@ -131,8 +133,8 @@ def load_project_settings(src: Path, config: Optional[str]) -> Dict: **json.loads(djlintrc_file.read_text(encoding="utf8")), } # pylint: disable=broad-except - except BaseException: - logger.info("Failed to load .djlintrc file.") + except BaseException as error: + logger.error("%sFailed to load .djlintrc file. %s", Fore.RED, error) return djlint_content @@ -214,7 +216,6 @@ class Config: configuration: Optional[str] = None, statistics: bool = False, ): - self.reformat = reformat self.check = check self.lint = lint diff --git a/tests/test_config/test_format_attribute_template_tags/test_config.py b/tests/test_config/test_format_attribute_template_tags/test_config.py index a0417bc..07f1a95 100644 --- a/tests/test_config/test_format_attribute_template_tags/test_config.py +++ b/tests/test_config/test_format_attribute_template_tags/test_config.py @@ -31,7 +31,6 @@ def test_with_config(runner: CliRunner) -> None: def test_without_config(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, diff --git a/tests/test_config/test_preserve_blank_lines/test_config.py b/tests/test_config/test_preserve_blank_lines/test_config.py index 4906ade..6617ef6 100644 --- a/tests/test_config/test_preserve_blank_lines/test_config.py +++ b/tests/test_config/test_preserve_blank_lines/test_config.py @@ -15,7 +15,6 @@ from src.djlint import main as djlint def test_config(runner: CliRunner) -> None: - result = runner.invoke( djlint, [ diff --git a/tests/test_config/test_preserve_leading_space/test_config.py b/tests/test_config/test_preserve_leading_space/test_config.py index 830c042..4ef321a 100644 --- a/tests/test_config/test_preserve_leading_space/test_config.py +++ b/tests/test_config/test_preserve_leading_space/test_config.py @@ -15,7 +15,6 @@ from src.djlint import main as djlint def test_config(runner: CliRunner) -> None: - result = runner.invoke( djlint, [ diff --git a/tests/test_html/test_aurelia.py b/tests/test_html/test_aurelia.py index 404362f..87511c3 100644 --- a/tests/test_html/test_aurelia.py +++ b/tests/test_html/test_aurelia.py @@ -27,7 +27,6 @@ from tests.conftest import reformat def test_aurelia(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, diff --git a/tests/test_html/test_basics.py b/tests/test_html/test_basics.py index 33db33b..328dc20 100644 --- a/tests/test_html/test_basics.py +++ b/tests/test_html/test_basics.py @@ -104,7 +104,6 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None: def test_empty(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, @@ -314,7 +313,6 @@ def test_empty(runner: CliRunner, tmp_file: TextIO) -> None: def test_hello_world(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, @@ -338,7 +336,6 @@ def test_hello_world(runner: CliRunner, tmp_file: TextIO) -> None: def test_html_comments(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, @@ -483,7 +480,6 @@ def test_html_comments(runner: CliRunner, tmp_file: TextIO) -> None: def test_issue_9368_3(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, @@ -495,7 +491,6 @@ def test_issue_9368_3(runner: CliRunner, tmp_file: TextIO) -> None: def test_issue_9368(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, @@ -533,7 +528,6 @@ def test_issue_9368(runner: CliRunner, tmp_file: TextIO) -> None: def test_void_elements(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, diff --git a/tests/test_html/test_comments.py b/tests/test_html/test_comments.py index 8a48f56..1dc1976 100644 --- a/tests/test_html/test_comments.py +++ b/tests/test_html/test_comments.py @@ -49,7 +49,6 @@ comment--> def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None: - html_in = ( b""" @@ -67,7 +66,6 @@ def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None: def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None: - html_in = ( b""" @@ -268,7 +266,6 @@ def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None: def test_hidden(runner: CliRunner, tmp_file: TextIO) -> None: - html_in = ( b""" diff --git a/tests/test_html/test_symbol_entities.py b/tests/test_html/test_symbol_entities.py index 9593a1b..7b343f6 100644 --- a/tests/test_html/test_symbol_entities.py +++ b/tests/test_html/test_symbol_entities.py @@ -27,7 +27,6 @@ from tests.conftest import reformat def test_symbol_entities(runner: CliRunner, tmp_file: TextIO) -> None: - output = reformat( tmp_file, runner, diff --git a/tests/test_html/test_yaml.py b/tests/test_html/test_yaml.py index 005e748..2d4037f 100644 --- a/tests/test_html/test_yaml.py +++ b/tests/test_html/test_yaml.py @@ -89,7 +89,6 @@ layout:
def test_custom_parser(runner: CliRunner, tmp_file: TextIO) -> None: - html_in = ( b""" ---mycustomparser @@ -114,7 +113,6 @@ slug: home def test_empty(runner: CliRunner, tmp_file: TextIO) -> None: - html_in = ( b""" --- @@ -134,7 +132,6 @@ def test_empty(runner: CliRunner, tmp_file: TextIO) -> None: def test_empty_2(runner: CliRunner, tmp_file: TextIO) -> None: - html_in = ( b""" --- @@ -155,7 +152,6 @@ def test_empty_2(runner: CliRunner, tmp_file: TextIO) -> None: def test_issue_9042_no_empty_line(runner: CliRunner, tmp_file: TextIO) -> None: - html_in = ( b""" --- @@ -177,7 +173,6 @@ Test abc. def test_issue_9042(runner: CliRunner, tmp_file: TextIO) -> None: - html_in = ( b""" ---