Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix "there exists"/"such that" not followed by a var name #538

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lint/rules/variable-use-def.ts
Original file line number Diff line number Diff line change
@@ -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);
16 changes: 16 additions & 0 deletions test/lint-variable-use-def.js
Original file line number Diff line number Diff line change
@@ -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`
<emu-alg>
1. If there exists an integer in ${M}_x_ greater than 0, return *true*.
1. Return *false*.
</emu-alg>
`,
{
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`