@@ -13,7 +13,9 @@ use crate::sql_lint::models::{
1313
1414use crate :: sql_lint:: _helpers:: additional:: collect_additional_facts;
1515use crate :: sql_lint:: _helpers:: inline_relations:: collect_inline_query_relation_spans;
16- use crate :: sql_lint:: _helpers:: join_predicates:: cross_join_diagnostics;
16+ use crate :: sql_lint:: _helpers:: join_predicates:: {
17+ condition_tokens, cross_join_diagnostics, trivial_on_condition,
18+ } ;
1719use crate :: sql_lint:: _helpers:: parsing:: parse;
1820use crate :: sql_lint:: _helpers:: terminal_shape:: collect_terminal_shape_facts;
1921
@@ -213,7 +215,6 @@ const INLINE_QUERY_RELATION: LintRuleMetadata = LintRuleMetadata {
213215 message : "Inline query relation obscures data flow" ,
214216 remediation : "Extract the derived relation into a named top-level CTE; use explicit LATERAL only when the relation must remain correlated." ,
215217} ;
216- const TRIVIAL_EQUALITY_TOKEN_COUNT : usize = 3 ;
217218const JOIN_EXPRESSION : LintRuleMetadata = LintRuleMetadata {
218219 code : "SQLCLEAN040" ,
219220 message : "JOIN ON contains a computed expression" ,
@@ -901,8 +902,10 @@ fn collect_from_and_join_facts(tokens: &[Token], direct: &[usize]) -> (Vec<Span>
901902 . iter ( )
902903 . any ( |& candidate| tokens[ candidate] . token_type == TokenType :: Using ) ;
903904 if !has_using
904- && on_position
905- . is_none_or ( |offset| trivial_on_condition ( tokens, & condition[ offset + 1 ..] ) )
905+ && on_position. is_none_or ( |offset| {
906+ let end = direct. get ( condition_end) . copied ( ) . unwrap_or ( tokens. len ( ) ) ;
907+ trivial_on_condition ( tokens, & condition_tokens ( tokens, condition[ offset] , end) )
908+ } )
906909 {
907910 missing_conditions. push ( tokens[ index] . span ) ;
908911 }
@@ -943,24 +946,6 @@ fn is_conditionless_join(tokens: &[Token], direct: &[usize], join_position: usiz
943946 } )
944947}
945948
946- fn trivial_on_condition ( tokens : & [ Token ] , condition : & [ usize ] ) -> bool {
947- let significant: Vec < & Token > = condition
948- . iter ( )
949- . map ( |& index| & tokens[ index] )
950- . filter ( |token| !matches ! ( token. token_type, TokenType :: LParen | TokenType :: RParen ) )
951- . collect ( ) ;
952- significant. is_empty ( )
953- || significant. len ( ) == 1 && significant[ 0 ] . token_type == TokenType :: True
954- || significant. len ( ) == TRIVIAL_EQUALITY_TOKEN_COUNT
955- && significant[ 1 ] . token_type == TokenType :: Eq
956- && matches ! (
957- significant[ 0 ] . token_type,
958- TokenType :: Number | TokenType :: String | TokenType :: True | TokenType :: False
959- )
960- && significant[ 0 ] . token_type == significant[ 2 ] . token_type
961- && significant[ 0 ] . text == significant[ 2 ] . text
962- }
963-
964949fn collect_set_operation_facts ( tokens : & [ Token ] , depths : & [ usize ] ) -> Vec < Span > {
965950 let mut spans: Vec < Span > = Vec :: new ( ) ;
966951 for ( index, token) in tokens. iter ( ) . enumerate ( ) {
0 commit comments