forked from extern/nushell
Move to using clippy (#1142)
* Clippy fixes * Finish converting to use clippy * fix warnings in new master * fix windows * fix windows Co-authored-by: Artem Vorotnikov <artem@vorotnikov.me>
This commit is contained in:
@ -30,7 +30,7 @@ impl PrettyDebugWithSource for CallNode {
|
||||
|
||||
impl CallNode {
|
||||
pub fn new(head: Box<TokenNode>, children: Vec<TokenNode>) -> CallNode {
|
||||
if children.len() == 0 {
|
||||
if children.is_empty() {
|
||||
CallNode {
|
||||
head,
|
||||
children: None,
|
||||
|
@ -26,7 +26,7 @@ impl language_reporting::ReportingFiles for Files {
|
||||
}
|
||||
|
||||
fn file_name(&self, _file: Self::FileId) -> FileName {
|
||||
FileName::Verbatim(format!("shell"))
|
||||
FileName::Verbatim("shell".to_string())
|
||||
}
|
||||
|
||||
fn byte_index(&self, _file: Self::FileId, _line: usize, _column: usize) -> Option<usize> {
|
||||
@ -143,9 +143,7 @@ impl language_reporting::ReportingFiles for Files {
|
||||
fn source(&self, span: Self::Span) -> Option<String> {
|
||||
trace!("source(tag={:?}) snippet={:?}", span, self.snippet);
|
||||
|
||||
if span.start() > span.end() {
|
||||
return None;
|
||||
} else if span.end() > self.snippet.len() {
|
||||
if span.start() > span.end() || span.end() > self.snippet.len() {
|
||||
return None;
|
||||
}
|
||||
Some(span.slice(&self.snippet).to_string())
|
||||
|
@ -22,12 +22,12 @@ impl PrettyDebug for CompareOperator {
|
||||
}
|
||||
|
||||
impl CompareOperator {
|
||||
pub fn print(&self) -> String {
|
||||
pub fn print(self) -> String {
|
||||
self.as_str().to_string()
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
match *self {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
CompareOperator::Equal => "==",
|
||||
CompareOperator::NotEqual => "!=",
|
||||
CompareOperator::LessThan => "<",
|
||||
@ -76,12 +76,12 @@ impl PrettyDebug for EvaluationOperator {
|
||||
}
|
||||
|
||||
impl EvaluationOperator {
|
||||
pub fn print(&self) -> String {
|
||||
pub fn print(self) -> String {
|
||||
self.as_str().to_string()
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
match *self {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
EvaluationOperator::Dot => ".",
|
||||
EvaluationOperator::DotDot => "..",
|
||||
}
|
||||
|
@ -233,13 +233,9 @@ pub fn raw_number(input: NomSpan) -> IResult<NomSpan, RawNumber> {
|
||||
|
||||
let dotdot_result = dotdot(input);
|
||||
|
||||
match dotdot_result {
|
||||
if let Ok((dotdot_input, _)) = dotdot_result {
|
||||
// If we see a `..` immediately after an integer, it's a range, not a decimal
|
||||
Ok((dotdot_input, _)) => {
|
||||
return Ok((input, RawNumber::int(Span::new(start, input.offset))))
|
||||
}
|
||||
|
||||
Err(_) => {}
|
||||
return Ok((input, RawNumber::int(Span::new(start, input.offset))));
|
||||
}
|
||||
|
||||
let dot: IResult<NomSpan, NomSpan, (NomSpan, nom::error::ErrorKind)> = tag(".")(input);
|
||||
@ -434,10 +430,8 @@ enum SawSpecial {
|
||||
fn start_file_char(input: NomSpan) -> IResult<NomSpan, BitFlags<SawSpecial>> {
|
||||
let path_sep_result = special_file_char(input);
|
||||
|
||||
match path_sep_result {
|
||||
Ok((input, special)) => return Ok((input, special)),
|
||||
|
||||
Err(_) => {}
|
||||
if let Ok((input, special)) = path_sep_result {
|
||||
return Ok((input, special));
|
||||
}
|
||||
|
||||
start_filename(input).map(|(input, output)| (input, BitFlags::empty()))
|
||||
@ -447,9 +441,8 @@ fn start_file_char(input: NomSpan) -> IResult<NomSpan, BitFlags<SawSpecial>> {
|
||||
fn continue_file_char(input: NomSpan) -> IResult<NomSpan, BitFlags<SawSpecial>> {
|
||||
let path_sep_result = special_file_char(input);
|
||||
|
||||
match path_sep_result {
|
||||
Ok((input, special)) => return Ok((input, special)),
|
||||
Err(_) => {}
|
||||
if let Ok((input, special)) = path_sep_result {
|
||||
return Ok((input, special));
|
||||
}
|
||||
|
||||
matches(is_file_char)(input).map(|(input, _)| (input, BitFlags::empty()))
|
||||
@ -457,9 +450,8 @@ fn continue_file_char(input: NomSpan) -> IResult<NomSpan, BitFlags<SawSpecial>>
|
||||
|
||||
#[tracable_parser]
|
||||
fn special_file_char(input: NomSpan) -> IResult<NomSpan, BitFlags<SawSpecial>> {
|
||||
match matches(is_path_separator)(input) {
|
||||
Ok((input, _)) => return Ok((input, BitFlags::empty() | SawSpecial::PathSeparator)),
|
||||
Err(_) => {}
|
||||
if let Ok((input, _)) = matches(is_path_separator)(input) {
|
||||
return Ok((input, BitFlags::empty() | SawSpecial::PathSeparator));
|
||||
}
|
||||
|
||||
let (input, _) = matches(is_glob_specific_char)(input)?;
|
||||
@ -667,9 +659,13 @@ pub fn spaced_token_list(input: NomSpan) -> IResult<NomSpan, Spanned<Vec<TokenNo
|
||||
|
||||
let mut out = vec![];
|
||||
|
||||
pre_ws.map(|pre_ws| out.extend(pre_ws));
|
||||
if let Some(pre_ws) = pre_ws {
|
||||
out.extend(pre_ws)
|
||||
}
|
||||
out.extend(items.item);
|
||||
post_ws.map(|post_ws| out.extend(post_ws));
|
||||
if let Some(post_ws) = post_ws {
|
||||
out.extend(post_ws)
|
||||
}
|
||||
|
||||
Ok((input, out.spanned(Span::new(start, end))))
|
||||
}
|
||||
@ -917,7 +913,7 @@ fn parse_int<T>(frag: &str, neg: Option<T>) -> i64 {
|
||||
|
||||
match neg {
|
||||
None => int,
|
||||
Some(_) => int * -1,
|
||||
Some(_) => -int,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1104,42 +1100,63 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_operator() {
|
||||
fn test_gt_operator() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
">" -> b::token_list(vec![b::op(">")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_gte_operator() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
">=" -> b::token_list(vec![b::op(">=")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lt_operator() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"<" -> b::token_list(vec![b::op("<")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lte_operator() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"<=" -> b::token_list(vec![b::op("<=")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_eq_operator() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"==" -> b::token_list(vec![b::op("==")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ne_operator() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"!=" -> b::token_list(vec![b::op("!=")])
|
||||
<nodes>
|
||||
"!=" -> b::token_list(vec![b::op("!=")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sim_operator() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"=~" -> b::token_list(vec![b::op("=~")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nsim_operator() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"!~" -> b::token_list(vec![b::op("!~")])
|
||||
@ -1396,37 +1413,58 @@ mod tests {
|
||||
<nodes>
|
||||
"git add ." -> b::token_list(vec![b::bare("git"), b::sp(), b::bare("add"), b::sp(), b::bare(".")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_smoke_single_command_open() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"open Cargo.toml" -> b::token_list(vec![b::bare("open"), b::sp(), b::bare("Cargo"), b::dot(), b::bare("toml")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_smoke_single_command_select() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"select package.version" -> b::token_list(vec![b::bare("select"), b::sp(), b::bare("package"), b::dot(), b::bare("version")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_smoke_single_command_it() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"echo $it" -> b::token_list(vec![b::bare("echo"), b::sp(), b::var("it")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_smoke_single_command_open_raw() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"open Cargo.toml --raw" -> b::token_list(vec![b::bare("open"), b::sp(), b::bare("Cargo"), b::dot(), b::bare("toml"), b::sp(), b::flag("raw")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_smoke_single_command_open_r() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"open Cargo.toml -r" -> b::token_list(vec![b::bare("open"), b::sp(), b::bare("Cargo"), b::dot(), b::bare("toml"), b::sp(), b::shorthand("r")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_smoke_single_command_config() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"config --set tabs 2" -> b::token_list(vec![b::bare("config"), b::sp(), b::flag("set"), b::sp(), b::bare("tabs"), b::sp(), b::int(2)])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_smoke_single_command_inc() {
|
||||
equal_tokens! {
|
||||
<nodes>
|
||||
"inc --patch package.version" -> b::token_list(
|
||||
|
@ -349,7 +349,7 @@ pub enum Delimiter {
|
||||
}
|
||||
|
||||
impl Delimiter {
|
||||
pub(crate) fn open(&self) -> &'static str {
|
||||
pub(crate) fn open(self) -> &'static str {
|
||||
match self {
|
||||
Delimiter::Paren => "(",
|
||||
Delimiter::Brace => "{",
|
||||
@ -357,7 +357,7 @@ impl Delimiter {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn close(&self) -> &'static str {
|
||||
pub(crate) fn close(self) -> &'static str {
|
||||
match self {
|
||||
Delimiter::Paren => ")",
|
||||
Delimiter::Brace => "}",
|
||||
|
@ -9,17 +9,15 @@ use bigdecimal::BigDecimal;
|
||||
use nu_source::{Span, Spanned, SpannedItem};
|
||||
use num_bigint::BigInt;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TokenTreeBuilder {
|
||||
pos: usize,
|
||||
output: String,
|
||||
}
|
||||
|
||||
impl TokenTreeBuilder {
|
||||
pub fn new() -> TokenTreeBuilder {
|
||||
TokenTreeBuilder {
|
||||
pos: 0,
|
||||
output: String::new(),
|
||||
}
|
||||
pub fn new() -> Self {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,7 +317,7 @@ impl TokenTreeBuilder {
|
||||
}
|
||||
|
||||
pub fn spanned_call(input: Vec<TokenNode>, span: impl Into<Span>) -> Spanned<CallNode> {
|
||||
if input.len() == 0 {
|
||||
if input.is_empty() {
|
||||
panic!("BUG: spanned call (TODO)")
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,8 @@ fn convert_number_to_u64(number: &Number) -> u64 {
|
||||
}
|
||||
|
||||
impl Unit {
|
||||
pub fn as_str(&self) -> &str {
|
||||
match *self {
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Unit::Byte => "B",
|
||||
Unit::Kilobyte => "KB",
|
||||
Unit::Megabyte => "MB",
|
||||
@ -58,10 +58,10 @@ impl Unit {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute(&self, size: &Number) -> UntaggedValue {
|
||||
pub fn compute(self, size: &Number) -> UntaggedValue {
|
||||
let size = size.clone();
|
||||
|
||||
match &self {
|
||||
match self {
|
||||
Unit::Byte => number(size),
|
||||
Unit::Kilobyte => number(size * 1024),
|
||||
Unit::Megabyte => number(size * 1024 * 1024),
|
||||
|
Reference in New Issue
Block a user