Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a CaseSensitivity type instead of using useCaseSensitiveFileNames bool #108

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

jakebailey
Copy link
Member

This feels less difficult to think about...

Comment on lines 603 to 609
func (o ComparePathsOptions) GetComparer() func(a, b string) int {
return stringutil.GetStringComparer(!o.UseCaseSensitiveFileNames)
return stringutil.GetStringComparer(!o.CaseSensitivity.IsCaseSensitive())
}

func (o ComparePathsOptions) getEqualityComparer() func(a, b string) bool {
return stringutil.GetStringEqualityComparer(!o.UseCaseSensitiveFileNames)
return stringutil.GetStringEqualityComparer(!o.CaseSensitivity.IsCaseSensitive())
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not plumb this further, but maybe case sensitivity should be in stringutil.

type CaseSensitivity uint8

const (
CaseSensitive CaseSensitivity = iota
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the default value "sensitive" which is backwards from before; will flip.

@andrewbranch
Copy link
Member

This doesn’t really feel necessary to me 🤷 I think isCaseSensitive (a better name for the same bool) sounds very understandably like a true/false file system property, personally.

@jakebailey
Copy link
Member Author

The reason I'm not a fan is that case insensitivity is the "weird" case, yet it's the one we treat as the default of false. I have a really hard time remembering which sensitivity true or false is just by reading.

@andrewbranch
Copy link
Member

I don’t think that’s right—Windows and macOS are case-insensitive, making the default of false correct for the vast majority of users.

assert.Equal(t, string(ToPath("file.ext", "/path/to", true /*useCaseSensitiveFileNames*/)), "/path/to/file.ext")
assert.Equal(t, string(ToPath("/path/to/../file.ext", "path/to", true /*useCaseSensitiveFileNames*/)), "/path/file.ext")
assert.Equal(t, string(ToPath("file.ext", "path/to", CaseInsensitive)), "path/to/file.ext")
assert.Equal(t, string(ToPath("file.ext", "/path/to", CaseSensitive)), "/path/to/file.ext")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't actually test the case sensitive case, right? since the path is all lowercase

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't seem like these are testing the case part. Probably this should have better tests.

@jakebailey
Copy link
Member Author

I don’t think that’s right—Windows and macOS are case-insensitive, making the default of false correct for the vast majority of users.

It's not about the number of users (obviously Windows/macOS outshadows Linux for dev machines, though not CI), but about how often we need to special case things in our code. If we're doing something with the bool it's almost always a case of if !useCaseSensitiveFileNames { // do complicated thing }.

@jakebailey
Copy link
Member Author

I guess it doesn't, since I didn't take it that far and reverse conditions.

I guess my point isn't super great if you can see from the variable name what it is, but mainly when I was working on the FS stuff, I was having trouble writing tests where I couldn't remember what true/false meant when passing things in, where a named value was a better argument to the call.

If this seems pointless, I can just drop it.

@jakebailey jakebailey closed this Dec 3, 2024
@DanielRosenwasser
Copy link
Member

I think the point is not so much just the naming, but more that when you pass the thing in, it's clear what you're passing in. If we have 2 boolean parameters in a row, you'll never have a hazardous refactoring. I personally think it's nice to have the safety of a distinct type.

@jakebailey jakebailey reopened this Dec 3, 2024
@jakebailey
Copy link
Member Author

I'll reopen, but it's entirely possible that this would be moot as most places which set this flag by hand are already written...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants