Skip to content

Commit

Permalink
Modify current count routine to only work for Feature.token
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Peveler <[email protected]>
  • Loading branch information
MasterOdin committed Feb 22, 2022
1 parent 2cd0f0c commit 1d96305
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export function countToken(tree: Tree, feature: Feature, token: string): number
const cursor = tree.rootNode.walk();
while (true) {
if (cursor.gotoFirstChild() || cursor.gotoNextSibling()) {
if (convertTokenName(cursor.nodeType).toLowerCase() === tokenLower) {
if (
feature === Feature.token &&
convertTokenName(cursor.nodeType).toLowerCase() === tokenLower
) {
count++;
}
continue;
Expand All @@ -41,7 +44,11 @@ export function countToken(tree: Tree, feature: Feature, token: string): number
break;
}
}
if (hadSibling && convertTokenName(cursor.nodeType).toLowerCase() === tokenLower) {
if (
feature === Feature.token &&
hadSibling &&
convertTokenName(cursor.nodeType).toLowerCase() === tokenLower
) {
count++;
}
if (cursor.currentNode === tree.rootNode) {
Expand Down
2 changes: 2 additions & 0 deletions test/diagnostics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ describe('diagnostics', () => {
});
});

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

0 comments on commit 1d96305

Please sign in to comment.