Skip to content

Commit b420cb5

Browse files
committed
PR suggested changes
1 parent 6655950 commit b420cb5

File tree

3 files changed

+50
-49
lines changed

3 files changed

+50
-49
lines changed

docs/rules/no-multi-comp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class HelloJohn extends React.Component {
6969
module.exports = HelloJohn;
7070
```
7171

72-
### `ignorePrivate`
72+
### `ignoreInternal`
7373

7474
When `true` the rule will ignore components which are not exported, which allows you to define components that are consumed only within the same file.
7575
This ensures there is only one entry point for a React component without limiting the structural content of the file.

lib/rules/no-multi-comp.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
default: false,
4040
type: 'boolean',
4141
},
42-
ignorePrivate: {
42+
ignoreInternal: {
4343
default: false,
4444
type: 'boolean',
4545
},
@@ -51,7 +51,7 @@ module.exports = {
5151
create: Components.detect((context, components, utils) => {
5252
const configuration = context.options[0] || {};
5353
const ignoreStateless = configuration.ignoreStateless || false;
54-
const ignorePrivate = configuration.ignorePrivate || false;
54+
const ignoreInternal = configuration.ignoreInternal || false;
5555

5656
const exportedComponents = new Set(); // Track exported components
5757
const validIdentifiers = new Set(['ArrowFunctionExpression', 'Identifier', 'FunctionExpression']);
@@ -109,7 +109,7 @@ module.exports = {
109109
* @returns {boolean} True if the component is exported or exportOnly is false
110110
*/
111111
function isPrivate(component) {
112-
return ignorePrivate && exportedComponents.has(findComponentIdentifierFromComponent(component));
112+
return ignoreInternal && exportedComponents.has(findComponentIdentifierFromComponent(component));
113113
}
114114

115115
const rule = {
@@ -123,23 +123,24 @@ module.exports = {
123123
.slice(1)
124124
.forEach((component) => {
125125
report(context,
126-
ignorePrivate ? messages.onlyOneExportedComponent : messages.onlyOneComponent,
127-
ignorePrivate ? 'onlyOneExportedComponent' : 'onlyOneComponent',
126+
ignoreInternal ? messages.onlyOneExportedComponent : messages.onlyOneComponent,
127+
ignoreInternal ? 'onlyOneExportedComponent' : 'onlyOneComponent',
128128
{
129129
node: component.node,
130130
});
131131
});
132132
},
133133
};
134134

135-
if (ignorePrivate) {
136-
rule.ExportNamedDeclaration = (node) => {
137-
exportedComponents.add(getExportedComponentName(node));
138-
};
139-
140-
rule.ExportDefaultDeclaration = (node) => {
141-
exportedComponents.add(getExportedComponentName(node));
142-
};
135+
if (ignoreInternal) {
136+
Object.assign(rule, {
137+
ExportNamedDeclaration(node) {
138+
exportedComponents.add(getExportedComponentName(node));
139+
},
140+
ExportDefaultDeclaration(node) {
141+
exportedComponents.add(getExportedComponentName(node));
142+
},
143+
});
143144
}
144145

145146
return rule;

tests/lib/rules/no-multi-comp.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -270,54 +270,54 @@ ruleTester.run('no-multi-comp', rule, {
270270
const ComponentOne = () => <></>;
271271
const ComponentTwo = () => <></>;
272272
`,
273-
options: [{ ignorePrivate: true }],
273+
options: [{ ignoreInternal: true }],
274274
},
275275
{
276276
code: `
277277
export const ComponentOne = () => <></>;
278278
const ComponentTwo = () => <></>;
279279
`,
280-
options: [{ ignorePrivate: true }],
280+
options: [{ ignoreInternal: true }],
281281
},
282282
{
283283
code: `
284284
const ComponentOne = () => <></>;
285285
const ComponentTwo = () => <></>;
286286
module.exports = { ComponentOne };
287287
`,
288-
options: [{ ignorePrivate: true }],
288+
options: [{ ignoreInternal: true }],
289289
},
290290
{
291291
code: `
292292
const ComponentOne = () => <></>;
293293
const ComponentTwo = () => <></>;
294294
export default ComponentOne;
295295
`,
296-
options: [{ ignorePrivate: true }],
296+
options: [{ ignoreInternal: true }],
297297
},
298298
{
299299
code: `
300300
function ComponentOne() { return <></> };
301301
const ComponentTwo = () => <></>;
302302
export default ComponentOne;
303303
`,
304-
options: [{ ignorePrivate: true }],
304+
options: [{ ignoreInternal: true }],
305305
},
306306
{
307307
code: `
308308
function ComponentOne() { return <></> };
309309
function ComponentTwo() { return <></> };
310310
export default ComponentOne;
311311
`,
312-
options: [{ ignorePrivate: true }],
312+
options: [{ ignoreInternal: true }],
313313
},
314314
{
315315
code: `
316316
import React, {Component} from "react";
317317
export class ComponentOne extends Component() { render() { return <></>; }};
318318
function ComponentTwo() { return <></> };
319319
`,
320-
options: [{ ignorePrivate: true }],
320+
options: [{ ignoreInternal: true }],
321321
},
322322
{
323323
code: `
@@ -326,46 +326,46 @@ ruleTester.run('no-multi-comp', rule, {
326326
function ComponentTwo() { return <></> };
327327
export default ComponentOne;
328328
`,
329-
options: [{ ignorePrivate: true }],
329+
options: [{ ignoreInternal: true }],
330330
},
331331
{
332332
code: `
333333
const ComponentOne = () => <></>;
334334
const ComponentTwo = () => <></>;
335335
export { ComponentOne };
336336
`,
337-
options: [{ ignorePrivate: true }],
337+
options: [{ ignoreInternal: true }],
338338
},
339339
{
340340
code: `
341341
export function ComponentOne() { return <></>; }
342342
function ComponentTwo() { return <></>; }
343343
`,
344-
options: [{ ignorePrivate: true }],
344+
options: [{ ignoreInternal: true }],
345345
},
346346
{
347347
code: `
348348
const ComponentOne = () => <></>;
349349
const ComponentTwo = () => <></>;
350350
module.exports = ComponentOne;
351351
`,
352-
options: [{ ignorePrivate: true }],
352+
options: [{ ignoreInternal: true }],
353353
},
354354
{
355355
code: `
356356
const ComponentOne = () => <></>;
357357
const ComponentTwo = () => <></>;
358358
export default function() { return <ComponentOne />; }
359359
`,
360-
options: [{ ignorePrivate: true }],
360+
options: [{ ignoreInternal: true }],
361361
},
362362
{
363363
code: `
364364
function ComponentOne() { return <></>; }
365365
const ComponentTwo = () => <></>;
366366
export { ComponentOne as default };
367367
`,
368-
options: [{ ignorePrivate: true }],
368+
options: [{ ignoreInternal: true }],
369369
},
370370
{
371371
code: `
@@ -377,7 +377,7 @@ ruleTester.run('no-multi-comp', rule, {
377377
render() { return <></>; }
378378
}
379379
`,
380-
options: [{ ignorePrivate: true }],
380+
options: [{ ignoreInternal: true }],
381381
},
382382
{
383383
code: `
@@ -390,7 +390,7 @@ ruleTester.run('no-multi-comp', rule, {
390390
}
391391
export { ComponentOne };
392392
`,
393-
options: [{ ignorePrivate: true }],
393+
options: [{ ignoreInternal: true }],
394394
},
395395
{
396396
code: `
@@ -399,15 +399,15 @@ ruleTester.run('no-multi-comp', rule, {
399399
const ComponentTwo = () => <></>;
400400
export default ComponentOne;
401401
`,
402-
options: [{ ignorePrivate: true }],
402+
options: [{ ignoreInternal: true }],
403403
},
404404
{
405405
code: `
406406
import React from "react";
407407
export default function Component(props) { return <div>{props.children}</div>; }
408408
function ComponentTwo(props) { return <div>{props.children}</div>; }
409409
`,
410-
options: [{ ignorePrivate: true }],
410+
options: [{ ignoreInternal: true }],
411411
},
412412
]),
413413

