Skip to content

Commit 0ca06e5

Browse files
author
Brian Kelly
authored
Update linter and add Prettier (#24)
1 parent d483f0b commit 0ca06e5

File tree

10 files changed

+4561
-2594
lines changed

10 files changed

+4561
-2594
lines changed

.eslintrc.js

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
11
module.exports = {
2-
"env": {
3-
"browser": true,
4-
"es6": true,
5-
"node": true,
6-
"jest": true,
7-
},
8-
"extends": "eslint:recommended",
9-
"parserOptions": {
10-
"ecmaVersion": 2015,
11-
"sourceType": "module"
12-
},
13-
"rules": {
14-
"indent": [
15-
"error",
16-
4
17-
],
18-
"linebreak-style": [
19-
"error",
20-
"unix"
21-
],
22-
"quotes": [
23-
"error",
24-
"single"
25-
],
26-
"semi": [
27-
"error",
28-
"always"
29-
]
30-
}
31-
};
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
node: true,
6+
jest: true,
7+
},
8+
extends: ["standard", "prettier"],
9+
parserOptions: {
10+
ecmaVersion: "latest",
11+
sourceType: "module",
12+
},
13+
plugins: ["jest"],
14+
rules: {},
15+
};

package-lock.json

Lines changed: 4334 additions & 2365 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,21 @@
1616
"build": "npm run lint && npm test && npm run webpack"
1717
},
1818
"devDependencies": {
19-
"@babel/core": "7.15.0",
20-
"@babel/preset-env": "7.15.0",
21-
"@babel/preset-react": "7.14.5",
22-
"babel-loader": "8.2.2",
23-
"eslint": "7.32.0",
24-
"jest": "27.0.6",
25-
"lodash": "4.17.21",
26-
"webpack": "5.51.1",
27-
"webpack-cli": "4.8.0"
19+
"@babel/core": "^7.17.9",
20+
"@babel/preset-env": "^7.16.11",
21+
"@babel/preset-react": "^7.16.7",
22+
"babel-loader": "^8.2.4",
23+
"eslint": "^7.32.0",
24+
"eslint-config-prettier": "^8.5.0",
25+
"eslint-config-standard": "^16.0.3",
26+
"eslint-plugin-import": "^2.26.0",
27+
"eslint-plugin-jest": "^26.1.4",
28+
"eslint-plugin-node": "^11.1.0",
29+
"eslint-plugin-promise": "^6.0.0",
30+
"jest": "^27.5.1",
31+
"lodash": "^4.17.21",
32+
"prettier": "^2.6.2",
33+
"webpack": "^5.72.0",
34+
"webpack-cli": "^4.9.2"
2835
}
2936
}

src/Line.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export class Line {
2-
constructor() {
3-
this.parts = [];
4-
}
2+
constructor() {
3+
this.parts = [];
4+
}
55
}

src/Part.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export class Part {
2-
constructor() {
3-
this.chord = null;
4-
this.lyric = null;
5-
}
2+
constructor() {
3+
this.chord = null;
4+
this.lyric = null;
5+
}
66
}

src/Section.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export class Section {
2-
constructor(name) {
3-
this.name = name;
4-
this.lines = [];
5-
}
2+
constructor(name) {
3+
this.name = name;
4+
this.lines = [];
5+
}
66
}

src/Song.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export class Song {
2-
constructor() {
3-
this.attrs = {};
4-
this.sections = [];
5-
this.custom = {};
6-
}
7-
}
2+
constructor() {
3+
this.attrs = {};
4+
this.sections = [];
5+
this.custom = {};
6+
}
7+
}

src/SongPro.js

Lines changed: 89 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,118 @@
1-
import {Song} from './Song';
2-
import {Section} from './Section';
3-
import {Line} from './Line';
4-
import {chunk, flatten, trim} from 'lodash';
5-
import {Part} from './Part';
1+
import { Song } from "./Song";
2+
import { Section } from "./Section";
3+
import { Line } from "./Line";
4+
import { chunk, flatten, trim } from "lodash";
5+
import { Part } from "./Part";
66

