Skip to content

Commit 207ad63

Browse files
committed
fix(#50): add --no-validate
1 parent 61cc2a5 commit 207ad63

File tree

5 files changed

+39
-10
lines changed

5 files changed

+39
-10
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ If a file is not properly formatted, the exit code will be non-zero.
9393

9494
```console
9595
foo@bar:~$ mdformat --help
96-
usage: mdformat [-h] [--check] [--version] [--number] [--wrap {keep,no,INTEGER}]
97-
[--end-of-line {lf,crlf,keep}] [--exclude PATTERN]
98-
[--extensions EXTENSION] [--codeformatters LANGUAGE]
99-
[paths ...]
96+
usage: mdformat [-h] [--check] [--no-validate] [--version] [--number]
97+
[--wrap {keep,no,INTEGER}] [--end-of-line {lf,crlf,keep}]
98+
[--extensions EXTENSION] [--codeformatters LANGUAGE] [paths ...]
10099

101100
CommonMark compliant Markdown formatter
102101

@@ -106,6 +105,7 @@ positional arguments:
106105
options:
107106
-h, --help show this help message and exit
108107
--check do not apply changes to files
108+
--no-validate do not validate that the rendered HTML is consistent
109109
--version show program's version number and exit
110110
--number apply consecutive numbering to ordered lists
111111
--wrap {keep,no,INTEGER}

src/mdformat/_cli.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,16 @@ def run(cli_args: Sequence[str]) -> int: # noqa: C901
143143
getattr(plugin, "CHANGES_AST", False)
144144
for plugin in enabled_parserplugins.values()
145145
)
146-
if not changes_ast and not is_md_equal(
147-
original_str,
148-
formatted_str,
149-
options=opts,
150-
extensions=enabled_parserplugins,
151-
codeformatters=enabled_codeformatters,
146+
if (
147+
not opts["no_validate"]
148+
and not changes_ast
149+
and not is_md_equal(
150+
original_str,
151+
formatted_str,
152+
options=opts,
153+
extensions=enabled_parserplugins,
154+
codeformatters=enabled_codeformatters,
155+
)
152156
):
153157
print_error(
154158
f'Could not format "{path_str}".',
@@ -198,6 +202,11 @@ def make_arg_parser(
198202
parser.add_argument(
199203
"--check", action="store_true", help="do not apply changes to files"
200204
)
205+
parser.add_argument(
206+
"--no-validate",
207+
action="store_true",
208+
help="do not validate that the rendered HTML is consistent",
209+
)
201210
version_str = f"mdformat {mdformat.__version__}"
202211
plugin_version_str = get_plugin_version_str(
203212
{**parser_extension_dists, **codeformatter_dists}

src/mdformat/_conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
DEFAULT_OPTS = {
1010
"wrap": "keep",
11+
"no_validate": False,
1112
"number": False,
1213
"end_of_line": "lf",
1314
"exclude": [],
@@ -59,6 +60,9 @@ def _validate_values(opts: Mapping, conf_path: Path) -> None: # noqa: C901
5960
if "end_of_line" in opts:
6061
if opts["end_of_line"] not in {"crlf", "lf", "keep"}:
6162
raise InvalidConfError(f"Invalid 'end_of_line' value in {conf_path}")
63+
if "no_validate" in opts:
64+
if not isinstance(opts["no_validate"], bool):
65+
raise InvalidConfError(f"Invalid 'no_validate' value in {conf_path}")
6266
if "number" in opts:
6367
if not isinstance(opts["number"], bool):
6468
raise InvalidConfError(f"Invalid 'number' value in {conf_path}")

tests/test_cli.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,21 @@ def test_eol__check_keep_crlf(tmp_path):
345345
assert run((str(file_path), "--check", "--end-of-line=keep")) == 1
346346

347347

348+
@pytest.mark.skip
349+
def test_no_validate(tmp_path):
350+
# FIXME: Fake an mdformat bug that renders to a different HTML
351+
352+
file_path = tmp_path / "test.md"
353+
content = "2. ordered"
354+
file_path.write_text(content)
355+
356+
assert run((str(file_path),)) == 1
357+
assert file_path.read_text() == content
358+
359+
assert run((str(file_path), "--no-validate")) == 0
360+
assert file_path.read_text() != content
361+
362+
348363
def test_get_plugin_info_str():
349364
info = get_plugin_info_str(
350365
{"mdformat-tables": ("0.1.0", ["tables"])},

tests/test_config_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_invalid_toml(tmp_path, capsys):
6464
[
6565
("wrap", "wrap = -3"),
6666
("end_of_line", "end_of_line = 'lol'"),
67+
("no_validate", "no_validate = 1"),
6768
("number", "number = 0"),
6869
("exclude", "exclude = '**'"),
6970
("exclude", "exclude = ['1',3]"),

0 commit comments

Comments
 (0)