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

JS-261 Update easy deps #4825

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 23 additions & 3 deletions packages/jsts/src/rules/S5860/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
import { AST, Rule, Scope } from 'eslint';
import * as estree from 'estree';
import * as regexpp from '@eslint-community/regexpp';
import { Backreference, CapturingGroup, RegExpLiteral } from '@eslint-community/regexpp/ast';
import {
AmbiguousBackreference,
Backreference,
CapturingGroup,
RegExpLiteral,
} from '@eslint-community/regexpp/ast';
import {
generateMeta,
getLhsVariable,
Expand Down Expand Up @@ -305,11 +310,22 @@ interface GroupKnowledge {
index: number;
}

function isAmbiguousGroup(reference: Backreference): reference is AmbiguousBackreference {
return reference.ambiguous;
}
Comment on lines +313 to +315
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this as, just checking in the line below for: reference.ambigous ? "treat as ambiguous" : "treat as unambiguous" did not pass jest tests.... Looked a bit with @ericmorand-sonarsource , but failed to figure it out.


function makeRegexKnowledge(node: estree.Node, regexp: RegExpLiteral): RegexKnowledge {
const capturingGroups: CapturingGroup[] = [];
const backreferences: Backreference[] = [];
regexpp.visitRegExpAST(regexp, {
onBackreferenceEnter: reference => reference.resolved.name && backreferences.push(reference),
onBackreferenceEnter: reference => {
const shouldSaveReference = isAmbiguousGroup(reference)
? reference.resolved.filter(capturingGroup => capturingGroup.name).length > 0
: reference.resolved.name !== null;
if (shouldSaveReference) {
backreferences.push(reference);
}
},
Comment on lines +321 to +328
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating this logic, as the typing changed in version 4.11.0 - eslint-community/regexpp@fb20f68

onCapturingGroupEnter: group => capturingGroups.push(group),
});
const groups: GroupKnowledge[] = [];
Expand All @@ -326,7 +342,11 @@ function makeGroupKnowledge(
index: number,
): GroupKnowledge {
const name = node.name!;
const used = backreferences.some(backreference => backreference.resolved === node);
const used = backreferences.some(backreference =>
backreference.ambiguous
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use same helper here?

? backreference.resolved.includes(node)
: backreference.resolved === node,
);
return { node, name, used, index };
}

Expand Down
Loading