@@ -58,15 +58,11 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
5858 continue ;
5959 }
6060
61- let fix = if let Some ( constraint_token) =
62- drop_constraint. constraint_token ( )
63- {
61+ let fix = drop_constraint. constraint_token ( ) . map ( |constraint_token| {
6462 let at = constraint_token. text_range ( ) . end ( ) ;
6563 let edit = Edit :: insert ( " if exists" , at) ;
66- Some ( Fix :: new ( "Insert `if exists`" , vec ! [ edit] ) )
67- } else {
68- None
69- } ;
64+ Fix :: new ( "Insert `if exists`" , vec ! [ edit] )
65+ } ) ;
7066
7167 ( ActionErrorMessage :: IfExists , fix)
7268 }
@@ -75,13 +71,11 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
7571 continue ;
7672 }
7773
78- let fix = if let Some ( column_token ) = add_column. column_token ( ) {
74+ let fix = add_column. column_token ( ) . map ( |column_token| {
7975 let at = column_token. text_range ( ) . end ( ) ;
8076 let edit = Edit :: insert ( " if not exists" , at) ;
81- Some ( Fix :: new ( "Insert `if not exists`" , vec ! [ edit] ) )
82- } else {
83- None
84- } ;
77+ Fix :: new ( "Insert `if not exists`" , vec ! [ edit] )
78+ } ) ;
8579 ( ActionErrorMessage :: IfNotExists , fix)
8680 }
8781 ast:: AlterTableAction :: ValidateConstraint ( validate_constraint) => {
@@ -113,13 +107,11 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
113107 continue ;
114108 }
115109
116- let fix = if let Some ( column_token ) = drop_column. column_token ( ) {
110+ let fix = drop_column. column_token ( ) . map ( |column_token| {
117111 let at = column_token. text_range ( ) . end ( ) ;
118112 let edit = Edit :: insert ( " if exists" , at) ;
119- Some ( Fix :: new ( "Insert `if exists`" , vec ! [ edit] ) )
120- } else {
121- None
122- } ;
113+ Fix :: new ( "Insert `if exists`" , vec ! [ edit] )
114+ } ) ;
123115 ( ActionErrorMessage :: IfExists , fix)
124116 }
125117 _ => ( ActionErrorMessage :: None , None ) ,
@@ -152,13 +144,11 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
152144 && create_index. name ( ) . is_some ( )
153145 && ( create_index. concurrently_token ( ) . is_some ( ) || !inside_transaction) =>
154146 {
155- let fix = if let Some ( name ) = create_index. name ( ) {
147+ let fix = create_index. name ( ) . map ( |name| {
156148 let at = name. syntax ( ) . text_range ( ) . start ( ) ;
157149 let edit = Edit :: insert ( "if not exists " , at) ;
158- Some ( Fix :: new ( "Insert `if not exists`" , vec ! [ edit] ) )
159- } else {
160- None
161- } ;
150+ Fix :: new ( "Insert `if not exists`" , vec ! [ edit] )
151+ } ) ;
162152 ctx. report ( Violation :: for_node (
163153 Rule :: PreferRobustStmts ,
164154 "Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through." . into ( ) ,
@@ -168,13 +158,11 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
168158 ast:: Stmt :: CreateTable ( create_table)
169159 if create_table. if_not_exists ( ) . is_none ( ) && !inside_transaction =>
170160 {
171- let fix = if let Some ( table_token ) = create_table. table_token ( ) {
161+ let fix = create_table. table_token ( ) . map ( |table_token| {
172162 let at = table_token. text_range ( ) . end ( ) ;
173163 let edit = Edit :: insert ( " if not exists" , at) ;
174- Some ( Fix :: new ( "Insert `if not exists`" , vec ! [ edit] ) )
175- } else {
176- None
177- } ;
164+ Fix :: new ( "Insert `if not exists`" , vec ! [ edit] )
165+ } ) ;
178166
179167 ctx. report ( Violation :: for_node (
180168 Rule :: PreferRobustStmts ,
@@ -185,13 +173,11 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
185173 ast:: Stmt :: DropIndex ( drop_index)
186174 if drop_index. if_exists ( ) . is_none ( ) && !inside_transaction =>
187175 {
188- let fix = if let Some ( first_index ) = drop_index. paths ( ) . next ( ) {
176+ let fix = drop_index. paths ( ) . next ( ) . map ( |first_index| {
189177 let at = first_index. syntax ( ) . text_range ( ) . start ( ) ;
190178 let edit = Edit :: insert ( "if exists " , at) ;
191- Some ( Fix :: new ( "Insert `if exists`" , vec ! [ edit] ) )
192- } else {
193- None
194- } ;
179+ Fix :: new ( "Insert `if exists`" , vec ! [ edit] )
180+ } ) ;
195181
196182 ctx. report ( Violation :: for_node (
197183 Rule :: PreferRobustStmts ,
@@ -202,13 +188,11 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
202188 ast:: Stmt :: DropTable ( drop_table)
203189 if drop_table. if_exists ( ) . is_none ( ) && !inside_transaction =>
204190 {
205- let fix = if let Some ( table_token ) = drop_table. table_token ( ) {
191+ let fix = drop_table. table_token ( ) . map ( |table_token| {
206192 let at = table_token. text_range ( ) . end ( ) ;
207193 let edit = Edit :: insert ( " if exists" , at) ;
208- Some ( Fix :: new ( "Insert `if exists`" , vec ! [ edit] ) )
209- } else {
210- None
211- } ;
194+ Fix :: new ( "Insert `if exists`" , vec ! [ edit] )
195+ } ) ;
212196 ctx. report ( Violation :: for_node (
213197 Rule :: PreferRobustStmts ,
214198 "Missing `IF EXISTS`, the migration can't be rerun if it fails part way through." . into ( ) ,
@@ -218,13 +202,11 @@ pub(crate) fn prefer_robust_stmts(ctx: &mut Linter, parse: &Parse<SourceFile>) {
218202 ast:: Stmt :: DropType ( drop_type)
219203 if drop_type. if_exists ( ) . is_none ( ) && !inside_transaction =>
220204 {
221- let fix = if let Some ( type_token ) = drop_type. type_token ( ) {
205+ let fix = drop_type. type_token ( ) . map ( |type_token| {
222206 let at = type_token. text_range ( ) . end ( ) ;
223207 let edit = Edit :: insert ( " if exists" , at) ;
224- Some ( Fix :: new ( "Insert `if exists`" , vec ! [ edit] ) )
225- } else {
226- None
227- } ;
208+ Fix :: new ( "Insert `if exists`" , vec ! [ edit] )
209+ } ) ;
228210
229211 ctx. report ( Violation :: for_node (
230212 Rule :: PreferRobustStmts ,
0 commit comments