-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f0b11ac
Showing
12 changed files
with
3,349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# eslint-plugin-todo-plz | ||
|
||
Enforce consistent and maintainable TODO comments. | ||
|
||
## Installation | ||
|
||
You'll first need to install [ESLint](http://eslint.org): | ||
|
||
``` | ||
$ npm i eslint --save-dev | ||
``` | ||
|
||
Next, install `eslint-plugin-todo-plz`: | ||
|
||
``` | ||
$ npm install eslint-plugin-todo-plz --save-dev | ||
``` | ||
|
||
## Usage | ||
|
||
Add `todo-plz` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix: | ||
|
||
```json | ||
{ | ||
"plugins": ["todo-plz"] | ||
} | ||
``` | ||
|
||
Then configure the rules you want to use under the rules section. | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"todo-plz/ticket-ref": ["error", { "pattern": "ABC-[0-9]+" }] | ||
} | ||
} | ||
``` | ||
|
||
## Supported Rules | ||
|
||
- [`ticket-ref`](docs/rules/ticket-ref.md) | ||
|
||
## Inspiration | ||
|
||
- Shoutout [`expiring-todo-comments`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/expiring-todo-comments.md) for showing me how to build my first ESLint rule. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Require a ticket reference in the TODO comment (ticket-ref) | ||
|
||
Adding a `TODO` comment that will be addressed in the future should have a corresponding ticket (AKA issue) in the project backlog so the team doesn't lose track of the pending work. | ||
|
||
## Fail | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
// TODO: Unmock this API request | ||
``` | ||
|
||
## Pass | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
// TODO (ABC-123): Unmock this API request | ||
``` | ||
|
||
## Options | ||
|
||
### pattern | ||
|
||
This option 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 `ABC` followed by a number (e.g `ABC-123`), you would configure this rule like: | ||
|
||
```json | ||
{ | ||
"rules": { | ||
"todo-plz/ticket-ref": ["error", { "pattern": "ABC-[0-9]+" }] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict"; | ||
|
||
module.exports.rules = { | ||
"ticket-ref": require("./rules/ticket-ref"), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @fileoverview Require a ticket reference in the TODO comment | ||
* @author Sawyer | ||
*/ | ||
"use strict"; | ||
|
||
const messages = { | ||
missingTicket: | ||
"TODO comment is missing a ticket reference matching pattern: {{ pattern }}", | ||
}; | ||
|
||
const schema = [ | ||
{ | ||
type: "object", | ||
properties: { | ||
pattern: { | ||
type: "string", | ||
}, | ||
terms: { | ||
type: "array", | ||
items: { | ||
type: "string", | ||
}, | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
function create(context) { | ||
const { pattern, terms } = { | ||
terms: ["TODO"], | ||
...context.options[0], | ||
}; | ||
const sourceCode = context.getSourceCode(); | ||
const comments = sourceCode.getAllComments(); | ||
|
||
function validate(comment) { | ||
const value = comment.value; | ||
const hasTerm = terms.some((term) => value.includes(term)); | ||
if (!hasTerm) { | ||
return; | ||
} | ||
|
||
terms.forEach((term) => { | ||
const searchPattern = new RegExp(`${term}\\s?\\(${pattern}\\)`, "i"); | ||
if (searchPattern.test(value)) return; | ||
|
||
context.report({ | ||
loc: comment.loc, | ||
messageId: "missingTicket", | ||
data: { pattern }, | ||
}); | ||
}); | ||
} | ||
|
||
comments.forEach(validate); | ||
|
||
return {}; | ||
} | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "Require a ticket reference in the TODO comment", | ||
category: "Fill me in", | ||
recommended: false, | ||
}, | ||
fixable: null, // or "code" or "whitespace" | ||
messages, | ||
schema, | ||
type: "suggestion", | ||
}, | ||
create, | ||
}; |
Oops, something went wrong.