Skip to content

Commit

Permalink
Update description option pr (#8)
Browse files Browse the repository at this point in the history
Minor updates to #6 to support release

Co-authored-by: Mikhail Cheremuhin-Rerberg <[email protected]>
  • Loading branch information
sawyerh and NooNoo1337 authored Sep 12, 2022
1 parent bdc45ba commit 0e14c79
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
35 changes: 29 additions & 6 deletions docs/rules/ticket-ref.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Adding a `TODO` comment that will be addressed in the future should have a corre

## Options

### pattern
### `pattern`

This option is required, and controls what the ticket pattern is to match against. Expects a regex string.
**This option is required**, and controls what the ticket pattern is to match against. Expects a regex string.

For example, let's say you're using Jira and your ticket IDs are prefixed with `PROJ` followed by a number (e.g `PROJ-123`), you would configure this rule like:

Expand All @@ -32,9 +32,9 @@ Examples of **correct** code for this rule when using the above options:
// TODO (PROJ-123): Connect to the API
```

### terms
### `terms`

Optional. Change what terms to require the ticket reference on. Defaults to: `["TODO"]`
_Optional._ Change what terms to require the ticket reference on. Defaults to: `["TODO"]`

```json
{
Expand All @@ -59,11 +59,16 @@ Examples of **correct** code for this rule when using the above options:
```js
// TODO (PROJ-123): Connect to the API
// FIXME (PROJ-123): Connect to the API
// HELLO: This isn't a term targeted by the lint rule
```

### commentPattern
---

Optional. This option overrides the overall comment pattern that matches both term and ticket. When used, `term` and `pattern` options are ignored. Expects a regex string.
## Advanced options

### `commentPattern`

_Optional._ Override the overall comment pattern that matches both term and ticket. When used, `term` and `pattern` options are ignored. Expects a regex string.

For example, let's say you expect a different comment pattern such as `TODO: [PROJ-123]`, you would configure this rule like:

Expand All @@ -90,3 +95,21 @@ Examples of **correct** code for this rule when using the above options:
```js
// TODO: [PROJ-456] Connect to the API
```

### `description`

_Optional_. Override the error message portion that provides guidance on the expected ticket pattern. Defaults to: `Ticket pattern: <pattern>`

```json
{
"rules": {
"todo-plz/ticket-ref": [
"error",
{
"pattern": "PROJ-[0-9]+",
"description": "For example: `TODO (PROJ-123):`"
}
]
}
}
```
36 changes: 18 additions & 18 deletions lib/rules/ticket-ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@ const messages = {
"{{ term }} comment doesn't reference a ticket number. {{ description }}",
};

function getMessageId({ commentPattern, description }) {
if (description) {
return "missingTicketWithDescription";
}

if (commentPattern) {
return "missingTicketWithCommentPattern";
}

return "missingTicket";
}

const schema = [
{
type: "object",
properties: {
pattern: {
type: "string",
},
commentPattern: {
type: "string",
},
description: {
type: "string",
},
pattern: {
type: "string",
},
terms: {
type: "array",
items: {
Expand All @@ -37,7 +49,7 @@ const schema = [
];

function create(context) {
const { commentPattern, pattern, description, terms } = {
const { commentPattern, description, pattern, terms } = {
terms: ["TODO"],
...context.options[0],
};
Expand All @@ -64,27 +76,15 @@ function create(context) {
return;
}

function getMessageId({ description, commentPattern }) {
if (description) {
return "missingTicketWithDescription";
}

if (commentPattern) {
return "missingTicketWithCommentPattern";
}

return "missingTicket";
}

includedTerms.forEach((term) => {
const searchPattern = termSearchPatterns[term];

if (searchPattern.test(value)) return;

context.report({
loc: comment.loc,
messageId: getMessageId({ description, commentPattern }),
data: { commentPattern, pattern, term, description },
messageId: getMessageId({ commentPattern, description }),
data: { commentPattern, description, pattern, term },
});
});
}
Expand Down

0 comments on commit 0e14c79

Please sign in to comment.