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

refactor(linter): replace ast "compare by hash" to "compare by content" #5600

Closed
Boshen opened this issue Sep 8, 2024 · 1 comment · Fixed by #5602 or #5648
Closed

refactor(linter): replace ast "compare by hash" to "compare by content" #5600

Boshen opened this issue Sep 8, 2024 · 1 comment · Fixed by #5602 or #5648
Assignees
Labels
A-linter Area - Linter C-enhancement Category - New feature or request

Comments

@Boshen
Copy link
Member

Boshen commented Sep 8, 2024

pub fn calculate_hash<T: ContentHash>(t: &T) -> u64 {
let mut hasher = FxHasher::default();
t.content_hash(&mut hasher);
hasher.finish()
}

Can now be replaced by ContentEq https://docs.rs/oxc_span/0.27.0/oxc_span/cmp/trait.ContentEq.html

@Boshen Boshen added C-enhancement Category - New feature or request good first issue Experience Level - Good for newcomers A-linter Area - Linter labels Sep 8, 2024
@Boshen Boshen reopened this Sep 8, 2024
@Boshen
Copy link
Member Author

Boshen commented Sep 8, 2024

Remaining case:

let mut map = FxHashMap::default();
map.reserve(ss.cases.len());
for case in &ss.cases {
if let Some(test) = case.test.as_ref() {
let hash = calculate_hash(test.get_inner_expression());
if let Some(prev_span) = map.insert(hash, test.span()) {
ctx.diagnostic(no_duplicate_case_diagnostic(prev_span, test.span()));
}
}
}

@Boshen Boshen self-assigned this Sep 8, 2024
@Boshen Boshen removed the good first issue Experience Level - Good for newcomers label Sep 8, 2024
Boshen added a commit that referenced this issue Sep 9, 2024
Boshen added a commit that referenced this issue Sep 9, 2024
Boshen added a commit that referenced this issue Sep 9, 2024
@Boshen Boshen closed this as completed Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-enhancement Category - New feature or request
Projects
None yet
1 participant