Skip to content

Commit

Permalink
Add note re: messaging linter line accuracy (#275)
Browse files Browse the repository at this point in the history
* Add note re: messaging linter line accuracy

Line numbers in messaging linter warnings are not accurate if the
violation takes place in a partial. The issue is a bit complex and seems
to have to do with the way `remarkIncludes` manipulates the MDAST.
Before we can address #273, this change adds a note
that line numbers may not be correct for violations that take place
inside partials.

* Respond to avatus feedback
  • Loading branch information
ptgott authored May 11, 2023
1 parent c14311e commit c0b7eb7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
12 changes: 11 additions & 1 deletion server/remark-lint-messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,22 @@ function checkMessaging(
const re = new RegExp(rule.incorrect);
const badText = text.match(re);
if (text.match(re)) {
let extras = "";
if (part == PageLocation.Body || part == PageLocation.Headers) {
extras +=
" (Note that the line number is not accurate if the issue occurs inside a partial.)";
}
if (part == PageLocation.Comments) {
extras +=
" (Note that the line number refers to the first line in the code snippet where the issue occurs, and is not accurate if the issue occurs inside a partial.)";
}
file.message(
`Incorrect messaging: "${badText[0]}" (${getReadableLocation(
part
)}). ` +
`${rule.explanation}. You should ${rule.correct}. ` +
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.',
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.' +
extras,
pos
);
}
Expand Down
19 changes: 14 additions & 5 deletions uvu-tests/remark-messaging.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ install these services when getting started with Teleport.
const expectedErrors = [
'Incorrect messaging: "auth and proxy" (in body text). ' +
'You must capitalize product names. You should use "Auth and Proxy Services" instead. ' +
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.',
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.' +
" (Note that the line number is not accurate if the issue occurs inside a partial.)",
];

assert.equal(getErrors(result), expectedErrors);
Expand All @@ -102,7 +103,8 @@ In this guide, we will explain how to set up Teleport to access Kubernetes.
'Incorrect messaging: "Kubernetes Access" (in header). Focus our messaging ' +
"on a single product, rather than multiple. You should use " +
'"registering a Kubernetes cluster" instead. ' +
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.',
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter. ' +
"(Note that the line number is not accurate if the issue occurs inside a partial.)",
];

const result = transformer({
Expand Down Expand Up @@ -179,15 +181,22 @@ func myfunc(s string){
const expectedErrors = [
'Incorrect messaging: "auth and proxy" (in code comment). You must capitalize product ' +
'names. You should use "Auth and Proxy Services" instead. ' +
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.',
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.' +
" (Note that the line number refers to the first line in the code snippet" +
" where the issue occurs, and is not accurate if the issue occurs inside a partial.)",

'Incorrect messaging: "Kubernetes Access" (in code comment). Focus our messaging on a ' +
'single product, rather than multiple. You should use "registering a ' +
'Kubernetes cluster" instead. ' +
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.',
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.' +
" (Note that the line number refers to the first line in the code snippet" +
" where the issue occurs, and is not accurate if the issue occurs inside a partial.)",
'Incorrect messaging: "machine id" (in code comment). See our Core Concepts page: ' +
"https://goteleport.com/docs/core-concepts. " +
"You should capitalize the names of Teleport services. " +
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.',
'Add "{/*lint ignore messaging*/}" above this line to bypass the linter.' +
" (Note that the line number refers to the first line in the code snippet" +
" where the issue occurs, and is not accurate if the issue occurs inside a partial.)",
];

assert.equal(getErrors(result), expectedErrors);
Expand Down

1 comment on commit c0b7eb7

@vercel
Copy link

@vercel vercel bot commented on c0b7eb7 May 11, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.