Skip to content

Commit ed4978c

Browse files
committed
Only build up data when needed.
Per #1250 (comment)
1 parent dbe6686 commit ed4978c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/rules/jsx-boolean-value.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ const exceptionsSchema = {
1717
const ALWAYS = 'always';
1818
const NEVER = 'never';
1919

20+
const errorData = new WeakMap();
21+
function getErrorData(exceptions) {
22+
if (!errorData.has(exceptions)) {
23+
const exceptionProps = Array.from(exceptions, (name) => `\`${name}\``).join(', ');
24+
const exceptionsMessage = exceptions.size > 0 ? ` for the following props: ${exceptionProps}` : '';
25+
errorData.set(exceptions, {exceptionsMessage: exceptionsMessage});
26+
}
27+
return errorData.get(exceptions);
28+
}
29+
2030
module.exports = {
2131
meta: {
2232
docs: {
@@ -63,9 +73,6 @@ module.exports = {
6373
const configuration = context.options[0] || NEVER;
6474
const configObject = context.options[1] || {};
6575
const exceptions = new Set((configuration === ALWAYS ? configObject[NEVER] : configObject[ALWAYS]) || []);
66-
const exceptionProps = Array.from(exceptions, (name) => `\`${name}\``).join(', ');
67-
const exceptionsMessage = exceptions.size > 0 ? ` for the following props: ${exceptionProps}` : '';
68-
const data = {exceptionsMessage: exceptionsMessage};
6976

7077
const NEVER_MESSAGE = 'Value must be omitted for boolean attributes{{exceptionsMessage}}';
7178
const ALWAYS_MESSAGE = 'Value must be set for boolean attributes{{exceptionsMessage}}';
@@ -80,6 +87,7 @@ module.exports = {
8087
const isNever = configuration === NEVER ? !isException : isException;
8188

8289
if (isAlways && value === null) {
90+
const data = getErrorData(exceptions);
8391
context.report({
8492
node: node,
8593
message: ALWAYS_MESSAGE,
@@ -90,6 +98,7 @@ module.exports = {
9098
});
9199
}
92100
if (isNever && value && value.type === 'JSXExpressionContainer' && value.expression.value === true) {
101+
const data = getErrorData(exceptions);
93102
context.report({
94103
node: node,
95104
message: NEVER_MESSAGE,

0 commit comments

Comments
 (0)