77
export class SongPro {
8-
static parse(text) {
9-
let song = new Song();
10-
let currentSection = null;
11-
12-
const lines = text.split('\n');
13-
14-
for (let i = 0; i < lines.length; i++) {
15-
let text = lines[i];
16-
17-
if (text.startsWith('@')) {
18-
this.processAttribute(song, text);
19-
} else if (text.startsWith('!')) {
20-
this.processCustomAttribute(song, text);
21-
} else if (text.startsWith('#')) {
22-
currentSection = this.processSection(song, text);
23-
} else {
24-
this.processLyricsAndChords(song, currentSection, text);
25-
}
26-
}
27-
28-
return song;
8+
static parse(text) {
9+
const song = new Song();
10+
let currentSection = null;
11+
12+
const lines = text.split("\n");
13+
14+
for (let i = 0; i < lines.length; i++) {
15+
const text = lines[i];
16+
17+
if (text.startsWith("@")) {
18+
this.processAttribute(song, text);
19+
} else if (text.startsWith("!")) {
20+
this.processCustomAttribute(song, text);
21+
} else if (text.startsWith("#")) {
22+
currentSection = this.processSection(song, text);
23+
} else {
24+
this.processLyricsAndChords(song, currentSection, text);
25+
}
2926
}
3027

31-
static processAttribute(song, line) {
32-
const matches = /@(\w*)=([^%]*)/.exec(line);
28+
return song;
29+
}
3330

34-
if (matches == null) {
35-
return;
36-
}
31+
static processAttribute(song, line) {
32+
const matches = /@(\w*)=([^%]*)/.exec(line);
3733

38-
song.attrs[matches[1]] = matches[2];
34+
if (matches == null) {
35+
return;
3936
}
4037

41-
static processCustomAttribute(song, line) {
42-
const matches = /!(\w*)=([^%]*)/.exec(line);
38+
song.attrs[matches[1]] = matches[2];
39+
}
4340

44-
if (matches == null) {
45-
return;
46-
}
41+
static processCustomAttribute(song, line) {
42+
const matches = /!(\w*)=([^%]*)/.exec(line);
4743

48-
song.custom[matches[1]] = matches[2];
44+
if (matches == null) {
45+
return;
4946
}
5047

51-
static processSection(song, line) {
52-
const matches = /#\s*([^$]*)/.exec(line);
48+
song.custom[matches[1]] = matches[2];
49+
}
5350

54-
if (matches == null) {
55-
return;
56-
}
51+
static processSection(song, line) {
52+
const matches = /#\s*([^$]*)/.exec(line);
5753

58-
let name = matches[1];
59-
let currentSection = new Section(name);
60-
song.sections.push(currentSection);
61-
62-
return currentSection;
54+
if (matches == null) {
55+
return;
6356
}
6457

65-
static processLyricsAndChords(song, currentSection, text) {
66-
if (text === '') {
67-
return;
68-
}
58+
const name = matches[1];
59+
const currentSection = new Section(name);
60+
song.sections.push(currentSection);
6961

70-
if (currentSection == null) {
71-
currentSection = new Section('');
72-
song.sections.push(currentSection);
73-
}
62+
return currentSection;
63+
}
7464

75-
let line = new Line();
65+
static processLyricsAndChords(song, currentSection, text) {
66+
if (text === "") {
67+
return;
68+
}
7669

77-
let captures = this.scan(text, /(\[[\w#b/]+])?([\w\s',.!()_\-"]*)/gi);
78-
captures = flatten(captures);
79-
let groups = chunk(captures, 2);
70+
if (currentSection == null) {
71+
currentSection = new Section("");
72+
song.sections.push(currentSection);
73+
}
8074

75+
const line = new Line();
8176

82-
for (let i = 0; i < groups.length; i++) {
83-
let group = groups[i];
84-
let chord = group[0];
85-
let lyric = group[1];
77+
let captures = this.scan(text, /(\[[\w#b/]+])?([\w\s',.!()_\-"]*)/gi);
78+
captures = flatten(captures);
79+
const groups = chunk(captures, 2);
8680

87-
let part = new Part();
81+
for (let i = 0; i < groups.length; i++) {
82+
const group = groups[i];
83+
let chord = group[0];
84+
let lyric = group[1];
8885

89-
if (chord) {
90-
chord = chord.replace('[', '').replace(']', '');
91-
}
86+
const part = new Part();
9287

93-
if (chord === undefined) {
94-
chord = '';
95-
}
96-
if (lyric === undefined) {
97-
lyric = '';
98-
}
88+
if (chord) {
89+
chord = chord.replace("[", "").replace("]", "");
90+
}
9991

100-
part.chord = trim(chord);
101-
part.lyric = trim(lyric);
92+
if (chord === undefined) {
93+
chord = "";
94+
}
95+
if (lyric === undefined) {
96+
lyric = "";
97+
}
10298

103-
if (!(part.chord === '' && part.lyric === '')) {
104-
line.parts.push(part);
105-
}
106-
}
99+
part.chord = trim(chord);
100+
part.lyric = trim(lyric);
107101

108-
currentSection.lines.push(line);
102+
if (!(part.chord === "" && part.lyric === "")) {
103+
line.parts.push(part);
104+
}
109105
}
110106

111-
static scan(string, regex) {
112-
if (!regex.global) throw new Error('regex must have \'global\' flag set');
113-
var results = [];
114-
string.replace(regex, function () {
115-
results.push(Array.prototype.slice.call(arguments, 1, -2));
116-
});
117-
return results;
118-
}
119-
}
107+
currentSection.lines.push(line);
108+
}
109+
110+
static scan(string, regex) {
111+
if (!regex.global) throw new Error("regex must have 'global' flag set");
112+
const results = [];
113+
string.replace(regex, function () {
114+
results.push(Array.prototype.slice.call(arguments, 1, -2));
115+
});
116+
return results;
117+
}
118+
}

0 commit comments

Comments
 (0)