Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow users to override comment delimiters #900

Merged

Conversation

ptgott
Copy link
Contributor

@ptgott ptgott commented Sep 23, 2024

Allow users to specify the comment delimiters they are using in their documentation. vale replaces these with HTML comment tags before linting, making it possible to control style rules for specific passages of prose in file formats that use non-HTML comment syntax. This is critical for controlling style rules within a page in MDX, and potentially other formats as well.

This example configures the CommentDelimiters field for *.md files, indicating that {/* and */} are the custom comment delimiters:

[*.md]
CommentDelimiters = "{/*,*/}"

Internally, custom delimiters are represented as a [2]string, and it is only possible to configure one set of custom comment delimiters for a given format block.

More specific changes:

  • Refactor applyPatterns. Remove the method receiver and take only the necessary fields of *core.Config as parameters. This makes it easier to test applyPatterns without mocking an entire *core.Config. Also extract functions for applyInlinePatterns and applyBlockPatterns so we can use fewer arguments in a single function.
  • Add applyCommentPatterns, which works similarly to applyInlinePatterns and applyBlockPatterns, but for substituting comments.
  • For tests, import https//github.com/stretchr/testify/assert, a popular testing library, to get richer test output.

Closes #762

@ptgott
Copy link
Contributor Author

ptgott commented Sep 27, 2024

Hello @jdkato, it looks like a number of cucumber tests are failing in CI. When I set up a development environment per the instructions and run make test on origin/v3, cucumber tests also fail. Is this a known issue? Is there a way to verify which failures were introduced by my changes? Thanks!

@jdkato
Copy link
Member

jdkato commented Sep 27, 2024

The tests pass on the v3 branch on GitHub and for me locally.

So my guess is that the failures you're seeing locally on the v3 branch are related to your environment, but I would need to know which cases are failing to say more.

The failures here are related to your changes, but I haven't looked closely enough to say exactly why.

My advice would be to try running Vale in the relevant test directories, starting with testdata/fixtures/patterns.

@ptgott ptgott force-pushed the paul.gottschling/762-comment-patterns branch from 9a7ac8b to cfbeec1 Compare October 3, 2024 19:22
@ptgott
Copy link
Contributor Author

ptgott commented Oct 3, 2024

@jdkato Thanks for your help! I realized why my changes were introducing failures and pushed a fix with a new unit test.

@jdkato
Copy link
Member

jdkato commented Oct 9, 2024

The changes look good. Are you ready for this to be merged?

Allow users to specify the comment delimiters they are using in their
documentation. vale replaces these with HTML comment tags before
linting, making it possible to control style rules for specific passages
of prose in file formats that use non-HTML comment syntax. This is
critical for controlling style rules within a page in MDX, and
potentially other formats as well.

This example configures the `CommentDelimiters` field for `*.md` files,
indicating that `{/*` and `*/}` are the custom comment delimiters:

```ini
[*.md]
CommentDelimiters = "{/*,*/}"
```

Internally, custom delimiters are represented as a `[2]string`, and it
is only possible to configure one set of custom comment delimiters for a
given format block.

More specific changes:
- Refactor `applyPatterns`. Remove the method receiver and take only the
  necessary fields of `*core.Config` as parameters. This makes it easier
  to test `applyPatterns` without mocking an entire `*core.Config`. Also
  extract functions for `applyInlinePatterns` and `applyBlockPatterns`
  so we can use fewer arguments in a single function.
- Add `applyCommentPatterns`, which works similarly to
  `applyInlinePatterns` and `applyBlockPatterns`, but for substituting
  comments.
- For tests, import `https//github.com/stretchr/testify/assert`, a
  popular testing library, to get richer test output.

Closes errata-ai#762
@ptgott ptgott force-pushed the paul.gottschling/762-comment-patterns branch from cfbeec1 to 7ed02e6 Compare October 9, 2024 19:52
@ptgott
Copy link
Contributor Author

ptgott commented Oct 9, 2024

The changes look good. Are you ready for this to be merged?

Yes, thanks for taking a look and helping me through the process!

@jdkato jdkato merged commit b6df01b into errata-ai:v3 Oct 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom comment patterns (e.g., MDX)
3 participants