Skip to content

Commit

Permalink
Merge pull request #6 from phntmxyz/support-diff-tag-within-code
Browse files Browse the repository at this point in the history
Support diff tag within code
  • Loading branch information
rehlma authored Oct 29, 2024
2 parents 059e66f + be11fe7 commit a0b3691
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 4 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![GitHub Marketplace](https://img.shields.io/badge/Marketplace-PR%20Todo%20Checker-blue?logo=github)](https://github.com/marketplace/actions/pr-todo-checker)

[![GitHub Super-Linter](https://github.com/phntmxyz/pr_todo_checker/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/phntmxyz/pr_todo_checker/actions/workflows/ci.yml/badge.svg)
[![Check dist/](https://github.com/phntmxyz/pr_todo_checker/actions/workflows/check-dist.yml/badge.svg)](https://github.com/phntmxyz/pr_todo_checker/actions/workflows/check-dist.yml)
[![CodeQL](https://github.com/phntmxyz/pr_todo_checker/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/phntmxyz/pr_todo_checker/actions/workflows/codeql-analysis.yml)
Expand Down
32 changes: 32 additions & 0 deletions __test__/test_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,35 @@ export const multiDiffInPatch: PrDiff = [
}`
}
]

export const atAtInDiff: PrDiff = [
{
sha: '111111111',
filename: 'first.dart',
status: 'removed',
additions: 0,
deletions: 5,
changes: 5,
blob_url: '',
raw_url: '',
contents_url: '',
patch: `@@ -1,7 +1,6 @@
import 'dart:async';
import 'package:a/a.dart';
-import 'package:b/b.dart';
import 'package:c/c.dart';
import 'package:d/d.dart';
@@ -109,9 +108,6 @@ class A extends B {
- // todo: remove
a.b();
}
-
- @visibleForTesting
- B? b;
}
/// Comment.`
}
]
16 changes: 16 additions & 0 deletions __test__/todo-finder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,22 @@ describe('extract Todos', () => {
expect(fileTodos).toEqual(expectedTodos)
})

it('should not parse diff content in code', () => {
const customMatcher = '{}'
const fileTodos = findTodos(testData.atAtInDiff, [], customMatcher)

const expectedTodos: Todo[] = [
{
filename: 'first.dart',
line: 9,
content: 'todo: remove',
isAdded: false
}
]

expect(fileTodos).toEqual(expectedTodos)
})

it('should correctly exclude files', () => {
const exclude = ['**/*.yml', '**/excluded/*']

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29530,7 +29530,7 @@ function findTodos(prDiff, exclude = [], customTodoMatcherString = '{}') {
const firstAddedLineRegex = /\+(\d+)/;
const firstRemovedLineRegex = /-(\d+)/;
// Find new diff line @@ -128,12 +128,14 @@ class XYZ {
const newDiffLineRegex = /(@@ [-|+]?\d+,\d+ [-|+]?\d+,\d+ @@)(@@ [-|+]?\d+,\d+ [-|+]?\d+,\d+ @@)*/gm;
const newDiffLineRegex = /(^@@ [-|+]?\d+,\d+ [-|+]?\d+,\d+ @@)(@@ [-|+]?\d+,\d+ [-|+]?\d+,\d+ @@)*/gm;
const todos = [];
for (const file of prDiff) {
const excluded = exclude.some(pattern => (0, minimatch_1.minimatch)(file.filename, pattern));
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/todo-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function findTodos(
const firstRemovedLineRegex = /-(\d+)/
// Find new diff line @@ -128,12 +128,14 @@ class XYZ {
const newDiffLineRegex =
/(@@ [-|+]?\d+,\d+ [-|+]?\d+,\d+ @@)(@@ [-|+]?\d+,\d+ [-|+]?\d+,\d+ @@)*/gm
/(^@@ [-|+]?\d+,\d+ [-|+]?\d+,\d+ @@)(@@ [-|+]?\d+,\d+ [-|+]?\d+,\d+ @@)*/gm

const todos: Todo[] = []

Expand Down

0 comments on commit a0b3691

Please sign in to comment.