Skip to content

Commit 1d96305

Browse files
committed
Modify current count routine to only work for Feature.token
Signed-off-by: Matthew Peveler <matt.peveler@gmail.com>
1 parent 2cd0f0c commit 1d96305

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/count.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export function countToken(tree: Tree, feature: Feature, token: string): number
2828
const cursor = tree.rootNode.walk();
2929
while (true) {
3030
if (cursor.gotoFirstChild() || cursor.gotoNextSibling()) {
31-
if (convertTokenName(cursor.nodeType).toLowerCase() === tokenLower) {
31+
if (
32+
feature === Feature.token &&
33+
convertTokenName(cursor.nodeType).toLowerCase() === tokenLower
34+
) {
3235
count++;
3336
}
3437
continue;
@@ -41,7 +44,11 @@ export function countToken(tree: Tree, feature: Feature, token: string): number
4144
break;
4245
}
4346
}
44-
if (hadSibling && convertTokenName(cursor.nodeType).toLowerCase() === tokenLower) {
47+
if (
48+
feature === Feature.token &&
49+
hadSibling &&
50+
convertTokenName(cursor.nodeType).toLowerCase() === tokenLower
51+
) {
4552
count++;
4653
}
4754
if (cursor.currentNode === tree.rootNode) {

test/diagnostics.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ describe('diagnostics', () => {
6363
});
6464
});
6565

66+
// Testing that we find tokens that are at end of lines, after tokens with
67+
// children
6668
test('find all colon tokens', () => {
6769
const { tokens } = diagnostics(
6870
parseFile(Language.python, path.join(TEST_DATA, 'python', 'operators.py')),

0 commit comments

Comments
 (0)