Skip to content

Commit 8c3a5ba

Browse files
authored
fix "there exists"/"such that" not followed by a var name (#538)
1 parent 9034ed3 commit 8c3a5ba

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/lint/rules/variable-use-def.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ function walkAlgorithm(
289289
if (
290290
prev.name === 'text' &&
291291
// prettier-ignore
292-
/\b(?:for any |for some |there exists |there is |there does not exist )(\w+ )*$/.test(prev.contents)
292+
/\b(?:for any |for some |there exists |there is |there does not exist )((?!of |in )(\w+ ))*$/.test(prev.contents)
293293
) {
294294
scope.declare(varName, part);
295295
declaredThisLine.add(part);

test/lint-variable-use-def.js

+16
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ describe('variables are declared and used appropriately', () => {
115115
);
116116
});
117117

118+
it('"there exists a value in _x_ with a property" does not declare _x_"', async () => {
119+
await assertLint(
120+
positioned`
121+
<emu-alg>
122+
1. If there exists an integer in ${M}_x_ greater than 0, return *true*.
123+
1. Return *false*.
124+
</emu-alg>
125+
`,
126+
{
127+
ruleId: 'use-before-def',
128+
nodeType: 'emu-alg',
129+
message: 'could not find a preceding declaration for "x"',
130+
}
131+
);
132+
});
133+
118134
it('variables in a loop header other than the loop variable must be declared', async () => {
119135
await assertLint(
120136
positioned`

0 commit comments

Comments
 (0)