Repository: styleguidist/react-styleguidist
Pull request #718 (2017-11-30 14:23:36)

Allow ignore to be specified at section level

codecov-io: # [Codecov](https://codecov.io/gh/styleguidist/react-styleguidist/pull/718?src=pr&el=h1) Report
> Merging [#718](https://codecov.io/gh/styleguidist/react-styleguidist/pull/718?src=pr&el=desc) into [master](https://codecov.io/gh/styleguidist/react-styleguidist/commit/8619f7059e52dd8251d371a9691d0b90d4198c02?src=pr&el=desc) will **increase** coverage by `0.01%`.
> The diff coverage is `100%`.

| [Impacted Files](https://codecov.io/gh/styleguidist/react-styleguidist/pull/718?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [loaders/utils/getSections.js](https://codecov.io/gh/styleguidist/react-styleguidist/pull/718/diff?src=pr&el=tree#diff-bG9hZGVycy91dGlscy9nZXRTZWN0aW9ucy5qcw==) | `100% <100%> (ø)` | :arrow_up: |

AlexMeah: @sapegin Made the suggested changes let me know if they are ok

Patch:
diff --git a/docs/Components.md b/docs/Components.md
index b56e714d..e502dc3f 100644
--- a/docs/Components.md
+++ b/docs/Components.md
@@ -48,6 +48,7 @@ Each section consists of (all fields are optional):
 - `name` — section title.
 - `content` — location of a Markdown file containing the overview content.
 - `components` — a glob pattern string or a function returning a list of components. The same rules apply as for the root `components` option.
+- `ignore` — string/array of globs that should not be included in the section.
 - `sections` — array of subsections (can be nested).
 
 Configuring a style guide with textual documentation section and a list of components would look like:
diff --git a/loaders/utils/getSections.js b/loaders/utils/getSections.js
index 5c02d725..a7042856 100644
--- a/loaders/utils/getSections.js
+++ b/loaders/utils/getSections.js
@@ -4,6 +4,7 @@
 
 const fs = require('fs');
 const path = require('path');
+const _ = require('lodash');
 const requireIt = require('./requireIt');
 const getComponentFiles = require('./getComponentFiles');
 const getComponents = require('./getComponents');
@@ -39,11 +40,17 @@ function processSection(section, config) {
 		content = requireIt(`!!${examplesLoader}!${filepath}`);
 	}
 
+	let ignore = config.ignore ? _.castArray(config.ignore) : [];
+
+	if (section.ignore) {
+		ignore = ignore.concat(_.castArray(section.ignore));
+	}
+
 	return {
 		name: section.name,
 		slug: slugger.slug(section.name),
 		components: getComponents(
-			getComponentFiles(section.components, config.configDir, config.ignore),
+			getComponentFiles(section.components, config.configDir, ignore),
 			config
 		),
 		sections: getSections(section.sections || [], config),


Test patch:
diff --git a/loaders/utils/__tests__/__snapshots__/getSections.spec.js.snap b/loaders/utils/__tests__/__snapshots__/getSections.spec.js.snap
index a093f906..bf6a36f7 100644
--- a/loaders/utils/__tests__/__snapshots__/getSections.spec.js.snap
+++ b/loaders/utils/__tests__/__snapshots__/getSections.spec.js.snap
@@ -37,7 +37,7 @@ Array [
         "props": RequireStatement {
           "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/Button/Button.js",
         },
-        "slug": "button-1",
+        "slug": "button-2",
       },
       Object {
         "filepath": "components/Placeholder/Placeholder.js",
@@ -52,7 +52,7 @@ Array [
         "props": RequireStatement {
           "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/Placeholder/Placeholder.js",
         },
-        "slug": "placeholder-1",
+        "slug": "placeholder-2",
       },
       Object {
         "filepath": "components/RandomButton/RandomButton.js",
@@ -65,7 +65,7 @@ Array [
         "props": RequireStatement {
           "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/RandomButton/RandomButton.js",
         },
-        "slug": "randombutton-1",
+        "slug": "randombutton-2",
       },
     ],
     "content": undefined,
@@ -73,6 +73,55 @@ Array [
     "sections": Array [],
     "slug": "components-1",
   },
+  Object {
+    "components": Array [
+      Object {
+        "filepath": "components/Button/Button.js",
+        "hasExamples": true,
+        "metadata": Object {},
+        "module": RequireStatement {
+          "filepath": "<rootDir>/test/components/Button/Button.js",
+        },
+        "pathLine": "components/Button/Button.js",
+        "props": RequireStatement {
+          "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/Button/Button.js",
+        },
+        "slug": "button-3",
+      },
+      Object {
+        "filepath": "components/Placeholder/Placeholder.js",
+        "hasExamples": true,
+        "metadata": RequireStatement {
+          "filepath": "!!json-loader!<rootDir>/test/components/Placeholder/Placeholder.json",
+        },
+        "module": RequireStatement {
+          "filepath": "<rootDir>/test/components/Placeholder/Placeholder.js",
+        },
+        "pathLine": "components/Placeholder/Placeholder.js",
+        "props": RequireStatement {
+          "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/Placeholder/Placeholder.js",
+        },
+        "slug": "placeholder-3",
+      },
+      Object {
+        "filepath": "components/RandomButton/RandomButton.js",
+        "hasExamples": true,
+        "metadata": Object {},
+        "module": RequireStatement {
+          "filepath": "<rootDir>/test/components/RandomButton/RandomButton.js",
+        },
+        "pathLine": "components/RandomButton/RandomButton.js",
+        "props": RequireStatement {
+          "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/RandomButton/RandomButton.js",
+        },
+        "slug": "randombutton-3",
+      },
+    ],
+    "content": undefined,
+    "name": "Ignore",
+    "sections": Array [],
+    "slug": "ignore-1",
+  },
 ]
 `;
 
@@ -152,3 +201,55 @@ Object {
   "slug": "readme",
 }
 `;
+
+exports[`processSection() should return an object for section without ignored components 1`] = `
+Object {
+  "components": Array [
+    Object {
+      "filepath": "components/Button/Button.js",
+      "hasExamples": true,
+      "metadata": Object {},
+      "module": RequireStatement {
+        "filepath": "<rootDir>/test/components/Button/Button.js",
+      },
+      "pathLine": "components/Button/Button.js",
+      "props": RequireStatement {
+        "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/Button/Button.js",
+      },
+      "slug": "button-1",
+    },
+    Object {
+      "filepath": "components/Placeholder/Placeholder.js",
+      "hasExamples": true,
+      "metadata": RequireStatement {
+        "filepath": "!!json-loader!<rootDir>/test/components/Placeholder/Placeholder.json",
+      },
+      "module": RequireStatement {
+        "filepath": "<rootDir>/test/components/Placeholder/Placeholder.js",
+      },
+      "pathLine": "components/Placeholder/Placeholder.js",
+      "props": RequireStatement {
+        "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/Placeholder/Placeholder.js",
+      },
+      "slug": "placeholder-1",
+    },
+    Object {
+      "filepath": "components/RandomButton/RandomButton.js",
+      "hasExamples": true,
+      "metadata": Object {},
+      "module": RequireStatement {
+        "filepath": "<rootDir>/test/components/RandomButton/RandomButton.js",
+      },
+      "pathLine": "components/RandomButton/RandomButton.js",
+      "props": RequireStatement {
+        "filepath": "!!<rootDir>/loaders/props-loader.js!<rootDir>/test/components/RandomButton/RandomButton.js",
+      },
+      "slug": "randombutton-1",
+    },
+  ],
+  "content": undefined,
+  "name": "Ignore",
+  "sections": Array [],
+  "slug": "ignore",
+}
+`;
diff --git a/loaders/utils/__tests__/getSections.spec.js b/loaders/utils/__tests__/getSections.spec.js
index fe5891db..d5a07ea3 100644
--- a/loaders/utils/__tests__/getSections.spec.js
+++ b/loaders/utils/__tests__/getSections.spec.js
@@ -13,6 +13,11 @@ const sections = [
 		name: 'Components',
 		components: 'components/**/[A-Z]*.js',
 	},
+	{
+		name: 'Ignore',
+		components: 'components/**/*.js',
+		ignore: '**/components/Annotation/*',
+	},
 ];
 const config = {
 	configDir,
@@ -38,6 +43,12 @@ it('processSection() should return an object for section with components', () =>
 	expect(result).toMatchSnapshot();
 });
 
+it('processSection() should return an object for section without ignored components', () => {
+	const result = processSection(sections[2], config);
+
+	expect(result).toMatchSnapshot();
+});
+
 it('getSections() should return an array', () => {
 	const result = getSections(sections, config);