Skip to content

Commit

Permalink
fix: #296
Browse files Browse the repository at this point in the history
  • Loading branch information
terryyin committed Feb 4, 2025
1 parent fed797c commit bcbf2e2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lizard_languages/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ def __init__(self, context):
super(GoReader, self).__init__(context)
self.parallel_states = [GoStates(context)]

@staticmethod
def generate_tokens(source_code, addition='', token_class=None):
addition = addition + r"|`[^`]*`" # Add support for backtick-quoted strings
return CodeReader.generate_tokens(source_code, addition, token_class)

def __call__(self, tokens, reader):
self.context = reader.context
for token in tokens:
# Skip counting ? in backtick-quoted strings
if token.startswith('`') and token.endswith('`'):
for state in self.parallel_states:
state(token)
yield token
continue

# For non-backtick tokens, process normally
for state in self.parallel_states:
state(token)
yield token
for state in self.parallel_states:
state.statemachine_before_return()
self.eof()


class GoStates(GoLikeStates): # pylint: disable=R0903
pass
14 changes: 14 additions & 0 deletions test/test_languages/testGo.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,17 @@ def test_interface_with_func_followed_by_function_with_receiver(self):

self.assertEqual(1, len(result))
self.assertEqual("Handle", result[0].name)

def test_sql_query_with_question_marks(self):
result = get_go_function_list('''
func getQuery(dbIndex uint32, tbIndex uint32) string {
query := fmt.Sprintf(`INSERT INTO online_docs_%d.online_docs_notify_%d
(a, b, c, d, e, f, g, h, i, j)
VALUES (?, ?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?), ?, %d)`,
dbIndex, tbIndex, notifyStatusNew)
return query
}
''')
self.assertEqual(1, len(result))
self.assertEqual("getQuery", result[0].name)
self.assertEqual(1, result[0].cyclomatic_complexity)

0 comments on commit bcbf2e2

Please sign in to comment.