fix: declareColumns now correctly sanitizes Haskell Identifiers passed to it#43
Conversation
| specs = zip names types | ||
| specs = zipWith (\name type_ -> (sanitize name, type_)) names types | ||
| sanitize t = if isValidIdentifier t | ||
| then "_" <> T.filter Char.isAlphaNum t <> "_" |
There was a problem hiding this comment.
maybe let's move this branching logic to a separate function and write some test cases for it.
Some column names I'm curious about:
- "Data": your code handles this well
- "My Data": this will become
"_MyData_". I assume isAlphaNum filters spaces, right? My intuition says it should be "my_data" - "Distance (km/h)": this will become
"_Distancekmh_". It should be "distance_km_h". - "0 Age": this will become
"_0Age_". It should probably be"_0_age_" - "***": should fail and I think it fails fine in this case.
Also the condition looks backwards. It should be if valid then t else filter t.
There was a problem hiding this comment.
Ok so I've modified my logic to better fit what you described here. I filter out parentheses but leave valid strings alone. With the current logic I have:
Data -> _data_
My Data -> my_data
Distance (km/h) -> distance_km_h
0 Age -> _0_age_
camelCaseStr -> camelCaseStr
camelCase$Str -> camelcase_str -- an invalid character will flatten the entire identifier
snake_case_str -> snake_case_str
12_snake_case -> _12_snake_case_
*** -> _____ -- the stars are turned into underscores and then underscores on either side
There was a problem hiding this comment.
Also the condition was actually correct, I'd just named it very poorly. Let me know if the current logic and naming looks wonky too.
|
Subject: Request to Be Assigned Task – Fix for declareColumns Sanitization Hi Team, I’d like to take ownership of the following task: Fix: Ensure that declareColumns correctly sanitizes Haskell identifiers passed to it. If this task is still unassigned, please assign it to me. I’m ready to start working on the fix. Thanks, |
|
import qualified Data.Vector as VB -- Your existing functions: isReservedId, isVarId, isValidIdentifier... -- Fix for declareColumns
|
isLowerCase fails on GHC 9.4.8
_s.