mirror of
https://github.com/oxalica/nil.git
synced 2024-11-22 02:55:39 +03:00
Ignore identifiers starting with _
from liveness check
Partially fixes #55 Closes #109
This commit is contained in:
parent
dbf49b3aab
commit
61caccdde0
@ -17,6 +17,10 @@
|
||||
//! - Unused `with` expressions.
|
||||
//! - Unnecessary `rec` attrsets.
|
||||
//! - Unused parameters of a package.
|
||||
//!
|
||||
//! Notes:
|
||||
//! - All identifiers starting with `_` are skipped from warnings. This also includes Nix internals
|
||||
//! starting with `__`, eg. `__findFile` <https://github.com/oxalica/nil/pull/109>.
|
||||
use super::{BindingValue, DefDatabase, Expr, ExprId, NameId, ResolveResult};
|
||||
use crate::{Diagnostic, DiagnosticKind, FileId, ModuleKind};
|
||||
use la_arena::ArenaMap;
|
||||
@ -25,6 +29,10 @@ use std::sync::Arc;
|
||||
use syntax::ast::{self, AstNode};
|
||||
use syntax::TextRange;
|
||||
|
||||
fn should_ignore(name: &str) -> bool {
|
||||
name.starts_with('_')
|
||||
}
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Eq)]
|
||||
pub struct LivenessCheckResult {
|
||||
names: Box<[NameId]>,
|
||||
@ -207,6 +215,8 @@ pub(crate) fn liveness_check_query(
|
||||
}
|
||||
}
|
||||
|
||||
unused_defs.retain(|name| !should_ignore(&module[*name].text));
|
||||
|
||||
Arc::new(LivenessCheckResult {
|
||||
names: unused_defs.into(),
|
||||
withs: unused_withs.into(),
|
||||
@ -353,4 +363,10 @@ mod tests {
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn underscore_names() {
|
||||
check("x: _y: x");
|
||||
check("let __findFile = 42; in <nixpkgs>");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user