@@ -26,7 +26,6 @@ const Traverser = require("../shared/traverser"),
2626const SENTINEL_PATTERN =
2727 / (?: (?: C a l l | C l a s s | F u n c t i o n | M e m b e r | N e w | Y i e l d ) E x p r e s s i o n | S t a t e m e n t | D e c l a r a t i o n ) $ / u;
2828const LOOP_PATTERN = / ^ (?: D o W h i l e | F o r | W h i l e ) S t a t e m e n t $ / u; // for-in/of statements don't have `test` property.
29- const GROUP_PATTERN = / ^ (?: B i n a r y E x p r e s s i o n | C o n d i t i o n a l E x p r e s s i o n ) $ / u;
3029const SKIP_PATTERN = / ^ (?: A r r o w F u n c t i o n | C l a s s | F u n c t i o n ) E x p r e s s i o n $ / u;
3130const DYNAMIC_PATTERN = / ^ (?: C a l l | M e m b e r | N e w | T a g g e d T e m p l a t e | Y i e l d ) E x p r e s s i o n $ / u;
3231
@@ -190,7 +189,19 @@ module.exports = {
190189 url : "https://eslint.org/docs/latest/rules/no-unmodified-loop-condition" ,
191190 } ,
192191
193- schema : [ ] ,
192+ schema : [
193+ {
194+ type : "object" ,
195+ properties : {
196+ checkConditionalExpressions : {
197+ type : "boolean" ,
198+ } ,
199+ } ,
200+ additionalProperties : false ,
201+ } ,
202+ ] ,
203+
204+ defaultOptions : [ { checkConditionalExpressions : false } ] ,
194205
195206 messages : {
196207 loopConditionNotModified :
@@ -199,6 +210,7 @@ module.exports = {
199210 } ,
200211
201212 create ( context ) {
213+ const [ { checkConditionalExpressions } ] = context . options ;
202214 const sourceCode = context . sourceCode ;
203215 let groupMap = null ;
204216
@@ -305,10 +317,14 @@ module.exports = {
305317 }
306318
307319 /*
308- * If it's inside of a group, OK if either operand is modified.
309- * So stores the group this reference belongs to.
320+ * If it's inside of a group, OK if any reference in that group is
321+ * modified. So stores the group this reference belongs to.
310322 */
311- if ( GROUP_PATTERN . test ( node . type ) ) {
323+ if (
324+ node . type === "BinaryExpression" ||
325+ ( ! checkConditionalExpressions &&
326+ node . type === "ConditionalExpression" )
327+ ) {
312328 // If this expression is dynamic, no need to check.
313329 if ( hasDynamicExpressions ( node ) ) {
314330 break ;
0 commit comments