-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make clippy_lints::{utils,consts} modules private, remove unused items. #3105
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/// Return the index of the character after the first camel-case component of | ||
/// `s`. | ||
pub fn camel_case_until(s: &str) -> usize { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved from |
||
let mut iter = s.char_indices(); | ||
if let Some((_, first)) = iter.next() { | ||
if !first.is_uppercase() { | ||
return 0; | ||
} | ||
} else { | ||
return 0; | ||
} | ||
let mut up = true; | ||
let mut last_i = 0; | ||
for (i, c) in iter { | ||
if up { | ||
if c.is_lowercase() { | ||
up = false; | ||
} else { | ||
return last_i; | ||
} | ||
} else if c.is_uppercase() { | ||
up = true; | ||
last_i = i; | ||
} else if !c.is_lowercase() { | ||
return i; | ||
} | ||
} | ||
if up { | ||
last_i | ||
} else { | ||
s.len() | ||
} | ||
} | ||
|
||
/// Return index of the last camel-case component of `s`. | ||
pub fn camel_case_from(s: &str) -> usize { | ||
let mut iter = s.char_indices().rev(); | ||
if let Some((_, first)) = iter.next() { | ||
if !first.is_lowercase() { | ||
return s.len(); | ||
} | ||
} else { | ||
return s.len(); | ||
} | ||
let mut down = true; | ||
let mut last_i = s.len(); | ||
for (i, c) in iter { | ||
if down { | ||
if c.is_uppercase() { | ||
down = false; | ||
last_i = i; | ||
} else if !c.is_lowercase() { | ||
return last_i; | ||
} | ||
} else if c.is_lowercase() { | ||
down = true; | ||
} else { | ||
return last_i; | ||
} | ||
} | ||
last_i | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::{camel_case_from, camel_case_until}; | ||
|
||
#[test] | ||
fn from_full() { | ||
assert_eq!(camel_case_from("AbcDef"), 0); | ||
assert_eq!(camel_case_from("Abc"), 0); | ||
} | ||
|
||
#[test] | ||
fn from_partial() { | ||
assert_eq!(camel_case_from("abcDef"), 3); | ||
assert_eq!(camel_case_from("aDbc"), 1); | ||
} | ||
|
||
#[test] | ||
fn from_not() { | ||
assert_eq!(camel_case_from("AbcDef_"), 7); | ||
assert_eq!(camel_case_from("AbcDD"), 5); | ||
} | ||
|
||
#[test] | ||
fn from_caps() { | ||
assert_eq!(camel_case_from("ABCD"), 4); | ||
} | ||
|
||
#[test] | ||
fn until_full() { | ||
assert_eq!(camel_case_until("AbcDef"), 6); | ||
assert_eq!(camel_case_until("Abc"), 3); | ||
} | ||
|
||
#[test] | ||
fn until_not() { | ||
assert_eq!(camel_case_until("abcDef"), 0); | ||
assert_eq!(camel_case_until("aDbc"), 0); | ||
} | ||
|
||
#[test] | ||
fn until_partial() { | ||
assert_eq!(camel_case_until("AbcDef_"), 6); | ||
assert_eq!(camel_case_until("CallTypeC"), 8); | ||
assert_eq!(camel_case_until("AbcDD"), 3); | ||
} | ||
|
||
#[test] | ||
fn until_caps() { | ||
assert_eq!(camel_case_until("ABCD"), 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 was used by rls:
https://github.com/rust-lang-nursery/rls/blob/3f3877613b58e1b592dde736dbf3dca48db2131a/src/build/rustc.rs#L164
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.
Does RLS use any
utils
anywhere else?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.
I don't think so.