Skip to content

Commit a28c935

Browse files
committed
chore: address PR feedback
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 0c29e66 commit a28c935

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

lib/node_modules/@stdlib/_tools/changelog/generate/lib/breaking_changes.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
var filter = require( '@stdlib/array/base/filter' );
2424
var trim = require( '@stdlib/string/trim' );
2525
var map = require( '@stdlib/utils/map' );
26+
var reEOL = require( '@stdlib/regexp/eol' );
2627
var collectField = require( './collect_field.js' );
2728
var sectionStart = require( './section_start.js' );
2829
var sectionEnd = require( './section_end.js' );
@@ -38,19 +39,17 @@ var RE_YAML_DELIMITER = /^\s*---\s*$/;
3839
// FUNCTIONS //
3940

4041
/**
41-
* Strips YAML frontmatter blocks from text.
42+
* Strips YAML frontmatter blocks from text lines.
4243
*
4344
* @private
44-
* @param {string} text - text to process
45-
* @returns {string} text without YAML blocks
45+
* @param {Array<string>} lines - text lines to process
46+
* @returns {Array<string>} text lines without YAML blocks
4647
*/
47-
function stripYamlBlocks( text ) {
48+
function stripYamlBlocks( lines ) {
4849
var result;
4950
var inYaml;
50-
var lines;
5151
var i;
5252

53-
lines = text.split( '\n' );
5453
result = [];
5554
inYaml = false;
5655

@@ -67,7 +66,7 @@ function stripYamlBlocks( text ) {
6766
}
6867
}
6968

70-
return trim( result.join( '\n' ) );
69+
return result;
7170
}
7271

7372
/**
@@ -87,17 +86,39 @@ function stripYamlBlocks( text ) {
8786
* // returns '- [`abcdef1`](https://github.com/stdlib-js/stdlib/commit/abcdef1234567890): beep'
8887
*/
8988
function formatBreakingChange( note ) {
90-
var parts;
89+
var contentLines;
90+
var trimmedLine;
91+
var firstLine;
92+
var restLines;
93+
var textLines;
9194
var hash;
9295
var out;
96+
var i;
9397

94-
parts = stripYamlBlocks( note.text ).split( '\n' );
98+
textLines = note.text.split( reEOL.REGEXP );
99+
contentLines = stripYamlBlocks( textLines );
100+
firstLine = '';
101+
restLines = [];
95102
hash = trim( note.hash );
96-
out = '- [`'+hash.substring( 0, 7 )+'`]('+STDLIB_GITHUB_URL+'/'+hash+'): '+parts[ 0 ];
97-
if ( parts.length > 1 ) {
98-
out +='\n\n';
99-
out += ' - ';
100-
out += parts.slice( 1 ).join( '\n ' );
103+
104+
for ( i = 0; i < contentLines.length; i++ ) {
105+
trimmedLine = trim( contentLines[i] );
106+
if ( trimmedLine !== '' ) {
107+
// If this is our first non-empty line, it's the firstLine...
108+
if ( firstLine === '' ) {
109+
firstLine = trimmedLine;
110+
} else {
111+
restLines.push( trimmedLine );
112+
}
113+
}
114+
}
115+
116+
// Construct output string - use a single string concatenation when possible
117+
out = '- [`' + hash.substring( 0, 7 ) + '`](' + STDLIB_GITHUB_URL + '/' + hash + '): ' + firstLine;
118+
119+
if ( restLines.length > 0 ) {
120+
out += '\n\n';
121+
out += ' - ' + restLines.join( '\n ' );
101122
out += '\n';
102123
}
103124
return out;

0 commit comments

Comments
 (0)