-
-
Notifications
You must be signed in to change notification settings - Fork 892
LS: warn when a Gleam file path is not a valid module name #5015
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
base: main
Are you sure you want to change the base?
Conversation
lpil
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely! Thank you very much. I've added some feedback inline, and we'll also need tests for all the new functionality.
|
Hello! If this is ready for review remember to mark is as ready so we can have a look :) |
ready |
giacomocavalieri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some changes I'm not sure why they were introduced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! I've left some notes inline, and could you add tests please 🙏
Sorry for the delay, I didn't get a notification that it was ready. Thank you
| ]; | ||
| assert_eq!( | ||
| parse_and_order(functions.as_slice(), [].as_slice()).unwrap(), | ||
| parse_and_order(functions.as_slice(), [].as_slice()).expect("Expected parse_and_order to succeed"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo these unrelated changes please
| hint: None, | ||
| }; | ||
| feedback.append_diagnostic(path.to_path_buf(), diagnostic); | ||
| Some(feedback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return a diagnostic from this function, not the entire feedback container, otherwise this function would be responsible for checking for the mistake and also for the higher level concern of how they are stored.
| s = "module".into(); | ||
| } | ||
| if !s.chars().next().map(|c| c.is_ascii_lowercase()).unwrap_or(false) { | ||
| s = format!("m{}", s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this m prefix?
| let suggestion = module_name | ||
| .split('/') | ||
| .map(|seg| { | ||
| let mut s = to_snake_case(&ecow::EcoString::from(seg)).to_string(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ecostring rather than string please
| s | ||
| }) | ||
| .collect::<Vec<_>>() | ||
| .join("/"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can suggest invalid module names, such as gleam.
|
|
||
| let mut feedback = Feedback::default(); | ||
| // Highlight the first line to ensure the diagnostic is visible in editors | ||
| let first_line_end = src.find('\n').unwrap_or(src.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this look in various editors? Could we get some screenshots 🙏
| let first_line_end = src.find('\n').unwrap_or(src.len()); | ||
| let span_end: u32 = first_line_end.max(1).try_into().unwrap_or(1); | ||
| let diagnostic = Diagnostic { | ||
| title: format!("{module_name} is not a valid name for a Gleam module"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| title: format!("{module_name} is not a valid name for a Gleam module"), | |
| title: format!("{module_name} is not a valid module name"), |
| let span_end: u32 = first_line_end.max(1).try_into().unwrap_or(1); | ||
| let diagnostic = Diagnostic { | ||
| title: format!("{module_name} is not a valid name for a Gleam module"), | ||
| text: format!("You should switch to {suggestion} instead."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include what the rules are for module names, and don't use the word "should", especially in times like this when we don't know what the best option is.
| _ => return false, | ||
| } | ||
| iter.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we use the existing code for validating module names?
fix issue #3972