From c0528ca2381b82ae1cfbe04e1dfb09e427a8288d Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Mon, 3 Jul 2023 13:37:04 -0700 Subject: [PATCH] fix "there exists"/"such that" not followed by a var name --- src/lint/rules/variable-use-def.ts | 2 +- test/lint-variable-use-def.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lint/rules/variable-use-def.ts b/src/lint/rules/variable-use-def.ts index 77c4d7af..b2addcc9 100644 --- a/src/lint/rules/variable-use-def.ts +++ b/src/lint/rules/variable-use-def.ts @@ -289,7 +289,7 @@ function walkAlgorithm( if ( prev.name === 'text' && // prettier-ignore - /\b(?:for any |for some |there exists |there is |there does not exist )(\w+ )*$/.test(prev.contents) + /\b(?:for any |for some |there exists |there is |there does not exist )((?!of |in )(\w+ ))*$/.test(prev.contents) ) { scope.declare(varName, part); declaredThisLine.add(part); diff --git a/test/lint-variable-use-def.js b/test/lint-variable-use-def.js index 16f8b0c2..18007e90 100644 --- a/test/lint-variable-use-def.js +++ b/test/lint-variable-use-def.js @@ -115,6 +115,22 @@ describe('variables are declared and used appropriately', () => { ); }); + it('"there exists a value in _x_ with a property" does not declare _x_"', async () => { + await assertLint( + positioned` + + 1. If there exists an integer in ${M}_x_ greater than 0, return *true*. + 1. Return *false*. + + `, + { + ruleId: 'use-before-def', + nodeType: 'emu-alg', + message: 'could not find a preceding declaration for "x"', + } + ); + }); + it('variables in a loop header other than the loop variable must be declared', async () => { await assertLint( positioned`