Coverage for metrics / halstead / go.py: 100%

7 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-08 15:04 -0800

1"""Halstead complexity measures for Go.""" 

2 

3from __future__ import annotations 

4 

5from metrics.halstead.common import make_compute_halstead 

6 

7_GO_OPERATOR_TOKENS = { 

8 # Arithmetic 

9 "+", 

10 "-", 

11 "*", 

12 "/", 

13 "%", 

14 # Comparison 

15 "==", 

16 "!=", 

17 "<", 

18 ">", 

19 "<=", 

20 ">=", 

21 # Bitwise 

22 "&", 

23 "|", 

24 "^", 

25 "<<", 

26 ">>", 

27 "&^", 

28 # Logical (leaf tokens) 

29 "&&", 

30 "||", 

31 "!", 

32 # Assignment 

33 "=", 

34 ":=", 

35 "+=", 

36 "-=", 

37 "*=", 

38 "/=", 

39 "%=", 

40 "&=", 

41 "|=", 

42 "^=", 

43 "<<=", 

44 ">>=", 

45 "&^=", 

46 # Channel 

47 "<-", 

48 # Other symbols 

49 ".", 

50 ",", 

51 ":", 

52 ";", 

53 "(", 

54 ")", 

55 "[", 

56 "]", 

57 "{", 

58 "}", 

59 "...", 

60} 

61 

62_GO_KEYWORD_OPERATORS = { 

63 "if_statement", 

64 "for_statement", 

65 "expression_switch_statement", 

66 "type_switch_statement", 

67 "select_statement", 

68 "return_statement", 

69 "go_statement", 

70 "defer_statement", 

71 "function_declaration", 

72 "method_declaration", 

73 "var_declaration", 

74 "const_declaration", 

75 "type_declaration", 

76 "import_declaration", 

77 "short_var_declaration", 

78 "assignment_statement", 

79 "break_statement", 

80 "continue_statement", 

81 "goto_statement", 

82 "fallthrough_statement", 

83 "expression_case", 

84 "type_case", 

85 "default_case", 

86 "communication_case", 

87 "send_statement", 

88 "inc_statement", 

89 "dec_statement", 

90 "labeled_statement", 

91} 

92 

93_GO_OPERAND_TYPES = { 

94 "identifier", 

95 "type_identifier", 

96 "field_identifier", 

97 "package_identifier", 

98 "int_literal", 

99 "float_literal", 

100 "imaginary_literal", 

101 "rune_literal", 

102 "raw_string_literal", 

103 "interpreted_string_literal", 

104 "true", 

105 "false", 

106 "nil", 

107 "iota", 

108} 

109 

110_GO_COMMENT_TYPES = {"comment"} 

111 

112 

113compute_halstead_go = make_compute_halstead( 

114 _GO_COMMENT_TYPES, _GO_KEYWORD_OPERATORS, _GO_OPERAND_TYPES, _GO_OPERATOR_TOKENS 

115)