thailint 0.5.0__py3-none-any.whl → 0.15.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. src/__init__.py +1 -0
  2. src/analyzers/__init__.py +4 -3
  3. src/analyzers/ast_utils.py +54 -0
  4. src/analyzers/rust_base.py +155 -0
  5. src/analyzers/rust_context.py +141 -0
  6. src/analyzers/typescript_base.py +4 -0
  7. src/cli/__init__.py +30 -0
  8. src/cli/__main__.py +22 -0
  9. src/cli/config.py +480 -0
  10. src/cli/config_merge.py +241 -0
  11. src/cli/linters/__init__.py +67 -0
  12. src/cli/linters/code_patterns.py +270 -0
  13. src/cli/linters/code_smells.py +342 -0
  14. src/cli/linters/documentation.py +83 -0
  15. src/cli/linters/performance.py +287 -0
  16. src/cli/linters/shared.py +331 -0
  17. src/cli/linters/structure.py +327 -0
  18. src/cli/linters/structure_quality.py +328 -0
  19. src/cli/main.py +120 -0
  20. src/cli/utils.py +395 -0
  21. src/cli_main.py +37 -0
  22. src/config.py +38 -25
  23. src/core/base.py +7 -2
  24. src/core/cli_utils.py +19 -2
  25. src/core/config_parser.py +5 -2
  26. src/core/constants.py +54 -0
  27. src/core/linter_utils.py +95 -6
  28. src/core/python_lint_rule.py +101 -0
  29. src/core/registry.py +1 -1
  30. src/core/rule_discovery.py +147 -84
  31. src/core/types.py +13 -0
  32. src/core/violation_builder.py +78 -15
  33. src/core/violation_utils.py +69 -0
  34. src/formatters/__init__.py +22 -0
  35. src/formatters/sarif.py +202 -0
  36. src/linter_config/directive_markers.py +109 -0
  37. src/linter_config/ignore.py +254 -395
  38. src/linter_config/loader.py +45 -12
  39. src/linter_config/pattern_utils.py +65 -0
  40. src/linter_config/rule_matcher.py +89 -0
  41. src/linters/collection_pipeline/__init__.py +90 -0
  42. src/linters/collection_pipeline/any_all_analyzer.py +281 -0
  43. src/linters/collection_pipeline/ast_utils.py +40 -0
  44. src/linters/collection_pipeline/config.py +75 -0
  45. src/linters/collection_pipeline/continue_analyzer.py +94 -0
  46. src/linters/collection_pipeline/detector.py +360 -0
  47. src/linters/collection_pipeline/filter_map_analyzer.py +402 -0
  48. src/linters/collection_pipeline/linter.py +420 -0
  49. src/linters/collection_pipeline/suggestion_builder.py +130 -0
  50. src/linters/cqs/__init__.py +54 -0
  51. src/linters/cqs/config.py +55 -0
  52. src/linters/cqs/function_analyzer.py +201 -0
  53. src/linters/cqs/input_detector.py +139 -0
  54. src/linters/cqs/linter.py +159 -0
  55. src/linters/cqs/output_detector.py +84 -0
  56. src/linters/cqs/python_analyzer.py +54 -0
  57. src/linters/cqs/types.py +82 -0
  58. src/linters/cqs/typescript_cqs_analyzer.py +61 -0
  59. src/linters/cqs/typescript_function_analyzer.py +192 -0
  60. src/linters/cqs/typescript_input_detector.py +203 -0
  61. src/linters/cqs/typescript_output_detector.py +117 -0
  62. src/linters/cqs/violation_builder.py +94 -0
  63. src/linters/dry/base_token_analyzer.py +16 -9
  64. src/linters/dry/block_filter.py +120 -20
  65. src/linters/dry/block_grouper.py +4 -0
  66. src/linters/dry/cache.py +104 -10
  67. src/linters/dry/cache_query.py +4 -0
  68. src/linters/dry/config.py +54 -11
  69. src/linters/dry/constant.py +92 -0
  70. src/linters/dry/constant_matcher.py +223 -0
  71. src/linters/dry/constant_violation_builder.py +98 -0
  72. src/linters/dry/duplicate_storage.py +5 -4
  73. src/linters/dry/file_analyzer.py +4 -2
  74. src/linters/dry/inline_ignore.py +7 -16
  75. src/linters/dry/linter.py +183 -48
  76. src/linters/dry/python_analyzer.py +60 -439
  77. src/linters/dry/python_constant_extractor.py +100 -0
  78. src/linters/dry/single_statement_detector.py +417 -0
  79. src/linters/dry/token_hasher.py +116 -112
  80. src/linters/dry/typescript_analyzer.py +68 -382
  81. src/linters/dry/typescript_constant_extractor.py +138 -0
  82. src/linters/dry/typescript_statement_detector.py +255 -0
  83. src/linters/dry/typescript_value_extractor.py +70 -0
  84. src/linters/dry/violation_builder.py +4 -0
  85. src/linters/dry/violation_filter.py +5 -4
  86. src/linters/dry/violation_generator.py +71 -14
  87. src/linters/file_header/atemporal_detector.py +68 -50
  88. src/linters/file_header/base_parser.py +93 -0
  89. src/linters/file_header/bash_parser.py +66 -0
  90. src/linters/file_header/config.py +90 -16
  91. src/linters/file_header/css_parser.py +70 -0
  92. src/linters/file_header/field_validator.py +36 -33
  93. src/linters/file_header/linter.py +140 -144
  94. src/linters/file_header/markdown_parser.py +130 -0
  95. src/linters/file_header/python_parser.py +14 -58
  96. src/linters/file_header/typescript_parser.py +73 -0
  97. src/linters/file_header/violation_builder.py +13 -12
  98. src/linters/file_placement/config_loader.py +3 -1
  99. src/linters/file_placement/directory_matcher.py +4 -0
  100. src/linters/file_placement/linter.py +66 -34
  101. src/linters/file_placement/pattern_matcher.py +41 -6
  102. src/linters/file_placement/pattern_validator.py +31 -12
  103. src/linters/file_placement/rule_checker.py +12 -7
  104. src/linters/lazy_ignores/__init__.py +43 -0
  105. src/linters/lazy_ignores/config.py +74 -0
  106. src/linters/lazy_ignores/directive_utils.py +164 -0
  107. src/linters/lazy_ignores/header_parser.py +177 -0
  108. src/linters/lazy_ignores/linter.py +158 -0
  109. src/linters/lazy_ignores/matcher.py +168 -0
  110. src/linters/lazy_ignores/python_analyzer.py +209 -0
  111. src/linters/lazy_ignores/rule_id_utils.py +180 -0
  112. src/linters/lazy_ignores/skip_detector.py +298 -0
  113. src/linters/lazy_ignores/types.py +71 -0
  114. src/linters/lazy_ignores/typescript_analyzer.py +146 -0
  115. src/linters/lazy_ignores/violation_builder.py +135 -0
  116. src/linters/lbyl/__init__.py +31 -0
  117. src/linters/lbyl/config.py +63 -0
  118. src/linters/lbyl/linter.py +67 -0
  119. src/linters/lbyl/pattern_detectors/__init__.py +53 -0
  120. src/linters/lbyl/pattern_detectors/base.py +63 -0
  121. src/linters/lbyl/pattern_detectors/dict_key_detector.py +107 -0
  122. src/linters/lbyl/pattern_detectors/division_check_detector.py +232 -0
  123. src/linters/lbyl/pattern_detectors/file_exists_detector.py +220 -0
  124. src/linters/lbyl/pattern_detectors/hasattr_detector.py +119 -0
  125. src/linters/lbyl/pattern_detectors/isinstance_detector.py +119 -0
  126. src/linters/lbyl/pattern_detectors/len_check_detector.py +173 -0
  127. src/linters/lbyl/pattern_detectors/none_check_detector.py +146 -0
  128. src/linters/lbyl/pattern_detectors/string_validator_detector.py +145 -0
  129. src/linters/lbyl/python_analyzer.py +215 -0
  130. src/linters/lbyl/violation_builder.py +354 -0
  131. src/linters/magic_numbers/context_analyzer.py +227 -225
  132. src/linters/magic_numbers/linter.py +28 -82
  133. src/linters/magic_numbers/python_analyzer.py +4 -16
  134. src/linters/magic_numbers/typescript_analyzer.py +9 -12
  135. src/linters/magic_numbers/typescript_ignore_checker.py +81 -0
  136. src/linters/method_property/__init__.py +49 -0
  137. src/linters/method_property/config.py +138 -0
  138. src/linters/method_property/linter.py +414 -0
  139. src/linters/method_property/python_analyzer.py +473 -0
  140. src/linters/method_property/violation_builder.py +119 -0
  141. src/linters/nesting/linter.py +24 -16
  142. src/linters/nesting/python_analyzer.py +4 -0
  143. src/linters/nesting/typescript_analyzer.py +6 -12
  144. src/linters/nesting/violation_builder.py +1 -0
  145. src/linters/performance/__init__.py +91 -0
  146. src/linters/performance/config.py +43 -0
  147. src/linters/performance/constants.py +49 -0
  148. src/linters/performance/linter.py +149 -0
  149. src/linters/performance/python_analyzer.py +365 -0
  150. src/linters/performance/regex_analyzer.py +312 -0
  151. src/linters/performance/regex_linter.py +139 -0
  152. src/linters/performance/typescript_analyzer.py +236 -0
  153. src/linters/performance/violation_builder.py +160 -0
  154. src/linters/print_statements/config.py +7 -12
  155. src/linters/print_statements/linter.py +26 -43
  156. src/linters/print_statements/python_analyzer.py +91 -93
  157. src/linters/print_statements/typescript_analyzer.py +15 -25
  158. src/linters/print_statements/violation_builder.py +12 -14
  159. src/linters/srp/class_analyzer.py +11 -7
  160. src/linters/srp/heuristics.py +56 -22
  161. src/linters/srp/linter.py +15 -16
  162. src/linters/srp/python_analyzer.py +55 -20
  163. src/linters/srp/typescript_metrics_calculator.py +110 -50
  164. src/linters/stateless_class/__init__.py +25 -0
  165. src/linters/stateless_class/config.py +58 -0
  166. src/linters/stateless_class/linter.py +349 -0
  167. src/linters/stateless_class/python_analyzer.py +290 -0
  168. src/linters/stringly_typed/__init__.py +36 -0
  169. src/linters/stringly_typed/config.py +189 -0
  170. src/linters/stringly_typed/context_filter.py +451 -0
  171. src/linters/stringly_typed/function_call_violation_builder.py +135 -0
  172. src/linters/stringly_typed/ignore_checker.py +100 -0
  173. src/linters/stringly_typed/ignore_utils.py +51 -0
  174. src/linters/stringly_typed/linter.py +376 -0
  175. src/linters/stringly_typed/python/__init__.py +33 -0
  176. src/linters/stringly_typed/python/analyzer.py +348 -0
  177. src/linters/stringly_typed/python/call_tracker.py +175 -0
  178. src/linters/stringly_typed/python/comparison_tracker.py +257 -0
  179. src/linters/stringly_typed/python/condition_extractor.py +134 -0
  180. src/linters/stringly_typed/python/conditional_detector.py +179 -0
  181. src/linters/stringly_typed/python/constants.py +21 -0
  182. src/linters/stringly_typed/python/match_analyzer.py +94 -0
  183. src/linters/stringly_typed/python/validation_detector.py +189 -0
  184. src/linters/stringly_typed/python/variable_extractor.py +96 -0
  185. src/linters/stringly_typed/storage.py +620 -0
  186. src/linters/stringly_typed/storage_initializer.py +45 -0
  187. src/linters/stringly_typed/typescript/__init__.py +28 -0
  188. src/linters/stringly_typed/typescript/analyzer.py +157 -0
  189. src/linters/stringly_typed/typescript/call_tracker.py +335 -0
  190. src/linters/stringly_typed/typescript/comparison_tracker.py +378 -0
  191. src/linters/stringly_typed/violation_generator.py +419 -0
  192. src/orchestrator/core.py +252 -14
  193. src/orchestrator/language_detector.py +5 -3
  194. src/templates/thailint_config_template.yaml +196 -0
  195. src/utils/project_root.py +3 -0
  196. thailint-0.15.3.dist-info/METADATA +187 -0
  197. thailint-0.15.3.dist-info/RECORD +226 -0
  198. thailint-0.15.3.dist-info/entry_points.txt +4 -0
  199. src/cli.py +0 -1665
  200. thailint-0.5.0.dist-info/METADATA +0 -1286
  201. thailint-0.5.0.dist-info/RECORD +0 -96
  202. thailint-0.5.0.dist-info/entry_points.txt +0 -4
  203. {thailint-0.5.0.dist-info → thailint-0.15.3.dist-info}/WHEEL +0 -0
  204. {thailint-0.5.0.dist-info → thailint-0.15.3.dist-info}/licenses/LICENSE +0 -0
