Skip to content

Commit

Permalink
Issue 1277 (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdewinter authored Feb 2, 2025
1 parent 7d79a19 commit 277100c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ find_unused_pylint_suppressions() {
SCAN_FILES=()
git diff --name-only --staged >"${TEMP_FILE}"
while IFS= read -r line; do
if [[ ${line} == *.py ]] && [[ ${line} != "pytest_execute.py" ]]; then
if [[ ${line} == *.py ]] && [[ ${line} != "pytest_execute.py" ]] && [[ -f ${line} ]]; then
SCAN_FILES+=("${line}")
fi
done <"${TEMP_FILE}"
Expand Down
4 changes: 3 additions & 1 deletion newdocs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
<!--- pyml disable-next-line no-duplicate-heading-->
### Changed

- None
- [Issue 1277](https://github.com/jackdewinter/pymarkdown/issues/1277)
- Rule Md044 changed to add a `code_spans` exclusion as a compliment
to the `code_blocks` exclusion.

## Version 0.9.27 - Date: 2025-01-09

Expand Down
1 change: 1 addition & 0 deletions newdocs/src/plugins/rule_md044.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ configuration item.
| `enabled` | `boolean` | `True` | Whether the plugin rule is enabled. |
| `names` | `string` | None | Comma-separated list of proper nouns to preserve capitalization on.** |
| `code_blocks` | `boolean` | `True` | Search in Fenced Code Block elements and Indented Code Block elements. |
| `code_spans` | `boolean` | `True` | Search in Inline Code Span elements. |

** The comma-separated list of items is a string with a format of `{item},...,{item}`.
Any leading or trailing space characters surrounding the `{item}` are trimmed during
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": 7987,
"totalCovered": 7987
"totalMeasured": 7989,
"totalCovered": 7989
},
"lineLevel": {
"totalMeasured": 21603,
"totalCovered": 21603
"totalMeasured": 21607,
"totalCovered": 21607
}
}

2 changes: 1 addition & 1 deletion publish/test-results.json
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,7 @@
},
{
"name": "test.rules.test_md044",
"totalTests": 98,
"totalTests": 100,
"failedTests": 0,
"errorTests": 0,
"skippedTests": 0,
Expand Down
7 changes: 7 additions & 0 deletions pymarkdown/plugins/rule_md_044.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self) -> None:
super().__init__()
self.__proper_name_list: List[str] = []
self.__check_in_code_blocks: bool = False
self.__check_in_code_spans: bool = False
self.__is_in_code_block: bool = False
self.__names: str = ""
self.__replacement_items: List[FoundReplacement] = []
Expand Down Expand Up @@ -81,6 +82,9 @@ def initialize_from_config(self) -> None:
self.__check_in_code_blocks = self.plugin_configuration.get_boolean_property(
"code_blocks", default_value=True
)
self.__check_in_code_spans = self.plugin_configuration.get_boolean_property(
"code_spans", default_value=True
)
self.__proper_name_list = []
self.__names = self.plugin_configuration.get_string_property(
"names",
Expand Down Expand Up @@ -108,6 +112,7 @@ def query_config(self) -> List[QueryConfigItem]:
"""
return [
QueryConfigItem("code_blocks", self.__check_in_code_blocks),
QueryConfigItem("code_spans", self.__check_in_code_spans),
QueryConfigItem("names", self.__names),
]

Expand Down Expand Up @@ -464,6 +469,8 @@ def __handle_link_reference_definition(
def __handle_inline_code_span(
self, context: PluginScanContext, token: MarkdownToken
) -> None:
if not self.__check_in_code_spans:
return
code_span_token = cast(InlineCodeSpanMarkdownToken, token)
same_line_offset = -(
len(code_span_token.extracted_start_backticks)
Expand Down
17 changes: 17 additions & 0 deletions test/rules/test_md044.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,22 @@
fix_expected_file_contents="""# This section contains a ParaGraph
yes, `a ParaGraph is` contained.
""",
),
pluginRuleTest(
"bad_code_span_text_with_code_blocks_disabled",
source_file_contents="""# This section contains a paragraph
yes, `a paragraph is` contained.
""",
set_args=["plugins.md044.names=ParaGraph", "plugins.md044.code_spans=$!False"],
use_strict_config=True,
scan_expected_return_code=1,
scan_expected_output="""{temp_source_path}:1:27: MD044: Proper names should have the correct capitalization [Expected: ParaGraph; Actual: paragraph] (proper-names)
""",
fix_expected_file_contents="""# This section contains a ParaGraph
yes, `a paragraph is` contained.
""",
),
pluginRuleTest(
Expand Down Expand Up @@ -983,6 +999,7 @@ def test_md044_query_config():
CONFIGURATION ITEM TYPE VALUE
code_blocks boolean True
code_spans boolean True
names string ""
""",
Expand Down

0 comments on commit 277100c

Please sign in to comment.