Skip to content

Commit c4329bc

Browse files
committed
Fix newline spacing between import groups
1 parent f9f317e commit c4329bc

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

  • src-docs/src/components/guide_section

src-docs/src/components/guide_section/_utils.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const renderJsSourceCode = (code) => {
2121
// (, )? - optional comma after React - some files, like tests, only need the main React import
2222
// ({([^]+?)})? - optionally capture any characters (including newlines) between the import braces
2323
// from 'react'; - ` from 'react';` exactly
24-
/import (React)?(, )?({([^]+?)})? from 'react';/,
24+
// [\r\n] - match end of line
25+
/import (React)?(, )?({([^]+?)})? from 'react';[\r\n]/,
2526
(match) => {
2627
reactImport = match;
2728
return '';
@@ -35,12 +36,11 @@ export const renderJsSourceCode = (code) => {
3536

3637
// Find all imports that come from '@elastic/eui'
3738
renderedCode = renderedCode.replace(
38-
// [\r\n] - start of a line
3939
// import\s+\{ - import / whitespace / opening brace
4040
// ([^}]+) - group together anything that isn't a closing brace
4141
// \}\s+from\s+'@elastic\/eui'; - closing brace / whitespace / from / whitespace / '@elastic/eui';
4242
// [\r\n] - match end of line, so the extra new line is removed via the replace operation
43-
/[\r\n]import\s+\{([^}]+)\}\s+from\s+'@elastic\/eui';/g,
43+
/import\s+\{([^}]+)\}\s+from\s+'@elastic\/eui';[\r\n]/g,
4444
(match, imports) => {
4545
// remove any additional characters from imports
4646
const namedImports = imports.match(/[a-zA-Z0-9]+/g);
@@ -83,11 +83,14 @@ export const renderJsSourceCode = (code) => {
8383
}
8484
);
8585

86-
const formattedRemainingImports = remainingImports.join('\n');
86+
const formattedRemainingImports = remainingImports.reduce(
87+
(imports, importString) => (imports += `\n${importString}`),
88+
''
89+
);
8790

8891
/**
8992
* Putting it all together
9093
*/
91-
const fullyFormattedCode = `${reactImport}\n${formattedEuiImports}\n${formattedRemainingImports}\n\n${renderedCode.trim()}`;
94+
const fullyFormattedCode = `${reactImport}${formattedEuiImports}${formattedRemainingImports}\n\n${renderedCode.trim()}`;
9295
return fullyFormattedCode;
9396
};

0 commit comments

Comments
 (0)