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

Add nitpicky lint #2332

Merged
merged 7 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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