errata-ai / vale

:pencil: A markup-aware linter for prose built with speed and extensibility in mind.
https://vale.sh
MIT License
4.52k stars 155 forks source link

Vale 3 not respecting BlockIgnores for Python docstrings #858

Open jorgepiloto opened 5 months ago

jorgepiloto commented 5 months ago

Check for existing issues

Environment

OS information

OS: Ubuntu 22.04.3 LTS x86_64 
Kernel: 6.5.0-41-generic 
Shell: zsh 5.8.1 
Terminal: xfce4-terminal 
CPU: 11th Gen Intel i7-11850H (8) @ 2.496GHz

Install method

Snap

Vale version

3.6.0

Describe the bug / provide steps to reproduce it

Background

I have a Python file that renders into an example within the documentation of a project. Its inline comments support Markdown style, see:

# # Computing the area of a circle
#
# Use the formula: $A = \pi r^2$
#
# The following function implements previous formula:

def compute_circle_area(circle_radius: float) -> float:
    """Compute the area of a circle from its radius.

    Parameters
    ----------
    circle_radius : float
        Radius of the circle

    Returns
    -------
    float
        Area of the circle

    """
    return 3.14 * circle_radius ** 2

# Use previous function as follows:

circle_radius = 1
area = compute_circle_area(circle_radius)
print(f"{area = :.2f}")

Given the following .vale.ini file:

# Core settings
# =============

# Location of our `styles`
StylesPath = "styles"

# The options are `suggestion`, `warning`, or `error` (defaults to “warning”).
MinAlertLevel = warning

# By default, `code` and `tt` are ignored.
IgnoredScopes = code, tt

# By default, `script`, `style`, `pre`, and `figure` are ignored.
SkippedScopes = script, style, pre, figure

# WordTemplate specifies what Vale will consider to be an individual word.
WordTemplate = \b(?:%s)\b

# List of Packages to be used for our guidelines
Packages = Google

# Define the Ansys vocabulary
Vocab = ANSYS

[formats]
# Python + Markdown
py = md

[*.{py,md,rst}]
IgnoredScopes = code, tt

# Apply the following styles
BasedOnStyles = Vale, Google
Vale.Terms = NO

# Ignore inline LaTeX equations
TokenIgnores = (\$+[^\n$]+\$+)

# Ignore Python code blocks (not working despite being a valid regex)
BlockIgnores = (?s) """([^"]*)"""

This issue seems similar to the one in https://github.com/errata-ai/vale/issues/736