@@ -3,245 +3,247 @@ Purpose: Analyzes contexts to determine if numeric literals are acceptable
3
3
 
4
4
  Scope: Context detection for magic number acceptable usage patterns
5
5
 
6
- Overview: Provides ContextAnalyzer class that determines whether a numeric literal is in an acceptable
6
+ Overview: Provides module-level functions that determine whether a numeric literal is in an acceptable
7
7
  context where it should not be flagged as a magic number. Detects acceptable contexts including
8
8
  constant definitions (UPPERCASE names), small integers in range() or enumerate() calls, test files,
9
9
  and configuration contexts. Uses AST node analysis to inspect parent nodes and determine the usage
10
10
  pattern of numeric literals. Helps reduce false positives by distinguishing between legitimate
11
- numeric literals and true magic numbers that should be extracted to constants. Method count (10)
12
- exceeds SRP limit (8) because refactoring for A-grade complexity requires extracting helper methods.
13
- Class maintains single responsibility of context analysis - all methods support this core purpose.
11
+ numeric literals and true magic numbers that should be extracted to constants.
14
12
 
15
13
  Dependencies: ast module for AST node types, pathlib for Path handling
16
14
 
17
- Exports: ContextAnalyzer class
15
+ Exports: is_acceptable_context function and helper functions
18
16
 
