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

Adding trailing backslash rule #899

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vale/fixtures/OpenShiftAsciiDoc/TrailingBackslash/.vale.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
; Vale configuration file to test the `TrailingBackslash` rule
StylesPath = ../../../styles
MinAlertLevel = suggestion
[*.adoc]
OpenShiftAsciiDoc.TrailingBackslash = YES
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//vale-fixture
[source,terminal]
----
oc get my lunch\
----

//vale-fixture
[source,terminal]
----
C:\Program Files\
----
46 changes: 46 additions & 0 deletions .vale/fixtures/OpenShiftAsciiDoc/TrailingBackslash/testvalid.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[source,terminal]
----
$ oc get my lunch
----

[source,terminal]
----
# oc get my lunch
----

.Example
[source,terminal]
----
$ az role assignment create --role "<privileged_role>" \// <1>
Copy link
Collaborator

@apinnick apinnick Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a "normal" backslash without a callout to the testvalid file?

$ az role assignment \
  create --role "<privileged_role>"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will trigger the rule. I'll see if I can refine the regex to cater for this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into a similar issue when I tried to create a Vale rule that would flag lines in code that were missing backslashes. :-( Never did find a good solution.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could handle it with a script rule for sure.

----

[source,terminal]
----
sh-4.2# chroot /host
----

[source,terminal]
----
.
├── CODEOWNERS
├── README.md
└── scripts
└── validate-vale-rules.sh
----

[source,terminal]
----
(undercloud)$ cd go/to/path
----

[source,yaml]
----
include::yaml/boundary-clock-ptp-config.yaml[]
----

.Example
[source,terminal]
----
$ az role assignment \
create --role "<privileged_role>"
----
9 changes: 9 additions & 0 deletions .vale/styles/OpenShiftAsciiDoc/TrailingBackslash.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
extends: existence
scope: raw
level: error
message: "Codeblock contains unescaped trailing backslash."
action:
name: remove
raw:
- '(?<!^----\n.+\n+\w+)(?<!\\)\\\n'