Skip to content

Commit

Permalink
Add nitpicky lint (#2332)
Browse files Browse the repository at this point in the history
### What
https://github.com/rerun-io/rerun/blob/main/CODE_STYLE.md#misc

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)

<!-- This line will get updated when the PR build summary job finishes.
-->
PR Build Summary: https://build.rerun.io/pr/2332

<!-- pr-link-docs:start -->
Docs preview: https://rerun.io/preview/42af6f4/docs
Examples preview: https://rerun.io/preview/42af6f4/examples
<!-- pr-link-docs:end -->

---------

Co-authored-by: Andreas Reich <[email protected]>
  • Loading branch information
emilk and Wumpf authored Jun 9, 2023
1 parent a18b39d commit 0c805e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::{DynSpaceViewClass, SpaceViewClassName};

#[derive(Debug, thiserror::Error)]
pub enum SpaceViewClassRegistryError {
#[error("Space view with typename \"{0}\" was already registered.")]
DuplicateTypeName(SpaceViewClassName),
#[error("Space view with class name {0:?} was already registered.")]
DuplicateClassName(SpaceViewClassName),
}

/// Registry of all known space view types.
Expand All @@ -28,7 +28,7 @@ impl SpaceViewClassRegistry {
.insert(type_name, Box::new(space_view_type))
.is_some()
{
return Err(SpaceViewClassRegistryError::DuplicateTypeName(type_name));
return Err(SpaceViewClassRegistryError::DuplicateClassName(type_name));
}

Ok(())
Expand Down
8 changes: 8 additions & 0 deletions scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
wasm_caps = re.compile(r"\bWASM\b")
nb_prefix = re.compile(r"nb_")
else_return = re.compile(r"else\s*{\s*return;?\s*};")
explicit_quotes = re.compile(r'[^(]\\"\{\w*\}\\"') # looks for: \"{foo}\"


def lint_line(line: str) -> Optional[str]:
Expand Down Expand Up @@ -77,6 +78,9 @@ def lint_line(line: str) -> Optional[str]:
if nb_prefix.search(line):
return "Don't use nb_things - use num_things or thing_count instead"

if explicit_quotes.search(line):
return "Prefer using {:?} - it will also escape newlines etc"

return None


Expand All @@ -103,6 +107,7 @@ def test_lint_line() -> None:
"num_instances",
"instances_count",
"let Some(foo) = bar else { return; };",
"{foo:?}",
]

should_error = [
Expand All @@ -124,6 +129,9 @@ def test_lint_line() -> None:
"let Some(foo) = bar else {return;};",
"let Some(foo) = bar else {return};",
"let Some(foo) = bar else { return };",
r'println!("Problem: \"{}\"", string)',
r'println!("Problem: \"{0}\"")',
r'println!("Problem: \"{string}\"")',
]

for line in should_pass:
Expand Down

1 comment on commit 0c805e4

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Rust Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.25.

Benchmark suite Current: 0c805e4 Previous: a18b39d Ratio
mono_points_arrow_batched/generate_message_bundles 32116383 ns/iter (± 1364573) 25585237 ns/iter (± 1451545) 1.26
mono_points_arrow_batched/generate_messages 8915170 ns/iter (± 945679) 5257652 ns/iter (± 134707) 1.70
mono_points_arrow_batched/encode_total 50261949 ns/iter (± 4377353) 34130241 ns/iter (± 1490563) 1.47
mono_points_arrow_batched/decode_message_bundles 14217053 ns/iter (± 1125191) 11119825 ns/iter (± 1226123) 1.28
mono_points_arrow_batched/decode_total 15071563 ns/iter (± 966415) 10253392 ns/iter (± 304182) 1.47
arrow_mono_points/insert 3589446950 ns/iter (± 181916748) 2843463019 ns/iter (± 12704664) 1.26
arrow_mono_points/query 2564649 ns/iter (± 406888) 1352801 ns/iter (± 17816) 1.90

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.