Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support diff tag within code #6

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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