Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* - [Issue 1208](#1208)
  • Loading branch information
jackdewinter authored Dec 9, 2024
1 parent 5245305 commit 977ccaa
Show file tree
Hide file tree
Showing 7 changed files with 684 additions and 379 deletions.
593 changes: 231 additions & 362 deletions Pipfile.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion newdocs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

- [Issue 1259](https://github.com/jackdewinter/pymarkdown/issues/1259)
- Fixed asserts and bad parsing from cases where containers are
added and then a "raw" blank line removes all containers
added and then a "raw" blank line removes all containers.
- [Issue 1263](https://github.com/jackdewinter/pymarkdown/issues/1263)
- Fixed issue where a new unordered list between two block quotes
was not being recognized properly.
Expand All @@ -33,6 +33,9 @@
Markdown, but not the intended Markdown.
- [Issue 1267](https://github.com/jackdewinter/pymarkdown/issues/1267)
- Fixed reported issue with task lists creating an error in Md018.
- [Issue 1268](https://github.com/jackdewinter/pymarkdown/issues/1268)
- Fixed issue with Md022 and pragmas, similar to
[Issue 1208](https://github.com/jackdewinter/pymarkdown/issues/1208).

<!--- pyml disable-next-line no-duplicate-heading-->
### Changed
Expand Down
8 changes: 4 additions & 4 deletions publish/coverage.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"projectName": "pymarkdown",
"reportSource": "pytest",
"branchLevel": {
"totalMeasured": 5503,
"totalCovered": 5503
"totalMeasured": 5511,
"totalCovered": 5511
},
"lineLevel": {
"totalMeasured": 21393,
"totalCovered": 21393
"totalMeasured": 21408,
"totalCovered": 21408
}
}

6 changes: 4 additions & 2 deletions publish/pylint_suppression.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@
"too-many-arguments": 1
},
"pymarkdown/plugins/rule_md_021.py": {},
"pymarkdown/plugins/rule_md_022.py": {},
"pymarkdown/plugins/rule_md_022.py": {
"too-many-instance-attributes": 1
},
"pymarkdown/plugins/rule_md_023.py": {
"too-many-arguments": 1
},
Expand Down Expand Up @@ -505,7 +507,7 @@
"pymarkdown/version.py": {}
},
"disables-by-name": {
"too-many-instance-attributes": 26,
"too-many-instance-attributes": 27,
"too-many-public-methods": 4,
"too-few-public-methods": 39,
"too-many-arguments": 253,
Expand Down
2 changes: 1 addition & 1 deletion publish/test-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@
},
{
"name": "test.rules.test_md022",
"totalTests": 50,
"totalTests": 59,
"failedTests": 0,
"errorTests": 0,
"skippedTests": 0,
Expand Down
39 changes: 30 additions & 9 deletions pymarkdown/plugins/rule_md_022.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from pymarkdown.plugin_manager.rule_plugin import RulePlugin
from pymarkdown.tokens.markdown_token import MarkdownToken

# pylint: disable=too-many-instance-attributes


class RuleMd022(RulePlugin):
"""
Expand All @@ -30,6 +32,7 @@ def __init__(self) -> None:
self.__lines_above = 0
self.__lines_below = 0
self.__start_heading_blank_line_count = -1
self.__last_blank_line: Optional[MarkdownToken] = None

def get_details(self) -> PluginDetails:
"""
Expand Down Expand Up @@ -82,13 +85,7 @@ def starting_new_file(self) -> None:
self.__did_above_line_count_match = False
self.__start_heading_token = None
self.__did_heading_end = False

# def completed_file(self, context: PluginScanContext) -> None:
# """
# Event that the file being currently scanned is now completed.
# """
# if (self.__blank_line_count != -1) and self.__blank_line_count >= 0:
# self.perform_close_check(context, None)
self.__last_blank_line = None

def __next_token_heading_start(self, token: MarkdownToken) -> None:
# print(">>token.is_setext_heading or token.is_atx_heading>>")
Expand Down Expand Up @@ -119,6 +116,16 @@ def next_token(self, context: PluginScanContext, token: MarkdownToken) -> None:
# print(">>self.__blank_line_count>>" + str(self.__blank_line_count))
if (self.__blank_line_count != -1) and self.__blank_line_count >= 0:
self.perform_close_check(context, token)
elif (
self.__blank_line_count == -1
and token.is_blank_line
and self.__last_blank_line is not None
):
blank_line_number_delta = (
token.line_number - self.__last_blank_line.line_number
)
if blank_line_number_delta != 1:
self.__blank_line_count = 0

if (
token.is_blank_line
Expand All @@ -133,24 +140,35 @@ def next_token(self, context: PluginScanContext, token: MarkdownToken) -> None:
elif token.is_end_token:
self.__next_token_heading_end(token)
# print(">>self.__blank_line_count>>" + str(self.__blank_line_count))
self.__last_blank_line = token if token.is_blank_line else None

def perform_close_check(
self, context: PluginScanContext, token: Optional[MarkdownToken]
self, context: PluginScanContext, token: MarkdownToken
) -> None:
"""
Perform any state checks necessary upon closing the heading context. Also
called at the end of a document to make sure the implicit close of the
document is handled properly.
"""

is_eligible_blank_line = token.is_blank_line
is_simple_blank_line = True
if is_eligible_blank_line and self.__last_blank_line is not None:
line_number_delta = token.line_number - self.__last_blank_line.line_number
is_simple_blank_line = line_number_delta == 1
is_eligible_blank_line = is_simple_blank_line

if (self.__start_heading_token and self.__did_heading_end) and (
not token or (not token.is_blank_line and not token.is_block_quote_end)
(not is_eligible_blank_line and not token.is_block_quote_end)
):
did_end_match = self.__blank_line_count == self.__lines_below
# print(">>END: did_end_match>>" + str(did_end_match))
self.report_any_match_failures(context, did_end_match)
self.__start_heading_token = None

if token.is_blank_line and not is_simple_blank_line:
self.__blank_line_count = 0

def report_any_match_failures(
self, context: PluginScanContext, did_end_match: bool
) -> None:
Expand All @@ -177,3 +195,6 @@ def report_any_match_failures(
extra_error_information=extra_info,
use_original_position=self.__start_heading_token.is_setext_heading,
)


# pylint: enable=too-many-instance-attributes
Loading

0 comments on commit 977ccaa

Please sign in to comment.