Skip to content

Commit 6ce5c15

Browse files
committed
Improve readme structure, add todos
1 parent fb4db32 commit 6ce5c15

6 files changed

Lines changed: 222 additions & 196 deletions

File tree

packages/annotation-comments/README.md

Lines changed: 159 additions & 168 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { AnnotationComment } from './types'
2+
3+
export type CleanCodeOptions = {
4+
codeLines: string[]
5+
annotationComments: AnnotationComment[]
6+
removeAnnotationContents?: boolean | ((context: RemoveAnnotationContentsContext) => boolean)
7+
updateTargetRanges?: boolean
8+
handleRemoveLine?: (context: HandleRemoveLineContext) => boolean
9+
handleEditLine?: (context: HandleEditLineContext) => boolean
10+
}
11+
12+
export type RemoveAnnotationContentsContext = {
13+
comment: AnnotationComment
14+
}
15+
16+
export type HandleRemoveLineContext = {
17+
lineIndex: number
18+
codeLines: string[]
19+
}
20+
21+
export type HandleEditLineContext = {
22+
lineIndex: number
23+
startColumn: number
24+
endColumn: number
25+
codeLines: string[]
26+
}
27+
28+
export function cleanCode(options: CleanCodeOptions) {
29+
const { annotationComments, codeLines, updateTargetRanges, handleRemoveLine, handleEditLine: handleRemoveInlineRange } = options
30+
// TODO: Implement cleanCode()
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
- Now, the function goes through all identified annotation comments and does the following:
3+
- If the annotation has **no relative target range** given, automatically determine it:
4+
- If the annotation has **no target search query**, it attempts to target full lines:
5+
- If the **annotation comment is on the same line as content** (= annotation start line contains content other than whitespace or other annotation comments), the target range is the annotation comment line.
6+
- Otherwise, find the first line above and first line below that don't fully consist of annotation comments
7+
- If the **line below has content**, it is the target range.
8+
- Otherwise, if the **line above has content**, it is the target range.
9+
- Otherwise (**both lines are empty**), there is no target range (same as the relative range `:0`).
10+
- Otherwise, the annotation **has a target search query**, so determine the search direction:
11+
- If the **annotation comment is on the same line as content** (= annotation start line contains content other than whitespace or other annotation comments), the direction depends on where the content is in relation to the comment.
12+
- Otherwise, find the first line above and first line below that don't fully consist of annotation comments
13+
- If the **line above has content** and the **line below is empty**, the relative range is `:-1`.
14+
- Otherwise, the relative range is `:1`.
15+
- If a target search query is present, **perform the search** to determine the target range(s):
16+
- The target search query can be a simple string, a single-quoted string, a double-quoted string, or a regular expression. Regular expressions can optionally contain capture groups, which will then be used to determine the target range(s) instead of the full match.
17+
- The search is performed line by line, starting at the start or end of the annotation comment and going in the direction determined by the relative target range that was either given or automatically determined as described above.
18+
- Before searching a line for matches, all characters that lie within the `outerRange` of any annotation comment are removed from the line. If matches are found, the matched ranges are adjusted to include the removed characters.
19+
- Each match is added to the `targetRanges` until the number of matches equals the absolute value of the relative target range, or the end of the code is reached.
20+
- In the case of regular expressions with capture groups, a single match can result in multiple target ranges, one for each capture group.
21+
*/
22+
23+
export function findAnnotationTargets() {
24+
// TODO: Implement findAnnotationTargets()
25+
}

packages/annotation-comments/src/core/parse.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,7 @@ export function parseAnnotationComments(options: ParseAnnotationCommentsOptions)
5656
previousContentRanges = comment.contentRanges
5757
})
5858

59+
// TODO: Call findAnnotationTargets() here
60+
5961
return annotationComments
6062
}

packages/annotation-comments/src/core/remove.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/annotation-comments/test/parse.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ countdown(5)
254254
tag: { name: 'before', targetSearchQuery: undefined },
255255
contents: [`This is before any ignores`],
256256
},
257+
// TODO: Expect the ignore-tags annotation comment to be present as well
257258
{
258259
tag: { name: 'after', targetSearchQuery: undefined },
259260
contents: [`This should be parsed again`],
@@ -276,6 +277,7 @@ countdown(5)
276277
tag: { name: 'before', targetSearchQuery: undefined },
277278
contents: [`This is before any ignores`],
278279
},
280+
// TODO: Expect the ignore-tags annotation comment to be present as well
279281
{
280282
tag: { name: 'after', targetSearchQuery: undefined },
281283
contents: [`This should be parsed again`],
@@ -297,6 +299,7 @@ countdown(5)
297299
tag: { name: 'before', targetSearchQuery: undefined },
298300
contents: [`This is before any ignores`],
299301
},
302+
// TODO: Expect the ignore-tags annotation comment to be present as well
300303
{
301304
tag: { name: 'note', targetSearchQuery: undefined },
302305
contents: [`This should be parsed again`],
@@ -321,6 +324,7 @@ countdown(5)
321324
tag: { name: 'before', targetSearchQuery: undefined },
322325
contents: [`This is before any ignores`],
323326
},
327+
// TODO: Expect the ignore-tags annotation comment to be present as well
324328
{
325329
tag: { name: 'ins', targetSearchQuery: undefined },
326330
contents: [],
@@ -351,6 +355,7 @@ countdown(5)
351355
commentRange: { start: { line: 0 }, end: { line: 5 } },
352356
annotationRange: { start: { line: 1 }, end: { line: 1 } },
353357
},
358+
// TODO: Expect the ignore-tags annotation comment to be present as well
354359
{
355360
tag: { name: 'note', targetSearchQuery: undefined },
356361
contents: [`This should be parsed again`],

0 commit comments

Comments
 (0)