diff --git a/src/lint/rules/variable-use-def.ts b/src/lint/rules/variable-use-def.ts
index 8633a985..a5fc0a9f 100644
--- a/src/lint/rules/variable-use-def.ts
+++ b/src/lint/rules/variable-use-def.ts
@@ -143,9 +143,10 @@ export function checkVariableUsage(
preceding.querySelector('emu-alg') == null &&
preceding.textContent != null
) {
+ const isParameter = preceding.nodeName === 'H1';
// `__` is for _x__y_, which has textContent `_x__y_`
for (const name of preceding.textContent.matchAll(/(?<=\b|_)_([a-zA-Z0-9]+)_(?=\b|_)/g)) {
- scope.declare(name[1], null, undefined, true);
+ scope.declare(name[1], null, isParameter ? 'parameter' : undefined, !isParameter);
}
}
preceding = previousOrParent(preceding, parentClause);
diff --git a/test/lint-variable-use-def.ts b/test/lint-variable-use-def.ts
index fcbec155..cf539786 100644
--- a/test/lint-variable-use-def.ts
+++ b/test/lint-variable-use-def.ts
@@ -699,6 +699,54 @@ describe('variables cannot be redeclared', () => {
`,
);
});
+
+ it('parameters cannot be redeclared', async () => {
+ await assertLint(
+ positioned`
+
+
+ Example (
+ _x_: ~foo~,
+ ): ~foo~ or ~bar~
+
+
+
+ 1. Let ${M}_x_ be ~bar~.
+ 1. Return _x_.
+
+
+ `,
+ {
+ ruleId: 're-declaration',
+ nodeType: 'emu-alg',
+ message: '"x" is already declared',
+ },
+ );
+ });
+
+ it('optional parameters cannot be redeclared', async () => {
+ await assertLint(
+ positioned`
+
+
+ Example (
+ optional _x_: ~foo~,
+ ): ~foo~ or ~bar~
+
+
+
+ 1. If _x_ is not present, let ${M}_x_ be ~bar~.
+ 1. Return _x_.
+
+
+ `,
+ {
+ ruleId: 're-declaration',
+ nodeType: 'emu-alg',
+ message: '"x" is already declared',
+ },
+ );
+ });
});
describe('closures must not capture reassigned variables', () => {