@@ -761,7 +761,7 @@ ruleTester.run('no-multi-comp', rule, {
761761
export const ComponentOne = () => <></>;
762762
export const ComponentTwo = () => <></>;
763763
`,
764-
options: [{ ignorePrivate: true }],
764+
options: [{ ignoreInternal: true }],
765765
errors: [{ messageId: 'onlyOneExportedComponent' }],
766766
},
767767
{
@@ -770,7 +770,7 @@ ruleTester.run('no-multi-comp', rule, {
770770
const ComponentTwo = () => <></>;
771771
module.exports = { ComponentOne, ComponentTwo };
772772
`,
773-
options: [{ ignorePrivate: true }],
773+
options: [{ ignoreInternal: true }],
774774
errors: [{ messageId: 'onlyOneExportedComponent' }],
775775
},
776776
{
@@ -779,7 +779,7 @@ ruleTester.run('no-multi-comp', rule, {
779779
export const ComponentTwo = () => <></>;
780780
export default ComponentOne;
781781
`,
782-
options: [{ ignorePrivate: true }],
782+
options: [{ ignoreInternal: true }],
783783
errors: [{ messageId: 'onlyOneExportedComponent' }],
784784
},
785785
{
@@ -788,7 +788,7 @@ ruleTester.run('no-multi-comp', rule, {
788788
export const ComponentTwo = () => <></>;
789789
export default ComponentTwo;
790790
`,
791-
options: [{ ignorePrivate: true }],
791+
options: [{ ignoreInternal: true }],
792792
errors: [{ messageId: 'onlyOneExportedComponent' }],
793793
},
794794
{
@@ -797,7 +797,7 @@ ruleTester.run('no-multi-comp', rule, {
797797
export function ComponentTwo() { return <></> };
798798
export default ComponentOne;
799799
`,
800-
options: [{ ignorePrivate: true }],
800+
options: [{ ignoreInternal: true }],
801801
errors: [{ messageId: 'onlyOneExportedComponent' }],
802802
},
803803
{
@@ -806,7 +806,7 @@ ruleTester.run('no-multi-comp', rule, {
806806
export class ComponentOne extends Component() { render() { return <></>; }};
807807
export function ComponentTwo() { return <></> };
808808
`,
809-
options: [{ ignorePrivate: true }],
809+
options: [{ ignoreInternal: true }],
810810
errors: [{ messageId: 'onlyOneExportedComponent' }],
811811
},
812812
{
@@ -816,7 +816,7 @@ ruleTester.run('no-multi-comp', rule, {
816816
export function ComponentTwo() { return <></> };
817817
export default ComponentOne;
818818
`,
819-
options: [{ ignorePrivate: true }],
819+
options: [{ ignoreInternal: true }],
820820
errors: [{ messageId: 'onlyOneExportedComponent' }],
821821
},
822822
{
@@ -826,7 +826,7 @@ ruleTester.run('no-multi-comp', rule, {
826826
function ComponentTwo() { return <></> };
827827
export default ComponentOne;
828828
`,
829-
options: [{ ignorePrivate: true }],
829+
options: [{ ignoreInternal: true }],
830830
errors: [{ messageId: 'onlyOneExportedComponent' }],
831831
},
832832
{
@@ -835,15 +835,15 @@ ruleTester.run('no-multi-comp', rule, {
835835
const ComponentTwo = () => <></>;
836836
export { ComponentOne };
837837
`,
838-
options: [{ ignorePrivate: true }],
838+
options: [{ ignoreInternal: true }],
839839
errors: [{ messageId: 'onlyOneExportedComponent' }],
840840
},
841841
{
842842
code: `
843843
export function ComponentOne() { return <></>; }
844844
function ComponentTwo() { return <></>; }
845845
`,
846-
options: [{ ignorePrivate: true }],
846+
options: [{ ignoreInternal: true }],
847847
errors: [{ messageId: 'onlyOneExportedComponent' }],
848848
},
849849
{
@@ -852,7 +852,7 @@ ruleTester.run('no-multi-comp', rule, {
852852
const ComponentTwo = () => <></>;
853853
module.exports = ComponentOne;
854854
`,
855-
options: [{ ignorePrivate: true }],
855+
options: [{ ignoreInternal: true }],
856856
errors: [{ messageId: 'onlyOneExportedComponent' }],
857857
},
858858
{
@@ -861,7 +861,7 @@ ruleTester.run('no-multi-comp', rule, {
861861
const ComponentTwo = () => <></>;
862862
export default function() { return <ComponentOne />; }
863863
`,
864-
options: [{ ignorePrivate: true }],
864+
options: [{ ignoreInternal: true }],
865865
errors: [{ messageId: 'onlyOneExportedComponent' }],
866866
},
867867
{
@@ -870,7 +870,7 @@ ruleTester.run('no-multi-comp', rule, {
870870
const ComponentTwo = () => <></>;
871871
export { ComponentOne as default };
872872
`,
873-
options: [{ ignorePrivate: true }],
873+
options: [{ ignoreInternal: true }],
874874
errors: [{ messageId: 'onlyOneExportedComponent' }],
875875
},
876876
{
@@ -883,7 +883,7 @@ ruleTester.run('no-multi-comp', rule, {
883883
render() { return <></>; }
884884
}
885885
`,
886-
options: [{ ignorePrivate: true }],
886+
options: [{ ignoreInternal: true }],
887887
errors: [{ messageId: 'onlyOneExportedComponent' }],
888888
},
889889
{
@@ -897,7 +897,7 @@ ruleTester.run('no-multi-comp', rule, {
897897
}
898898
export { ComponentOne };
899899
`,
900-
options: [{ ignorePrivate: true }],
900+
options: [{ ignoreInternal: true }],
901901
errors: [{ messageId: 'onlyOneExportedComponent' }],
902902
},
903903
{
@@ -907,7 +907,7 @@ ruleTester.run('no-multi-comp', rule, {
907907
const ComponentTwo = () => <></>;
908908
export default ComponentOne;
909909
`,
910-
options: [{ ignorePrivate: true }],
910+
options: [{ ignoreInternal: true }],
911911
errors: [{ messageId: 'onlyOneExportedComponent' }],
912912
},
913913
{
@@ -916,7 +916,7 @@ ruleTester.run('no-multi-comp', rule, {
916916
export default function Component(props) { return <div>{props.children}</div>; }
917917
export function ComponentTwo(props) { return <div>{props.children}</div>; }
918918
`,
919-
options: [{ ignorePrivate: true }],
919+
options: [{ ignoreInternal: true }],
920920
errors: [{ messageId: 'onlyOneExportedComponent' }],
921921
},
922922
{
@@ -925,7 +925,7 @@ ruleTester.run('no-multi-comp', rule, {
925925
export function componentOne(props) { return <div>{props.children}</div>; }
926926
export function ComponentOne(props) { return <div>{props.children}</div>; }
927927
`,
928-
options: [{ ignorePrivate: true }],
928+
options: [{ ignoreInternal: true }],
929929
errors: [{ messageId: 'onlyOneExportedComponent' }],
930930
},
931931
]),

0 commit comments

Comments
 (0)