rrubocop 0.8.15

10x faster RuboCop drop-in. Same output format and configs, without maintaining RuboCop gems.
//! GraphQL/UnnecessaryFieldCamelize — camelize unused when name has no underscore.

use tree_sitter::Node;

use super::helpers::{field_name, has_kwarg, is_field_call, CALL_KINDS, DEPT_INCLUDE};
use crate::cop::{Cop, CopConfig};
use crate::diagnostic::Diagnostic;
use crate::parse::source::SourceFile;

pub struct UnnecessaryFieldCamelize;

impl Cop for UnnecessaryFieldCamelize {
    fn name(&self) -> &'static str {
        "GraphQL/UnnecessaryFieldCamelize"
    }

    fn default_include(&self) -> &'static [&'static str] {
        DEPT_INCLUDE
    }

    fn interested_node_kinds(&self) -> &'static [&'static str] {
        CALL_KINDS
    }

    fn check_node(
        &self,
        source: &SourceFile,
        node: Node<'_>,
        _config: &CopConfig,
        diagnostics: &mut Vec<Diagnostic>,
        _corrections: Option<&mut Vec<crate::correction::Correction>>,
    ) {
        if !is_field_call(source, node) {
            return;
        }
        let Some(name) = field_name(source, node) else {
            return;
        };
        if name.split('_').count() >= 2 {
            return;
        }
        if !has_kwarg(source, node, "camelize") {
            return;
        }
        let (line, col) = source.offset_to_line_col(node.start_byte());
        diagnostics.push(self.diagnostic(
            source,
            line,
            col,
            "Unnecessary field camelize".into(),
        ));
    }
}