references.scm
1 ;; ─────────────────────────────────────────────────────────────────────────── 2 ;; os.environ.get("VAR") / o.environ.get("VAR") 3 ;; ─────────────────────────────────────────────────────────────────────────── 4 (call 5 function: (attribute 6 object: (attribute 7 object: (identifier) @module 8 attribute: (identifier) @_object) 9 attribute: (identifier) @_method) 10 arguments: (argument_list 11 (string 12 (string_content) @env_var_name) 13 (_)?) 14 (#eq? @_object "environ") 15 (#any-of? @_method "get" "pop" "setdefault")) @env_access 16 17 ;; ─────────────────────────────────────────────────────────────────────────── 18 ;; os.environ["VAR"] / o.environ["VAR"] 19 ;; ─────────────────────────────────────────────────────────────────────────── 20 (subscript 21 value: (attribute 22 object: (identifier) @module 23 attribute: (identifier) @_object) 24 subscript: (string 25 (string_content) @env_var_name) 26 (#eq? @_object "environ")) @env_access 27 28 ;; ─────────────────────────────────────────────────────────────────────────── 29 ;; os.getenv("VAR") / o.getenv("VAR") 30 ;; ─────────────────────────────────────────────────────────────────────────── 31 (call 32 function: (attribute 33 object: (identifier) @module 34 attribute: (identifier) @_method) 35 arguments: (argument_list 36 (string 37 (string_content) @env_var_name) 38 (_)?) 39 (#eq? @_method "getenv")) @env_access 40 41 ;; ─────────────────────────────────────────────────────────────────────────── 42 ;; environ["VAR"] (from os import environ) / e["VAR"] (as e) 43 ;; ─────────────────────────────────────────────────────────────────────────── 44 (subscript 45 value: (identifier) @object 46 subscript: (string 47 (string_content) @env_var_name) 48 ;; No built-in way to know if this identifier is environ without ImportContext check 49 ;; But we capture it as @object, and extract_references validates it. 50 ) @env_access 51 52 ;; ─────────────────────────────────────────────────────────────────────────── 53 ;; environ.get("VAR") / e.get("VAR") 54 ;; ─────────────────────────────────────────────────────────────────────────── 55 (call 56 function: (attribute 57 object: (identifier) @object 58 attribute: (identifier) @_method) 59 arguments: (argument_list 60 (string 61 (string_content) @env_var_name) 62 (_)?) 63 (#any-of? @_method "get" "pop" "setdefault") 64 ) @env_access 65 66 ;; ═════════════════════════════════════════════════════════════════════════ 67 ;; python-dotenv / decouple patterns 68 ;; ═════════════════════════════════════════════════════════════════════════ 69 70 ;; ─────────────────────────────────────────────────────────────────────────── 71 ;; dotenv.get_key('.env', 'VAR') 72 ;; ─────────────────────────────────────────────────────────────────────────── 73 (call 74 function: (attribute 75 object: (identifier) @_module 76 attribute: (identifier) @_method) 77 arguments: (argument_list 78 (_) 79 (string 80 (string_content) @env_var_name)) 81 (#eq? @_module "dotenv") 82 (#eq? @_method "get_key")) @env_access 83 84 ;; ─────────────────────────────────────────────────────────────────────────── 85 ;; dotenv_values('.env')['VAR'] 86 ;; ─────────────────────────────────────────────────────────────────────────── 87 (subscript 88 value: (call 89 function: (identifier) @_func 90 arguments: (argument_list 91 (_)?)) 92 subscript: (string 93 (string_content) @env_var_name) 94 (#eq? @_func "dotenv_values")) @env_access 95 96 ;; ─────────────────────────────────────────────────────────────────────────── 97 ;; decouple config('VAR') - python-decouple library 98 ;; ─────────────────────────────────────────────────────────────────────────── 99 (call 100 function: (identifier) @_func 101 arguments: (argument_list 102 (string 103 (string_content) @env_var_name) 104 (_)?) 105 (#eq? @_func "config")) @env_access 106 107 ;; ─────────────────────────────────────────────────────────────────────────── 108 ;; decouple.config('VAR') 109 ;; ─────────────────────────────────────────────────────────────────────────── 110 (call 111 function: (attribute 112 object: (identifier) @_module 113 attribute: (identifier) @_func) 114 arguments: (argument_list 115 (string 116 (string_content) @env_var_name) 117 (_)?) 118 (#eq? @_module "decouple") 119 (#eq? @_func "config")) @env_access 120 121 ;; ═════════════════════════════════════════════════════════════════════════ 122 ;; Function parameter default patterns 123 ;; ═════════════════════════════════════════════════════════════════════════ 124 125 ;; ─────────────────────────────────────────────────────────────────────────── 126 ;; def connect(db=os.getenv('DB')): ... 127 ;; ─────────────────────────────────────────────────────────────────────────── 128 (default_parameter 129 value: (call 130 function: (attribute 131 object: (identifier) @_module 132 attribute: (identifier) @_method) 133 arguments: (argument_list 134 (string 135 (string_content) @env_var_name) 136 (_)?)) 137 (#eq? @_module "os") 138 (#eq? @_method "getenv")) @env_access 139 140 ;; ─────────────────────────────────────────────────────────────────────────── 141 ;; def connect(db=os.environ.get('DB')): ... 142 ;; ─────────────────────────────────────────────────────────────────────────── 143 (default_parameter 144 value: (call 145 function: (attribute 146 object: (attribute 147 object: (identifier) @_module 148 attribute: (identifier) @_object) 149 attribute: (identifier) @_method) 150 arguments: (argument_list 151 (string 152 (string_content) @env_var_name) 153 (_)?)) 154 (#eq? @_module "os") 155 (#eq? @_object "environ") 156 (#any-of? @_method "get" "pop" "setdefault")) @env_access 157 158 ;; ─────────────────────────────────────────────────────────────────────────── 159 ;; def connect(db=os.environ['DB']): ... 160 ;; ─────────────────────────────────────────────────────────────────────────── 161 (default_parameter 162 value: (subscript 163 value: (attribute 164 object: (identifier) @_module 165 attribute: (identifier) @_object) 166 subscript: (string 167 (string_content) @env_var_name)) 168 (#eq? @_module "os") 169 (#eq? @_object "environ")) @env_access 170 171 ;; ═════════════════════════════════════════════════════════════════════════ 172 ;; Dictionary literal patterns 173 ;; ═════════════════════════════════════════════════════════════════════════ 174 175 ;; ─────────────────────────────────────────────────────────────────────────── 176 ;; config = {'db': os.environ['DB']} 177 ;; ─────────────────────────────────────────────────────────────────────────── 178 (pair 179 value: (subscript 180 value: (attribute 181 object: (identifier) @_module 182 attribute: (identifier) @_attr) 183 subscript: (string 184 (string_content) @env_var_name)) 185 (#eq? @_module "os") 186 (#eq? @_attr "environ")) @env_access 187 188 ;; ─────────────────────────────────────────────────────────────────────────── 189 ;; config = {'db': os.getenv('DB')} 190 ;; ─────────────────────────────────────────────────────────────────────────── 191 (pair 192 value: (call 193 function: (attribute 194 object: (identifier) @_module 195 attribute: (identifier) @_method) 196 arguments: (argument_list 197 (string 198 (string_content) @env_var_name) 199 (_)?)) 200 (#eq? @_module "os") 201 (#eq? @_method "getenv")) @env_access 202 203 ;; ─────────────────────────────────────────────────────────────────────────── 204 ;; config = {'db': os.environ.get('DB')} 205 ;; ─────────────────────────────────────────────────────────────────────────── 206 (pair 207 value: (call 208 function: (attribute 209 object: (attribute 210 object: (identifier) @_module 211 attribute: (identifier) @_object) 212 attribute: (identifier) @_method) 213 arguments: (argument_list 214 (string 215 (string_content) @env_var_name) 216 (_)?)) 217 (#eq? @_module "os") 218 (#eq? @_object "environ") 219 (#any-of? @_method "get" "pop" "setdefault")) @env_access