Skip to content

Commit

Permalink
add test when location is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiez committed Oct 31, 2023
1 parent 2645d97 commit e8c3027
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
36 changes: 36 additions & 0 deletions packages/jsts/src/rules/S5843/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,42 @@ ruleTesterThreshold0.run(
],
options: [0],
},
{
code: `RegExp('\\r?');`,
errors: [
{
message: JSON.stringify({
message: `Simplify this regular expression to reduce its complexity from 1 to the 0 allowed.`,
cost: 1,
secondaryLocations: [], // Secondary location removed when invalid (start===end)
}),
line: 1,
endLine: 1,
column: 8,
endColumn: 13,
},
],
options: [0],
},
{
code: `RegExp('\\\\r?');`,
errors: [
{
message: JSON.stringify({
message: `Simplify this regular expression to reduce its complexity from 1 to the 0 allowed.`,
cost: 1,
secondaryLocations: [
{ message: '+1', column: 11, line: 1, endColumn: 12, endLine: 1 },
],
}),
line: 1,
endLine: 1,
column: 8,
endColumn: 14,
},
],
options: [0],
},
{
code: `/(?<=abc)/`,
errors: [
Expand Down
7 changes: 1 addition & 6 deletions packages/jsts/src/rules/S5860/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,7 @@ function prepareSecondaries(
function checkIndexedGroups(intellisense: RegexIntelliSense) {
intellisense.getKnowledge().forEach(regex => {
regex.groups.forEach(group => {
const { locations, messages } = prepareSecondaries(
regex,
[group],
intellisense,
'Named group',
);
const { locations, messages } = prepareSecondaries(regex, [group], intellisense, 'Group');

group.node.references.forEach(reference => {
const loc = getRegexpLocation(regex.node, reference, intellisense.context);
Expand Down

0 comments on commit e8c3027

Please sign in to comment.