mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-16 21:40:24 +00:00
fix(config): added error message print when config loading fails
closes #531
This commit is contained in:
parent
b47c6bba85
commit
e21fa29dc2
17 changed files with 8 additions and 40 deletions
|
|
@ -248,9 +248,7 @@ def main(
|
||||||
ascii=progress_char,
|
ascii=progress_char,
|
||||||
leave=False,
|
leave=False,
|
||||||
) as pbar:
|
) as pbar:
|
||||||
|
|
||||||
for future in as_completed(futures):
|
for future in as_completed(futures):
|
||||||
|
|
||||||
file_errors.append(future.result())
|
file_errors.append(future.result())
|
||||||
pbar.update()
|
pbar.update()
|
||||||
elapsed = pbar.format_interval(pbar.format_dict["elapsed"])
|
elapsed = pbar.format_interval(pbar.format_dict["elapsed"])
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ def format_template_tags(config: Config, attributes: str, spacing: int) -> str:
|
||||||
indent_adder = spacing or 0
|
indent_adder = spacing or 0
|
||||||
|
|
||||||
for line_number, line in enumerate(attributes.splitlines()):
|
for line_number, line in enumerate(attributes.splitlines()):
|
||||||
|
|
||||||
# when checking for template tag, use "match" to force start of line check.
|
# when checking for template tag, use "match" to force start of line check.
|
||||||
if re.match(
|
if re.match(
|
||||||
re.compile(config.template_unindent, re.I | re.X), line.strip()
|
re.compile(config.template_unindent, re.I | re.X), line.strip()
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,6 @@ def condense_html(html: str, config: Config) -> str:
|
||||||
# should we add blank lines before load tags?
|
# should we add blank lines before load tags?
|
||||||
if config.blank_line_before_tag:
|
if config.blank_line_before_tag:
|
||||||
for tag in [x.strip() for x in config.blank_line_before_tag.split(",")]:
|
for tag in [x.strip() for x in config.blank_line_before_tag.split(",")]:
|
||||||
|
|
||||||
html = re.sub(
|
html = re.sub(
|
||||||
re.compile(
|
re.compile(
|
||||||
rf"(?<!^\n)((?:{{%\s*?{tag}\b[^}}]+?%}}\n?)+)",
|
rf"(?<!^\n)((?:{{%\s*?{tag}\b[^}}]+?%}}\n?)+)",
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ def format_css(html: str, config: Config) -> str:
|
||||||
# add indent back
|
# add indent back
|
||||||
ignore_indent = False
|
ignore_indent = False
|
||||||
for line in beautified_lines:
|
for line in beautified_lines:
|
||||||
|
|
||||||
if re.search(
|
if re.search(
|
||||||
re.compile(
|
re.compile(
|
||||||
r"\/\*[ ]*?beautify[ ]+?ignore:end[ ]*?\*\/",
|
r"\/\*[ ]*?beautify[ ]+?ignore:end[ ]*?\*\/",
|
||||||
|
|
@ -38,7 +37,6 @@ def format_css(html: str, config: Config) -> str:
|
||||||
ignore_indent = False
|
ignore_indent = False
|
||||||
|
|
||||||
if ignore_indent is False and line:
|
if ignore_indent is False and line:
|
||||||
|
|
||||||
beautified += "\n" + inner_indent + line
|
beautified += "\n" + inner_indent + line
|
||||||
else:
|
else:
|
||||||
beautified += "\n" + line
|
beautified += "\n" + line
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ def indent_html(rawcode: str, config: Config) -> str:
|
||||||
ignored_level = 0
|
ignored_level = 0
|
||||||
|
|
||||||
for item in rawcode_flat_list:
|
for item in rawcode_flat_list:
|
||||||
|
|
||||||
# if a raw tag first line
|
# if a raw tag first line
|
||||||
if not is_block_raw and is_ignored_block_opening(config, item):
|
if not is_block_raw and is_ignored_block_opening(config, item):
|
||||||
is_raw_first_line = True
|
is_raw_first_line = True
|
||||||
|
|
@ -225,7 +224,6 @@ def indent_html(rawcode: str, config: Config) -> str:
|
||||||
def fix_non_handlebars_template_tags(
|
def fix_non_handlebars_template_tags(
|
||||||
html: str, out_format: str, match: re.Match
|
html: str, out_format: str, match: re.Match
|
||||||
) -> str:
|
) -> str:
|
||||||
|
|
||||||
if inside_ignored_block(config, html, match):
|
if inside_ignored_block(config, html, match):
|
||||||
return match.group()
|
return match.group()
|
||||||
|
|
||||||
|
|
@ -255,7 +253,6 @@ def indent_html(rawcode: str, config: Config) -> str:
|
||||||
def fix_handlebars_template_tags(
|
def fix_handlebars_template_tags(
|
||||||
html: str, out_format: str, match: re.Match
|
html: str, out_format: str, match: re.Match
|
||||||
) -> str:
|
) -> str:
|
||||||
|
|
||||||
if inside_ignored_block(config, html, match):
|
if inside_ignored_block(config, html, match):
|
||||||
return match.group()
|
return match.group()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ def format_js(html: str, config: Config) -> str:
|
||||||
# add indent back
|
# add indent back
|
||||||
ignore_indent = False
|
ignore_indent = False
|
||||||
for line in beautified_lines:
|
for line in beautified_lines:
|
||||||
|
|
||||||
if re.search(
|
if re.search(
|
||||||
re.compile(
|
re.compile(
|
||||||
r"\/\*[ ]*?beautify[ ]+?(?:preserve|ignore):end[ ]*?\*\/",
|
r"\/\*[ ]*?beautify[ ]+?(?:preserve|ignore):end[ ]*?\*\/",
|
||||||
|
|
|
||||||
|
|
@ -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.
|
# rule H025 is a special case where the output must be an even number.
|
||||||
if rule["name"] == "H025":
|
if rule["name"] == "H025":
|
||||||
|
|
||||||
open_tags: List[re.Match] = []
|
open_tags: List[re.Match] = []
|
||||||
|
|
||||||
# for match in re.finditer(
|
# for match in re.finditer(
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,6 @@ def build_output(error: dict, config: Config) -> int:
|
||||||
)
|
)
|
||||||
|
|
||||||
for message_dict in errors:
|
for message_dict in errors:
|
||||||
|
|
||||||
line = Fore.BLUE + message_dict["line"] + Style.RESET_ALL
|
line = Fore.BLUE + message_dict["line"] + Style.RESET_ALL
|
||||||
code = (
|
code = (
|
||||||
(Fore.RED if message_dict["code"][:1] == "E" else Fore.YELLOW)
|
(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:
|
if messages and codes:
|
||||||
|
|
||||||
longest_code = len(max(messages.keys(), key=len))
|
longest_code = len(max(messages.keys(), key=len))
|
||||||
longest_count = len(
|
longest_count = len(
|
||||||
str(max(Counter(codes).values(), key=lambda x: len(str(x))))
|
str(max(Counter(codes).values(), key=lambda x: len(str(x))))
|
||||||
)
|
)
|
||||||
|
|
||||||
for code in sorted(Counter(codes).items()):
|
for code in sorted(Counter(codes).items()):
|
||||||
|
|
||||||
code_space = (longest_code - len(str(code[0]))) * " "
|
code_space = (longest_code - len(str(code[0]))) * " "
|
||||||
count_space = (longest_count - len(str(code[1]))) * " "
|
count_space = (longest_count - len(str(code[1]))) * " "
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ logger = logging.getLogger(__name__)
|
||||||
def find_project_root(src: Path) -> Path:
|
def find_project_root(src: Path) -> Path:
|
||||||
"""Attempt to get the project root."""
|
"""Attempt to get the project root."""
|
||||||
for directory in [src, *src.resolve().parents]:
|
for directory in [src, *src.resolve().parents]:
|
||||||
|
|
||||||
if (directory / ".git").exists():
|
if (directory / ".git").exists():
|
||||||
return directory
|
return directory
|
||||||
|
|
||||||
|
|
@ -108,9 +107,12 @@ def load_project_settings(src: Path, config: Optional[str]) -> Dict:
|
||||||
)
|
)
|
||||||
|
|
||||||
# pylint: disable=broad-except
|
# pylint: disable=broad-except
|
||||||
except BaseException:
|
except BaseException as error:
|
||||||
logger.info(
|
logger.error(
|
||||||
"Failed to load config file. Ensure file exists and is in json format."
|
"%sFailed to load config file %s. %s",
|
||||||
|
Fore.RED,
|
||||||
|
Path(config).resolve(),
|
||||||
|
error,
|
||||||
)
|
)
|
||||||
|
|
||||||
pyproject_file = find_pyproject(src)
|
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")),
|
**json.loads(djlintrc_file.read_text(encoding="utf8")),
|
||||||
}
|
}
|
||||||
# pylint: disable=broad-except
|
# pylint: disable=broad-except
|
||||||
except BaseException:
|
except BaseException as error:
|
||||||
logger.info("Failed to load .djlintrc file.")
|
logger.error("%sFailed to load .djlintrc file. %s", Fore.RED, error)
|
||||||
|
|
||||||
return djlint_content
|
return djlint_content
|
||||||
|
|
||||||
|
|
@ -214,7 +216,6 @@ class Config:
|
||||||
configuration: Optional[str] = None,
|
configuration: Optional[str] = None,
|
||||||
statistics: bool = False,
|
statistics: bool = False,
|
||||||
):
|
):
|
||||||
|
|
||||||
self.reformat = reformat
|
self.reformat = reformat
|
||||||
self.check = check
|
self.check = check
|
||||||
self.lint = lint
|
self.lint = lint
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ def test_with_config(runner: CliRunner) -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_without_config(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_without_config(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
runner,
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ from src.djlint import main as djlint
|
||||||
|
|
||||||
|
|
||||||
def test_config(runner: CliRunner) -> None:
|
def test_config(runner: CliRunner) -> None:
|
||||||
|
|
||||||
result = runner.invoke(
|
result = runner.invoke(
|
||||||
djlint,
|
djlint,
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ from src.djlint import main as djlint
|
||||||
|
|
||||||
|
|
||||||
def test_config(runner: CliRunner) -> None:
|
def test_config(runner: CliRunner) -> None:
|
||||||
|
|
||||||
result = runner.invoke(
|
result = runner.invoke(
|
||||||
djlint,
|
djlint,
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ from tests.conftest import reformat
|
||||||
|
|
||||||
|
|
||||||
def test_aurelia(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_aurelia(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
runner,
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,6 @@ def test_comment(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
runner,
|
||||||
|
|
@ -314,7 +313,6 @@ def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_hello_world(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_hello_world(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
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:
|
def test_html_comments(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
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:
|
def test_issue_9368_3(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
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:
|
def test_issue_9368(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
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:
|
def test_void_elements(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
runner,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ comment-->
|
||||||
|
|
||||||
|
|
||||||
def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
html_in = (
|
html_in = (
|
||||||
b"""
|
b"""
|
||||||
<!-- hello -->
|
<!-- hello -->
|
||||||
|
|
@ -67,7 +66,6 @@ def test_before_text(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
html_in = (
|
html_in = (
|
||||||
b"""
|
b"""
|
||||||
<? hello ?>
|
<? hello ?>
|
||||||
|
|
@ -268,7 +266,6 @@ def test_bogus(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_hidden(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_hidden(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
html_in = (
|
html_in = (
|
||||||
b"""
|
b"""
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ from tests.conftest import reformat
|
||||||
|
|
||||||
|
|
||||||
def test_symbol_entities(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_symbol_entities(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
output = reformat(
|
output = reformat(
|
||||||
tmp_file,
|
tmp_file,
|
||||||
runner,
|
runner,
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,6 @@ layout: <div><div></div></div>
|
||||||
|
|
||||||
|
|
||||||
def test_custom_parser(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_custom_parser(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
html_in = (
|
html_in = (
|
||||||
b"""
|
b"""
|
||||||
---mycustomparser
|
---mycustomparser
|
||||||
|
|
@ -114,7 +113,6 @@ slug: home
|
||||||
|
|
||||||
|
|
||||||
def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
html_in = (
|
html_in = (
|
||||||
b"""
|
b"""
|
||||||
---
|
---
|
||||||
|
|
@ -134,7 +132,6 @@ def test_empty(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
|
|
||||||
def test_empty_2(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_empty_2(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
html_in = (
|
html_in = (
|
||||||
b"""
|
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:
|
def test_issue_9042_no_empty_line(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
html_in = (
|
html_in = (
|
||||||
b"""
|
b"""
|
||||||
---
|
---
|
||||||
|
|
@ -177,7 +173,6 @@ Test <a href="https://djlint.com">abc</a>.
|
||||||
|
|
||||||
|
|
||||||
def test_issue_9042(runner: CliRunner, tmp_file: TextIO) -> None:
|
def test_issue_9042(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||||
|
|
||||||
html_in = (
|
html_in = (
|
||||||
b"""
|
b"""
|
||||||
---
|
---
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue