Skip to content

Commit

Permalink
Merge 7f764c3 into 8a04978
Browse files Browse the repository at this point in the history
  • Loading branch information
no-chris committed Aug 29, 2021
2 parents 8a04978 + 7f764c3 commit 1b857d9
Show file tree
Hide file tree
Showing 88 changed files with 2,948 additions and 1,482 deletions.
88 changes: 45 additions & 43 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
module.exports = {
'env': {
'browser': true,
'es6': true
env: {
browser: true,
es6: true,
},

'extends': [
'eslint:recommended'
],
extends: ['eslint:recommended'],

'plugins': [
'import',
'no-unsanitized'
],
plugins: ['import', 'no-unsanitized'],

'globals': {
'Atomics': 'readonly',
'SharedArrayBuffer': 'readonly'
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},

'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module'
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},

'rules': {
'complexity': [ 'error', { max: 10 } ],
'indent': [ 'error', 'tab', { 'SwitchCase': 1 } ],
'linebreak-style': [ 'error', 'unix' ],
'max-depth': [ 'error', 4 ],
'max-len': [ 'error', {'code': 150 } ],
'max-lines': [ 'error', { max: 300, skipBlankLines: true, skipComments: true, } ],
'max-lines-per-function': [ 'warn', { max: 50, skipBlankLines: true, skipComments: true, }],
'max-params': [ 'warn', { max: 4 } ],
'no-shadow': [ 'error', { 'builtinGlobals': true } ],
'quotes': [ 'error', 'single' ],
'semi': [ 'error', 'always'],

'no-restricted-imports': [
rules: {
complexity: ['error', { max: 10 }],
indent: ['error', 'tab', { SwitchCase: 1 }],
'linebreak-style': ['error', 'unix'],
'max-depth': ['error', 4],
'max-len': ['error', { code: 150 }],
'max-lines': [
'error',
{ max: 300, skipBlankLines: true, skipComments: true },
],
'max-lines-per-function': [
'warn',
{ max: 50, skipBlankLines: true, skipComments: true },
],
'max-params': ['warn', { max: 4 }],
'no-shadow': ['error', { builtinGlobals: true }],
semi: ['error', 'always'],

'no-restricted-imports': [
'error',
{
paths: [
{
name: 'lodash',
message: 'Please do not import lodash as a whole: import individual lodash functions instead.'
}
]
}
message:
'Please do not import lodash as a whole: import individual lodash functions instead.',
},
],
},
],

'no-unsanitized/property': [ 'error', { escape: { methods: ['escapeHTML'] } } ],
'no-unsanitized/method': [ 'error' ],

'no-unsanitized/property': [
'error',
{ escape: { methods: ['escapeHTML'] } },
],
'no-unsanitized/method': ['error'],

'import/no-restricted-paths': [ 'error',
'import/no-restricted-paths': [
'error',
{
'zones': [
{ 'target': './src/parser', 'from': './src/renderer' },
]
}
zones: [{ target: './src/parser', from: './src/renderer' }],
},
],
}
},
};
7 changes: 7 additions & 0 deletions .idea/prettier.xml

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

6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage
CHANGELOG.md
lib
package.json
package-lock.json
SLOC
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"endOfLine": "lf",
"semi": true,
"singleQuote": true,
"tabWidth": 4,
"trailingComma": "es5",
"useTabs": true
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
The best way to write chords charts

Finally chords charts that are:
- easy to write
- complete and accurate, with bar information

- easy to write
- complete and accurate, with bar information
24 changes: 10 additions & 14 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
/* eslint-env node */
module.exports = {
testEnvironment: 'jsdom',

collectCoverage: true,
collectCoverageFrom: [
'src/**/*.js',
'!**/node_modules/**'
],
collectCoverageFrom: ['src/**/*.js', '!**/node_modules/**'],
coverageDirectory: '<rootDir>/coverage',
coveragePathIgnorePatterns: ['node_modules'],
coverageReporters: ['json', 'lcov', 'text', 'clover'],
coverageThreshold: {
'global': {
'branches': 99,
'functions': 100,
'lines': 100,
'statements': 0
}
global: {
branches: 99,
functions: 100,
lines: 100,
statements: 0,
},
},

transform: {
Expand All @@ -25,7 +22,6 @@ module.exports = {
},

moduleNameMapper: {
'\\.(css|scss)$': '<rootDir>/scss/__mocks__/styleMock.js'
}

'\\.(css|scss)$': '<rootDir>/scss/__mocks__/styleMock.js',
},
};
6 changes: 6 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"jest-handlebars": "^1.0.1",
"mini-css-extract-plugin": "^2.0.0",
"node-sass": "^6.0.1",
"prettier": "^2.3.2",
"raw-loader": "^4.0.2",
"sass": "^1.32.13",
"sass-loader": "^12.1.0",
Expand All @@ -53,6 +54,7 @@
"tiny-emitter": "^2.1.0"
},
"scripts": {
"format": "prettier --write \"**/*.{js,jsx,json,ts,md}\"",
"lint": "eslint src tests",
"test": "jest",
"bundle-js": "webpack",
Expand Down
2 changes: 1 addition & 1 deletion src/core/addEventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function addEventEmitter(object) {

emit(eventName, ...args) {
this._emitter.emit(eventName, ...args);
}
},
};

return Object.assign(object, eventEmitter);
Expand Down
2 changes: 1 addition & 1 deletion src/core/dom/htmlToElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import domPurify from 'dompurify';

