Skip to content

Commit

Permalink
https://github.com/jackdewinter/pymarkdown/issues/940
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdewinter committed Dec 31, 2023
1 parent 98dda99 commit 28694d7
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 16 deletions.
4 changes: 3 additions & 1 deletion docs/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,15 @@ completed_file
possible -> MD005, Md007
possible -> MD019/MD021, MD023
possible -> md027 19/21/23/05/07 when blanks inside of list
-> mod027 and most others

Md001 Atx/SetExt hash_count
MD004 UnorderedListStartMarkdownToken list_start_sequence
Md005 NewListItemMarkdownToken indent_level, extracted_whitespace
UnorderedListStartMarkdownToken indent_level, extracted_whitespace, column_number, leading_spaces
OrderedListStartMarkdownToken indent_level, extracted_whitespace, column_number, leading_spaces
MD006(d) NewListItemMarkdownToken indent_level, extracted_whitespace
UnorderedListStartMarkdownToken indent_level, extracted_whitespace
MD007 NewListItemMarkdownToken indent_level, extracted_whitespace
UnorderedListStartMarkdownToken indent_level, extracted_whitespace
MD009 line -> no trailing spaces
Expand Down Expand Up @@ -175,5 +178,4 @@ MD027 BlankLineMarkdownToken extracted_whitespace
UnorderedListStartMarkdownToken indent_level, extracted_whitespace, column_number, leading_spaces
OrderedListStartMarkdownToken indent_level, extracted_whitespace, column_number, leading_spaces

md006
md030
10 changes: 10 additions & 0 deletions docs/rules/rule_md006.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
| `md006` |
| `ul-start-left` |

| Autofix Available |
| --- |
| Yes |

## Summary

Consider starting bulleted lists at the beginning of the line.
Expand Down Expand Up @@ -91,3 +95,9 @@ This rule is largely inspired by the MarkdownLint rule
It is not clear how this rule, which is disabled by default, differs from
Rule Md007. To make sure this rule is well-rounded, it has been changed
to work with nested list blocks and block quotes.

## Fix Description

The containers will be altered so that they start at the beginning of "the line".
As that definition was not clearly understood [Rule MD007](./rule_md007.md) was
created to more clearly handle the issue.
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": 4675,
"totalCovered": 4675
"totalMeasured": 4679,
"totalCovered": 4679
},
"lineLevel": {
"totalMeasured": 19102,
"totalCovered": 19102
"totalMeasured": 19111,
"totalCovered": 19111
}
}

2 changes: 1 addition & 1 deletion publish/test-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@
},
{
"name": "test.rules.test_md006",
"totalTests": 16,
"totalTests": 22,
"failedTests": 0,
"errorTests": 0,
"skippedTests": 0,
Expand Down
50 changes: 42 additions & 8 deletions pymarkdown/plugins/rule_md_006.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import List, cast

from pymarkdown.general.parser_helper import ParserHelper
from pymarkdown.plugin_manager.plugin_details import PluginDetails
from pymarkdown.plugin_manager.plugin_details import PluginDetailsV2
from pymarkdown.plugin_manager.plugin_scan_context import PluginScanContext
from pymarkdown.plugin_manager.rule_plugin import RulePlugin
from pymarkdown.tokens.block_quote_markdown_token import BlockQuoteMarkdownToken
Expand All @@ -23,18 +23,18 @@ def __init__(self) -> None:
super().__init__()
self.__token_stack: List[MarkdownToken] = []

def get_details(self) -> PluginDetails:
def get_details(self) -> PluginDetailsV2:
"""
Get the details for the plugin.
"""
return PluginDetails(
return PluginDetailsV2(
plugin_name="ul-start-left",
plugin_id="MD006",
plugin_enabled_by_default=False,
plugin_description="Consider starting bulleted lists at the beginning of the line",
plugin_version="0.5.0",
plugin_interface_version=1,
plugin_url="https://github.com/jackdewinter/pymarkdown/blob/main/docs/rules/rule_md006.md",
plugin_supports_fix=True,
)

def starting_new_file(self) -> None:
Expand Down Expand Up @@ -70,12 +70,46 @@ def next_token(self, context: PluginScanContext, token: MarkdownToken) -> None:
self.__token_stack.append(token)
if token.is_unordered_list_start:
expected_indent = self.__calculate_expected_indent()
if token.column_number != (1 + expected_indent):
self.report_next_token_error(context, token)
if delta := (1 + expected_indent) - token.column_number:
self.__report_or_fix(context, token, delta)
elif token.is_list_end or token.is_block_quote_end:
del self.__token_stack[-1]
elif token.is_new_list_item:
if self.__token_stack[-1].is_unordered_list_start:
expected_indent = self.__calculate_expected_indent()
if token.column_number != (1 + expected_indent):
self.report_next_token_error(context, token)
if delta := (1 + expected_indent) - token.column_number:
self.__report_or_fix(context, token, delta)

def __report_or_fix(
self, context: PluginScanContext, token: MarkdownToken, adjust_amount: int
) -> None:
if context.in_fix_mode:
list_start_token = cast(ListStartMarkdownToken, token)
self.register_fix_token_request(
context,
token,
"next_token",
"indent_level",
list_start_token.indent_level + adjust_amount,
)
if not token.is_new_list_item:
self.register_fix_token_request(
context, token, "next_token", "extracted_whitespace", ""
)
self.register_fix_token_request(
context,
token,
"next_token",
"column_number",
list_start_token.column_number + adjust_amount,
)
else:
self.register_fix_token_request(
context,
token,
"next_token",
"extracted_whitespace",
list_start_token.extracted_whitespace[:adjust_amount],
)
else:
self.report_next_token_error(context, token)
Loading

0 comments on commit 28694d7

Please sign in to comment.