Skip to content

Commit

Permalink
Merge e5ff205 into ef325bc
Browse files Browse the repository at this point in the history
  • Loading branch information
no-chris committed Nov 20, 2021
2 parents ef325bc + e5ff205 commit 7baf959
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 89 deletions.
69 changes: 2 additions & 67 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"eslint": "^8.0.1",
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-no-unsanitized": "^4.0.0",
"generate-changelog": "^1.8.0",
"handlebars-loader": "^1.7.1",
"jest": "^27.2.5",
"jest-handlebars": "^1.0.1",
Expand Down Expand Up @@ -59,10 +58,6 @@
"build": "npm run lint && npm run test && npm run bundle-js && npm run bundle-css && npm run size && npm run sloc",
"format": "prettier --write \"**/*.{js,jsx,json,ts,md}\"",
"lint": "eslint src tests",
"outdated": "npm outdated",
"release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version major && git push origin && git push origin --tags",
"release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version minor && git push origin && git push origin --tags",
"release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md' && npm version patch && git push origin && git push origin --tags",
"size": "size-limit",
"sloc": "echo \"Source code:\" > SLOC && npx sloc src >> SLOC && echo \"Tests:\" >> SLOC && npx sloc tests >> SLOC && echo \"Total:\" >> SLOC && npx sloc src tests >> SLOC",
"test": "jest"
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/components/renderSong.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function renderSong(
});

const sectionsStats = getSectionsStats(allLines);
const maxBeatsWidth = getMaxBeatsWidth(allLines, alignChordsWithLyrics);
const maxBeatsWidth = getMaxBeatsWidth(allLines, shouldAlignChords);

const song = renderAllLines().join('\n');

Expand Down Expand Up @@ -154,9 +154,10 @@ export default function renderSong(
let rendered;

if (line.type === lineTypes.CHORD) {
let spaced = alignBars
? alignedChordSpacer(line.model, maxBeatsWidth)
: simpleChordSpacer(line.model);
let spaced =
alignBars && !shouldAlignChords(line)
? alignedChordSpacer(line.model, maxBeatsWidth)
: simpleChordSpacer(line.model);

const nextLine = allFilteredLines[lineIndex + 1];
if (shouldAlignChords(line)) {
Expand Down
8 changes: 3 additions & 5 deletions src/renderer/spacers/chord/getMaxBeatsWidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@ import symbols from '../../symbols';

/**
* @param {SongLine[]} allLines
* @param {Boolean} alignChordsWithLyrics
* @param {Function} shouldAlignChords
* @returns {Array}
*/
export default function getMaxBeatsWidth(allLines, alignChordsWithLyrics) {
export default function getMaxBeatsWidth(allLines, shouldAlignChords) {
const maxBeatsWidth = [];

allLines
.filter((line) => line.type === lineTypes.CHORD)
.filter(
(line) => !(alignChordsWithLyrics && line.model.hasPositionedChords)
)
.filter((line) => !shouldAlignChords(line))
.forEach((line) => {
line.model.allBars.forEach((bar, barIndex) => {
if (!maxBeatsWidth[barIndex]) {
Expand Down
15 changes: 7 additions & 8 deletions tests/unit/renderer/spacers/chord/getMaxBeatsWidth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe.each([
(chord) => (chord.symbol = getChordSymbol(chord.model))
);

const maxBeatsWidth = getMaxBeatsWidth(allLines, false);
const maxBeatsWidth = getMaxBeatsWidth(allLines, () => false);
expect(maxBeatsWidth).toEqual(output);
});
});
Expand Down Expand Up @@ -181,7 +181,7 @@ describe.each([
(chord) => (chord.symbol = getChordSymbol(chord.model))
);

const maxBeatsWidth = getMaxBeatsWidth(allLines, false);
const maxBeatsWidth = getMaxBeatsWidth(allLines, () => false);
expect(maxBeatsWidth).toEqual(output);
});
}
Expand All @@ -190,7 +190,7 @@ describe.each([
describe.each([
[
'positioned chords NOT TAKEN into account when they are aligned with lyrics',
true,
[true, false],
[
'Ami7.. B7(b9,#9).. D7(#11)',
'_A lyric _line with _position markers',
Expand All @@ -203,7 +203,7 @@ describe.each([
],
[
'positioned chords taken into account when they are NOT aligned with lyrics',
false,
[false, false],
[
'Am7.. B7(b9,#9).. D7(#11)',
'_A lyric _line with _position markers',
Expand All @@ -216,7 +216,7 @@ describe.each([
],
])(
'Only count lines with positioned chords when necessary',
(title, alignChordsWithLyrics, input, output) => {
(title, shouldAlignChords, input, output) => {
test(title, () => {
const parsedSong = parseSong(input);
let { allLines } = parsedSong;
Expand All @@ -229,9 +229,8 @@ describe.each([
(chord) => (chord.symbol = getChordSymbol(chord.model))
);

const maxBeatsWidth = getMaxBeatsWidth(
allLines,
alignChordsWithLyrics
const maxBeatsWidth = getMaxBeatsWidth(allLines, () =>
shouldAlignChords.shift()
);
expect(maxBeatsWidth).toEqual(output);
});
Expand Down

0 comments on commit 7baf959

Please sign in to comment.