export default function htmlToElement(html) {
return domPurify.sanitize(html, {
RETURN_DOM_FRAGMENT: true
RETURN_DOM_FRAGMENT: true,
}).firstChild;
}
30 changes: 17 additions & 13 deletions src/parser/exceptions/IncorrectBeatCountException.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@ import _isString from 'lodash/isString';
import _isFinite from 'lodash/isFinite';

export default class IncorrectBeatCountException extends Error {
constructor(
{
string,
duration,
currentBeatCount,
beatCount
} = {}
) {
constructor({ string, duration, currentBeatCount, beatCount } = {}) {
if (!string || !_isString(string)) {
throw new TypeError('IncorrectBeatCountException cannot be created without chord string, received: ' + string);
throw new TypeError(
'IncorrectBeatCountException cannot be created without chord string, received: ' +
string
);
}
if (!duration || !_isFinite(duration)) {
throw new TypeError('IncorrectBeatCountException cannot be created without chord duration, received: ' + duration);
throw new TypeError(
'IncorrectBeatCountException cannot be created without chord duration, received: ' +
duration
);
}
if (!currentBeatCount || !_isFinite(currentBeatCount)) {
throw new TypeError('IncorrectBeatCountException cannot be created without currentBeatCount, received: ' + currentBeatCount);
throw new TypeError(
'IncorrectBeatCountException cannot be created without currentBeatCount, received: ' +
currentBeatCount
);
}
if (!beatCount || !_isFinite(beatCount)) {
throw new TypeError('IncorrectBeatCountException cannot be created without beatCount, received: ' + beatCount);
throw new TypeError(
'IncorrectBeatCountException cannot be created without beatCount, received: ' +
beatCount
);
}

super();
Expand All @@ -32,4 +37,3 @@ export default class IncorrectBeatCountException extends Error {
this.beatCount = beatCount;
}
}

12 changes: 5 additions & 7 deletions src/parser/exceptions/InvalidChordRepetitionException.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import _isString from 'lodash/isString';

export default class InvalidChordRepetitionException extends Error {
constructor(
{
string,
} = {}
) {
constructor({ string } = {}) {
if (!string || !_isString(string)) {
throw new TypeError('InvalidChordRepetitionException cannot be created without chord string, received: ' + string);
throw new TypeError(
'InvalidChordRepetitionException cannot be created without chord string, received: ' +
string
);
}

super();
Expand All @@ -16,4 +15,3 @@ export default class InvalidChordRepetitionException extends Error {
this.string = string;
}
}

6 changes: 3 additions & 3 deletions src/parser/getAllChordsInSong.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export default function getAllChordsInSong(allLines) {
const allChords = [];
let i;

forEachChordInSong(allLines, chord => {
i = _findIndex(allChords, o => _isEqual(o.model, chord.model));
forEachChordInSong(allLines, (chord) => {
i = _findIndex(allChords, (o) => _isEqual(o.model, chord.model));

if (i === -1) {
allChords.push({
model: _cloneDeep(chord.model),
occurrences: 1
occurrences: 1,
});
} else {
allChords[i].occurrences++;
Expand Down
7 changes: 2 additions & 5 deletions src/parser/helper/clearSpaces.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export default function clearSpaces(string) {
return string
.replace(/\t+/g, ' ')
.replace(/ +/g, ' ')
.trim();
}
return string.replace(/\t+/g, ' ').replace(/ +/g, ' ').trim();
}
21 changes: 9 additions & 12 deletions src/parser/helper/songs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import lineTypes from '../lineTypes';
export function forEachChordInSong(allLines, fn) {
const newLines = _cloneDeep(allLines);

newLines.forEach(line => {
newLines.forEach((line) => {
if (line.type === lineTypes.CHORD) {
line.model.allBars.forEach(bar => {
bar.allChords.forEach(chord => {
line.model.allBars.forEach((bar) => {
bar.allChords.forEach((chord) => {
fn(chord);
});
});
Expand All @@ -22,7 +22,6 @@ export function forEachChordInSong(allLines, fn) {
return newLines;
}


/**
* @param {ChordLine} chordLine
* @param {Function} fn - to execute on each chord
Expand All @@ -31,16 +30,15 @@ export function forEachChordInSong(allLines, fn) {
export function forEachChordInChordLine(chordLine, fn) {
const newChordLine = _cloneDeep(chordLine);

newChordLine.allBars.forEach(bar => {
bar.allChords.forEach(chord => {
fn(chord);
newChordLine.allBars.forEach((bar, barIndex) => {
bar.allChords.forEach((chord, chordIndex) => {
fn(chord, chordIndex, barIndex);
});
});

return newChordLine;
}


/**
* @param {SongLine[]} allLines
* @param {String} label - the label to select
Expand All @@ -54,18 +52,17 @@ export function getNthOfLabel(allLines, label, n) {
let enableSelect = false;
let currentLabel = '';

allLines.forEach(line => {
allLines.forEach((line) => {
if (line.type === lineTypes.SECTION_LABEL) {
currentLabel = line.model.label;

if (! typesCount[currentLabel]) {
if (!typesCount[currentLabel]) {
typesCount[currentLabel] = 1;
} else {
typesCount[currentLabel]++;
}

enableSelect = (line.id === (label + n));

enableSelect = line.id === label + n;
} else if (enableSelect) {
selected.push(line);
}
Expand Down
Loading

0 comments on commit 1b857d9

Please sign in to comment.