Skip to content

Commit

Permalink
Underscore is a letter (#261)
Browse files Browse the repository at this point in the history
or at least, it's a valid identifier name.
  • Loading branch information
laurentlb authored Mar 23, 2023
1 parent 766e2f2 commit 9254a57
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/renamer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ module private RenamerImpl =
)

let mutable best = -10000, ""
// For performance, consider at most 25 candidates.
for word: string in candidates |> Seq.take 25 do
// For performance, consider at most 26 candidates.
for word: string in candidates |> Seq.take 26 do
let firstLetter = word.[0]
let lastLetter = word.[word.Length - 1]
let mutable score = 0
Expand Down Expand Up @@ -353,7 +353,7 @@ module private RenamerImpl =
let computeListOfNames text =
let charCounts = Seq.countBy id text |> dict
let count c = match charCounts.TryGetValue(c) with true, res -> res | _ -> 0
let letters = ['a'..'z'] @ ['A'..'Z']
let letters = ['a'..'z'] @ ['A'..'Z'] @ ['_']
[
// First, use most frequent letters
yield! letters |> List.sortBy count |> List.rev |> List.map string
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/many_variables.expected
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"{"
"float M=L,f=K,N=J,O=I,P=H,Q=G;"
"int R=1,S=2,T=3,U=4,V=5,W=6,X=7,Y=8;"
"float Z=F,a=E,b=D,c=C,d=B,e=A;"
"int g=1,h=2,i=3,j=4,k=5,l=6,m=7,n=8;"
"float o=0.;"
"int p=1,q=2,r=3,s=4,t=5,u=6,v=7,w=8;"
"float x=0.;"
"int y=1,z=2,at=3,aa=4,ab=5,ac=6,ad=7,aA=8;"
"return Y+n+w+aA;"
"float Z=F,_=E,a=D,b=C,c=B,d=A;"
"int e=1,g=2,h=3,i=4,j=5,k=6,l=7,m=8;"
"float n=0.;"
"int o=1,p=2,q=3,r=4,s=5,t=6,u=7,v=8;"
"float w=0.;"
"int x=1,y=2,z=3,at=4,aa=5,ab=6,ac=7,aA=8;"
"return Y+m+v+aA;"
"}",

0 comments on commit 9254a57

Please sign in to comment.