Skip to content

Make --ignore-multiline-regex example non-greedy #3892

Description

@vries

I recently started using --ignore-multiline-regex:

$ codespell -h
  ...
  --ignore-multiline-regex IGNORE_MULTILINE_REGEX
                        regular expression that is used to ignore text that may span
                        multi-line regions. The regex is run with re.DOTALL. For
                        example to allow skipping of regions of Python code using
                        begin/end comments one could use: --ignore-multiline-regex '#
                        codespell:ignore-begin *\n.*# codespell:ignore-end *\n'.
                        Defaults to empty/disabled.

I started out with this simple setup in setup.cfg:

# How to ignore blocks of code.                                                          
ignore-multiline-regex = codespell:ignore-begin.*codespell:ignore-end

Soon I found out that the matching is greedy and that therefore in this example:

/* codespell:ignore-begin */
/* Ignore this: usuable.  */
/* codespell:ignore-end */

/* Don't ignore this: usuable.  */

/* codespell:ignore-begin */
/* Ignore that: usuable.  */
/* codespell:ignore-end */

codespell ignores the "Don't ignore this" line.

I fixed this by doing:

ignore-multiline-regex = codespell:ignore-begin.*codespell:ignore-end
ignore-multiline-regex = codespell:ignore-begin.*?codespell:ignore-end

We should do the same in the example shown by codespell -h.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions