Skip to content

Commit 27d8075

Browse files
committed
fix docs, change name to ignorePrivate
1 parent 23c5e34 commit 27d8075

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

docs/rules/no-multi-comp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ class HelloJohn extends React.Component {
6969
module.exports = HelloJohn;
7070
```
7171

72-
### `exportOnly`
72+
### `ignorePrivate`
7373

74-
When `true` the rule will ignore components which are not exported, which allows you to define components as long as they are only used within a private scope.
74+
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.
75+
This ensures there is only one entry point for a React component without limiting the structural content of the file.
7576

7677
Examples of **correct** code for this rule:
7778

@@ -117,7 +118,6 @@ function HelloAgain(props) {
117118
module.exports = {Hello, HelloAgain}
118119
```
119120

120-
121121
## When Not To Use It
122122

123123
If you prefer to declare multiple components per file you can disable this rule.

lib/rules/no-multi-comp.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module.exports = {
3939
default: false,
4040
type: 'boolean',
4141
},
42-
exportOnly: {
42+
ignorePrivate: {
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 exportOnly = configuration.exportOnly || false;
54+
const ignorePrivate = configuration.ignorePrivate || false;
5555

5656
const exportedComponents = new Set(); // Track exported components
5757
const validIdentifiers = new Set(['ArrowFunctionExpression', 'Identifier', 'FunctionExpression']);
@@ -108,8 +108,8 @@ module.exports = {
108108
* @param {Object} component The component being checked.
109109
* @returns {boolean} True if the component is exported or exportOnly is false
110110
*/
111-
function isExported(component) {
112-
return !exportOnly || exportedComponents.has(findComponentIdentifierFromComponent(component));
111+
function isPrivate(component) {
112+
return ignorePrivate && exportedComponents.has(findComponentIdentifierFromComponent(component));
113113
}
114114

115115
const rule = {
@@ -120,20 +120,20 @@ module.exports = {
120120

121121
values(components.list())
122122
.filter((component) => !isIgnored(component))
123-
.filter((component) => isExported(component))
123+
.filter((component) => !isPrivate(component))
124124
.slice(1)
125125
.forEach((component) => {
126126
report(context,
127-
exportOnly ? messages.onlyOneExportedComponent : messages.onlyOneComponent,
128-
exportOnly ? 'onlyOneExportedComponent' : 'onlyOneComponent',
127+
ignorePrivate ? messages.onlyOneExportedComponent : messages.onlyOneComponent,
128+
ignorePrivate ? 'onlyOneExportedComponent' : 'onlyOneComponent',
129129
{
130130
node: component.node,
131131
});
132132
});
133133
},
134134
};
135135

136-
if (exportOnly) {
136+
if (ignorePrivate) {
137137
rule.ExportNamedDeclaration = (node) => {
138138
exportedComponents.add(getExportedComponentName(node));
139139
};

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: [{ exportOnly: true }],
273+
options: [{ ignorePrivate: true }],
274274
},
275275
{
276276
code: `
277277
export const ComponentOne = () => <></>;
278278
const ComponentTwo = () => <></>;
279279
`,
280-
options: [{ exportOnly: true }],
280+
options: [{ ignorePrivate: true }],
281281
},
282282
{
283283
code: `
284284
const ComponentOne = () => <></>;
285285
const ComponentTwo = () => <></>;
286286
module.exports = { ComponentOne };
287287
`,
288-
options: [{ exportOnly: true }],
288+
options: [{ ignorePrivate: true }],
289289
},
290290
{
291291
code: `
292292
const ComponentOne = () => <></>;
293293
const ComponentTwo = () => <></>;
294294
export default ComponentOne;
295295
`,
296-
options: [{ exportOnly: true }],
296+
options: [{ ignorePrivate: true }],
297297
},
298298
{
299299
code: `
300300
function ComponentOne() { return <></> };
301301
const ComponentTwo = () => <></>;
302302
export default ComponentOne;
303303
`,
304-
options: [{ exportOnly: true }],
304+
options: [{ ignorePrivate: true }],
305305
},
306306
{
307307
code: `
308308
function ComponentOne() { return <></> };
309309
function ComponentTwo() { return <></> };
310310
export default ComponentOne;
311311
`,
312-
options: [{ exportOnly: true }],
312+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
320+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
329+
options: [{ ignorePrivate: true }],
330330
},
331331
{
332332
code: `
333333
const ComponentOne = () => <></>;
334334
const ComponentTwo = () => <></>;
335335
export { ComponentOne };
336336
`,
337-
options: [{ exportOnly: true }],
337+
options: [{ ignorePrivate: true }],
338338
},
339339
{
340340
code: `
341341
export function ComponentOne() { return <></>; }
342342
function ComponentTwo() { return <></>; }
343343
`,
344-
options: [{ exportOnly: true }],
344+
options: [{ ignorePrivate: true }],
345345
},
346346
{
347347
code: `
348348
const ComponentOne = () => <></>;
349349
const ComponentTwo = () => <></>;
350350
module.exports = ComponentOne;
351351
`,
352-
options: [{ exportOnly: true }],
352+
options: [{ ignorePrivate: true }],
353353
},
354354
{
355355
code: `
356356
const ComponentOne = () => <></>;
357357
const ComponentTwo = () => <></>;
358358
export default function() { return <ComponentOne />; }
359359
`,
360-
options: [{ exportOnly: true }],
360+
options: [{ ignorePrivate: true }],
361361
},
362362
{
363363
code: `
364364
function ComponentOne() { return <></>; }
365365
const ComponentTwo = () => <></>;
366366
export { ComponentOne as default };
367367
`,
368-
options: [{ exportOnly: true }],
368+
options: [{ ignorePrivate: true }],
369369
},
370370
{
371371
code: `
@@ -377,7 +377,7 @@ ruleTester.run('no-multi-comp', rule, {
377377
render() { return <></>; }
378378
}
379379
`,
380-
options: [{ exportOnly: true }],
380+
options: [{ ignorePrivate: true }],
381381
},
382382
{
383383
code: `
@@ -390,7 +390,7 @@ ruleTester.run('no-multi-comp', rule, {
390390
}
391391
export { ComponentOne };
392392
`,
393-
options: [{ exportOnly: true }],
393+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
402+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
410+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
764+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
773+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
782+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
791+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
800+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
809+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
819+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
829+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
838+
options: [{ ignorePrivate: true }],
839839
errors: [{ messageId: 'onlyOneExportedComponent' }],
840840
},
841841
{
842842
code: `
843843
export function ComponentOne() { return <></>; }
844844
function ComponentTwo() { return <></>; }
845845
`,
846-
options: [{ exportOnly: true }],
846+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
855+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
864+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
873+
options: [{ ignorePrivate: true }],
874874
errors: [{ messageId: 'onlyOneExportedComponent' }],
875875
},
876876
{
@@ -883,7 +883,7 @@ ruleTester.run('no-multi-comp', rule, {
883883
render() { return <></>; }
884884
}
885885
`,
886-
options: [{ exportOnly: true }],
886+
options: [{ ignorePrivate: true }],
887887
errors: [{ messageId: 'onlyOneExportedComponent' }],
888888
},
889889
{
@@ -897,7 +897,7 @@ ruleTester.run('no-multi-comp', rule, {
897897
}
898898
export { ComponentOne };
899899
`,
900-
options: [{ exportOnly: true }],
900+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
910+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
919+
options: [{ ignorePrivate: 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: [{ exportOnly: true }],
928+
options: [{ ignorePrivate: true }],
929929
errors: [{ messageId: 'onlyOneExportedComponent' }],
930930
},
931931
]),

0 commit comments

Comments
 (0)