19
- Interfaces: ContextAnalyzer.is_acceptable_context(node, parent, file_path, config) -> bool,
20
- various helper methods for specific context checks
17
+ Interfaces: is_acceptable_context(node, parent, file_path, config) -> bool
21
18
 
22
19
  Implementation: AST parent node inspection, pattern matching for acceptable contexts, configurable
23
20
  max_small_integer threshold for range detection
21
+
22
+ Suppressions:
23
+ - B101: Assert used for internal invariant checking, not security validation
24
24
  """
25
25
 
26
26
  import ast
27
27
  from pathlib import Path
28
28
 
29
29
 
30
- class ContextAnalyzer: # thailint: ignore[srp]
31
- """Analyzes contexts to determine if numeric literals are acceptable."""
32
-
33
- def is_acceptable_context(
34
- self,
35
- node: ast.Constant,
36
- parent: ast.AST | None,
37
- file_path: Path | None,
38
- config: dict,
39
- ) -> bool:
40
- """Check if a numeric literal is in an acceptable context.
41
-
42
- Args:
43
- node: The numeric constant node
44
- parent: The parent node in the AST
45
- file_path: Path to the file being analyzed
46
- config: Configuration with allowed_numbers and max_small_integer
47
-
48
- Returns:
49
- True if the context is acceptable and should not be flagged
50
- """
51
- # File-level and definition checks
52
- if self.is_test_file(file_path) or self.is_constant_definition(node, parent):
53
- return True
54
-
55
- # Usage pattern checks
56
- return self._is_acceptable_usage_pattern(node, parent, config)
57
-
58
- def _is_acceptable_usage_pattern(
59
- self, node: ast.Constant, parent: ast.AST | None, config: dict
60
- ) -> bool:
61
- """Check if numeric literal is in acceptable usage pattern.
62
-
63
- Args:
64
- node: The numeric constant node
65
- parent: The parent node in the AST
66
- config: Configuration with max_small_integer threshold
67
-
68
- Returns:
69
- True if usage pattern is acceptable
70
- """
71
- if self.is_small_integer_in_range(node, parent, config):
72
- return True
73
-
74
- if self.is_small_integer_in_enumerate(node, parent, config):
75
- return True
76
-
77
- return self.is_string_repetition(node, parent)
78
-
79
- def is_test_file(self, file_path: Path | None) -> bool:
80
- """Check if the file is a test file.
81
-
82
- Args:
83
- file_path: Path to the file
84
-
85
- Returns:
86
- True if the file is a test file (matches test_*.py pattern)
87
- """
88
- if not file_path:
89
- return False
90
- return file_path.name.startswith("test_") or "_test.py" in file_path.name
91
-
92
- def is_constant_definition(self, node: ast.Constant, parent: ast.AST | None) -> bool:
93
- """Check if the number is part of an UPPERCASE constant definition.
94
-
95
- Args:
96
- node: The numeric constant node
97
- parent: The parent node in the AST
98
-
99
- Returns:
100
- True if this is a constant definition
101
- """
102
- if not self._is_assignment_node(parent):
103
- return False
104
-
105
- # Type narrowing: parent is ast.Assign after the check above
106
- assert isinstance(parent, ast.Assign) # nosec B101
107
- return self._has_constant_target(parent)
108
-
109
- def _is_assignment_node(self, parent: ast.AST | None) -> bool:
110
- """Check if parent is an assignment node."""
111
- return parent is not None and isinstance(parent, ast.Assign)
112
-
113
- def _has_constant_target(self, parent: ast.Assign) -> bool:
114
- """Check if assignment has uppercase constant target."""
115
- return any(
116
- isinstance(target, ast.Name) and self._is_constant_name(target.id)
117
- for target in parent.targets
118
- )
119
-
120
- def _is_constant_name(self, name: str) -> bool:
121
- """Check if a name follows constant naming convention.
122
-
123
- Args:
124
- name: Variable name to check
125
-
126
- Returns:
127
- True if the name is UPPERCASE (constant convention)
128
- """
129
- return name.isupper() and len(name) > 1
130
-
131
- def is_small_integer_in_range(
132
- self, node: ast.Constant, parent: ast.AST | None, config: dict
133
- ) -> bool:
134
- """Check if this is a small integer used in range() call.
135
-
136
- Args:
137
- node: The numeric constant node
138
- parent: The parent node in the AST
139
- config: Configuration with max_small_integer threshold
140
-
141
- Returns:
142
- True if this is a small integer in range()
143
- """
144
- if not isinstance(node.value, int):
145
- return False
146
-
147
- max_small_int = config.get("max_small_integer", 10)
148
- if not 0 <= node.value <= max_small_int:
149
- return False
150
-
151
- return self._is_in_range_call(parent)
152
-
153
- def is_small_integer_in_enumerate(
154
- self, node: ast.Constant, parent: ast.AST | None, config: dict
155
- ) -> bool:
156
- """Check if this is a small integer used in enumerate() call.
157
-
158
- Args:
159
- node: The numeric constant node
160
- parent: The parent node in the AST
161
- config: Configuration with max_small_integer threshold
162
-
163
- Returns:
164
- True if this is a small integer in enumerate()
165
- """
166
- if not isinstance(node.value, int):
167
- return False
168
-
169
- max_small_int = config.get("max_small_integer", 10)
170
- if not 0 <= node.value <= max_small_int:
171
- return False
172
-
173
- return self._is_in_enumerate_call(parent)
174
-
175
- def _is_in_range_call(self, parent: ast.AST | None) -> bool:
176
- """Check if the parent is a range() call.
177
-
178
- Args:
179
- parent: The parent node
180
-
181
- Returns:
182
- True if parent is range() call
183
- """
184
- return (
185
- isinstance(parent, ast.Call)
186
- and isinstance(parent.func, ast.Name)
187
- and parent.func.id == "range"
188
- )
189
-
190
- def _is_in_enumerate_call(self, parent: ast.AST | None) -> bool:
191
- """Check if the parent is an enumerate() call.
192
-
193
- Args:
194
- parent: The parent node
195
-
196
- Returns:
197
- True if parent is enumerate() call
198
- """
199
- return (
200
- isinstance(parent, ast.Call)
201
- and isinstance(parent.func, ast.Name)
202
- and parent.func.id == "enumerate"
203
- )
204
-
205
- def is_string_repetition(self, node: ast.Constant, parent: ast.AST | None) -> bool:
206
- """Check if this number is used in string repetition (e.g., "-" * 40).
207
-
208
- Args:
209
- node: The numeric constant node
210
- parent: The parent node in the AST
211
-
212
- Returns:
213
- True if this is a string repetition pattern
214
- """
215
- if not isinstance(node.value, int):
216
- return False
217
-
218
- if not isinstance(parent, ast.BinOp):
219
- return False
220
-
221
- if not isinstance(parent.op, ast.Mult):
222
- return False
223
-
224
- # Check if either operand is a string constant
225
- return self._has_string_operand(parent)
226
-
227
- def _has_string_operand(self, binop: ast.BinOp) -> bool:
228
- """Check if binary operation has a string operand.
229
-
230
- Args:
231
- binop: Binary operation node
232
-
233
- Returns:
234
- True if either left or right operand is a string constant
235
- """
236
- return self._is_string_constant(binop.left) or self._is_string_constant(binop.right)
237
-
238
- def _is_string_constant(self, node: ast.AST) -> bool:
239
- """Check if a node is a string constant.
240
-
241
- Args:
242
- node: AST node to check
243
-
244
- Returns:
245
- True if node is a Constant with string value
246
- """
247
- return isinstance(node, ast.Constant) and isinstance(node.value, str)
30
+ def is_acceptable_context(
31
+ node: ast.Constant,
32
+ parent: ast.AST | None,
33
+ file_path: Path | None,
34
+ config: dict,
35
+ ) -> bool:
36
+ """Check if a numeric literal is in an acceptable context.
37
+
38
+ Args:
39
+ node: The numeric constant node
40
+ parent: The parent node in the AST
41
+ file_path: Path to the file being analyzed
42
+ config: Configuration with allowed_numbers and max_small_integer
43
+
44
+ Returns:
45
+ True if the context is acceptable and should not be flagged
46
+ """
47
+ # File-level and definition checks
48
+ if is_test_file(file_path) or is_constant_definition(node, parent):
49
+ return True
50
+
51
+ # Usage pattern checks
52
+ return _is_acceptable_usage_pattern(node, parent, config)
53
+
54
+
55
+ def _is_acceptable_usage_pattern(node: ast.Constant, parent: ast.AST | None, config: dict) -> bool:
56
+ """Check if numeric literal is in acceptable usage pattern.
57
+
58
+ Args:
59
+ node: The numeric constant node
60
+ parent: The parent node in the AST
61
+ config: Configuration with max_small_integer threshold
62
+
63
+ Returns:
64
+ True if usage pattern is acceptable
65
+ """
66
+ if is_small_integer_in_range(node, parent, config):
67
+ return True
68
+
69
+ if is_small_integer_in_enumerate(node, parent, config):
70
+ return True
71
+
72
+ return is_string_repetition(node, parent)
73
+
74
+
75
+ def is_test_file(file_path: Path | None) -> bool:
76
+ """Check if the file is a test file.
77
+
78
+ Args:
79
+ file_path: Path to the file
80
+
81
+ Returns:
82
+ True if the file is a test file (matches test_*.py pattern)
83
+ """
84
+ if not file_path:
85
+ return False
86
+ return file_path.name.startswith("test_") or "_test.py" in file_path.name
87
+
88
+
89
+ def is_constant_definition(node: ast.Constant, parent: ast.AST | None) -> bool:
90
+ """Check if the number is part of an UPPERCASE constant definition.
91
+
92
+ Args:
93
+ node: The numeric constant node
94
+ parent: The parent node in the AST
95
+
96
+ Returns:
97
+ True if this is a constant definition
98
+ """
99
+ if not _is_assignment_node(parent):
100
+ return False
101
+
102
+ # Type narrowing: parent is ast.Assign after the check above
103
+ assert isinstance(parent, ast.Assign) # nosec B101
104
+ return _has_constant_target(parent)
105
+
106
+
107
+ def _is_assignment_node(parent: ast.AST | None) -> bool:
108
+ """Check if parent is an assignment node."""
109
+ return parent is not None and isinstance(parent, ast.Assign)
110
+
111
+
112
+ def _has_constant_target(parent: ast.Assign) -> bool:
113
+ """Check if assignment has uppercase constant target."""
114
+ return any(
115
+ isinstance(target, ast.Name) and _is_constant_name(target.id) for target in parent.targets
116
+ )
117
+
118
+
119
+ def _is_constant_name(name: str) -> bool:
120
+ """Check if a name follows constant naming convention.
121
+
122
+ Args:
123
+ name: Variable name to check
124
+
125
+ Returns:
126
+ True if the name is UPPERCASE (constant convention)
127
+ """
128
+ return name.isupper() and len(name) > 1
129
+
130
+
131
+ def is_small_integer_in_range(node: ast.Constant, parent: ast.AST | None, config: dict) -> bool:
132
+ """Check if this is a small integer used in range() call.
133
+
134
+ Args:
135
+ node: The numeric constant node
136
+ parent: The parent node in the AST
137
+ config: Configuration with max_small_integer threshold
138
+
139
+ Returns:
140
+ True if this is a small integer in range()
141
+ """
142
+ if not isinstance(node.value, int):
143
+ return False
144
+
145
+ max_small_int = config.get("max_small_integer", 10)
146
+ if not 0 <= node.value <= max_small_int:
147
+ return False
148
+
149
+ return _is_in_range_call(parent)
150
+
151
+
152
+ def is_small_integer_in_enumerate(node: ast.Constant, parent: ast.AST | None, config: dict) -> bool:
153
+ """Check if this is a small integer used in enumerate() call.
154
+
155
+ Args:
156
+ node: The numeric constant node
157
+ parent: The parent node in the AST
158
+ config: Configuration with max_small_integer threshold
159
+
160
+ Returns:
161
+ True if this is a small integer in enumerate()
162
+ """
163
+ if not isinstance(node.value, int):
164
+ return False
165
+
166
+ max_small_int = config.get("max_small_integer", 10)
167
+ if not 0 <= node.value <= max_small_int:
168
+ return False
169
+
170
+ return _is_in_enumerate_call(parent)
171
+
172
+
173
+ def _is_in_range_call(parent: ast.AST | None) -> bool:
174
+ """Check if the parent is a range() call.
175
+
176
+ Args:
177
+ parent: The parent node
178
+
179
+ Returns:
180
+ True if parent is range() call
181
+ """
182
+ return (
183
+ isinstance(parent, ast.Call)
184
+ and isinstance(parent.func, ast.Name)
185
+ and parent.func.id == "range"
186
+ )
187
+
188
+
189
+ def _is_in_enumerate_call(parent: ast.AST | None) -> bool:
190
+ """Check if the parent is an enumerate() call.
191
+
192
+ Args:
193
+ parent: The parent node
194
+
195
+ Returns:
196
+ True if parent is enumerate() call
197
+ """
198
+ return (
199
+ isinstance(parent, ast.Call)
200
+ and isinstance(parent.func, ast.Name)
201
+ and parent.func.id == "enumerate"
202
+ )
203
+
204
+
205
+ def is_string_repetition(node: ast.Constant, parent: ast.AST | None) -> bool:
206
+ """Check if this number is used in string repetition (e.g., "-" * 40).
207
+
208
+ Args:
209
+ node: The numeric constant node
210
+ parent: The parent node in the AST
211
+
212
+ Returns:
213
+ True if this is a string repetition pattern
214
+ """
215
+ if not isinstance(node.value, int):
216
+ return False
217
+
218
+ if not isinstance(parent, ast.BinOp):
219
+ return False
220
+
221
+ if not isinstance(parent.op, ast.Mult):
222
+ return False
223
+
224
+ # Check if either operand is a string constant
225
+ return _has_string_operand(parent)
226
+
227
+
228
+ def _has_string_operand(binop: ast.BinOp) -> bool:
229
+ """Check if binary operation has a string operand.
230
+
231
+ Args:
232
+ binop: Binary operation node
233
+
234
+ Returns:
235
+ True if either left or right operand is a string constant
236
+ """
237
+ return _is_string_constant(binop.left) or _is_string_constant(binop.right)
238
+
239
+
240
+ def _is_string_constant(node: ast.AST) -> bool:
241
+ """Check if a node is a string constant.
242
+
243
+ Args:
244
+ node: AST node to check
245
+
246
+ Returns:
247
+ True if node is a Constant with string value
248
+ """
249
+ return isinstance(node, ast.Constant) and isinstance(node.value, str)