Skip to content

Commit 1f7488a

Browse files
authored
Simplify reportListenerProblems (#2132)
1 parent f3265b9 commit 1f7488a

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

rules/utils/rule.js

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,35 @@ function wrapFixFunction(fix) {
3333
};
3434
}
3535

36-
function reportListenerProblems(listener, context) {
37-
// Listener arguments can be `codePath, node` or `node`
38-
return function (...listenerArguments) {
39-
let problems = listener(...listenerArguments);
36+
function reportListenerProblems(problems, context) {
37+
if (!problems) {
38+
return;
39+
}
4040

41-
if (!problems) {
42-
return;
43-
}
41+
if (!isIterable(problems)) {
42+
problems = [problems];
43+
}
4444

45-
if (!isIterable(problems)) {
46-
problems = [problems];
45+
for (const problem of problems) {
46+
if (problem.fix) {
47+
problem.fix = wrapFixFunction(problem.fix);
4748
}
4849

49-
for (const problem of problems) {
50-
if (problem.fix) {
51-
problem.fix = wrapFixFunction(problem.fix);
52-
}
53-
54-
if (Array.isArray(problem.suggest)) {
55-
for (const suggest of problem.suggest) {
56-
if (suggest.fix) {
57-
suggest.fix = wrapFixFunction(suggest.fix);
58-
}
59-
60-
suggest.data = {
61-
...problem.data,
62-
...suggest.data,
63-
};
50+
if (Array.isArray(problem.suggest)) {
51+
for (const suggest of problem.suggest) {
52+
if (suggest.fix) {
53+
suggest.fix = wrapFixFunction(suggest.fix);
6454
}
65-
}
6655

67-
context.report(problem);
56+
suggest.data = {
57+
...problem.data,
58+
...suggest.data,
59+
};
60+
}
6861
}
69-
};
62+
63+
context.report(problem);
64+
}
7065
}
7166

7267
// `checkVueTemplate` function will wrap `create` function, there is no need to wrap twice
@@ -106,9 +101,10 @@ function reportProblems(create) {
106101
Object.entries(listeners)
107102
.map(([selector, listeners]) => [
108103
selector,
104+
// Listener arguments can be `codePath, node` or `node`
109105
(...listenerArguments) => {
110106
for (const listener of listeners) {
111-
reportListenerProblems(listener, context)(...listenerArguments);
107+
reportListenerProblems(listener(...listenerArguments), context);
112108
}
113109
},
114110
]),

0 commit comments

Comments
 (0)