Skip to content

Commit

Permalink
Add "fixme" as a valid purpose (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesstelford authored Sep 16, 2020
1 parent 131d097 commit bb5c58f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .changeset/plenty-trainers-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@markings/source-comments": minor
"@markings/source-react": minor
"@markings/types": minor
---

Add support for `fixme` purpose in react sources, and `FIXME` in comment
sources.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`fixme 1`] = `
[
{
"description": "something",
"purpose": "todo",
"purpose": "fixme",
"location": {
"line": 1
}
Expand Down
11 changes: 8 additions & 3 deletions packages/source-comments/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Source } from "@markings/types";
import { Source, RecordOfPurposes } from "@markings/types";
import * as BabelTypes from "@babel/types";

let commentTypes = ["TODO", "FIXME", "QUESTION"];
let commentPurposes: RecordOfPurposes = {
TODO: "todo",
FIXME: "fixme",
QUESTION: "question"
};
let commentTypes = Object.keys(commentPurposes);

export const source: Source = {
type: "babel",
Expand All @@ -16,7 +21,7 @@ export const source: Source = {
if (match !== null && commentTypes.includes(match[1])) {
addMarking({
description: match[2].trim(),
purpose: match[1] === "QUESTION" ? "question" : "todo",
purpose: commentPurposes[match[1]],
location: {
line: comment.loc.start.line
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Marking description="something" purpose="fixme" />;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Marking description="something" purpose="todo" />;
34 changes: 33 additions & 1 deletion packages/source-react/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,23 @@ exports[`with-child-func 1`] = `
]
`;

exports[`with-purpose 1`] = `
exports[`with-purpose-fixme 1`] = `
<Marking description="something" purpose="fixme" />;
↓ ↓ ↓ ↓ ↓ ↓
[
{
"description": "something",
"purpose": "fixme",
"location": {
"line": 1
}
}
]
`;

exports[`with-purpose-question 1`] = `
<Marking description="something" purpose="question" />;
↓ ↓ ↓ ↓ ↓ ↓
Expand All @@ -52,6 +68,22 @@ exports[`with-purpose 1`] = `
]
`;

exports[`with-purpose-todo 1`] = `
<Marking description="something" purpose="todo" />;
↓ ↓ ↓ ↓ ↓ ↓
[
{
"description": "something",
"purpose": "todo",
"location": {
"line": 1
}
}
]
`;

exports[`without-purpose 1`] = `
<Marking description="something" />;
Expand Down
4 changes: 3 additions & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Visitor } from "@babel/traverse";

export const PURPOSES = ["question", "todo"] as const;
export const PURPOSES = ["question", "todo", "fixme"] as const;

export type Purpose = typeof PURPOSES[number];

export type RecordOfPurposes = { [index: string]: Purpose};

export type PartialMarking = {
location: {
line: number;
Expand Down

0 comments on commit bb5c58f

Please sign in to comment.