Skip to content

Commit

Permalink
airbnb with rule to only warn on class-methods-use-this
Browse files Browse the repository at this point in the history
  • Loading branch information
rvilarl committed Mar 23, 2021
1 parent b33f489 commit 98e2206
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 41 deletions.
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
{
"files": [ "**/*.ts" ],
"extends": [
"eslint:recommended",
"eslint-config-airbnb-typescript/base",
"prettier"
],
"rules": {
"no-console": 1, // Means warning
"prettier/prettier": 2, // Means error
"class-methods-use-this": "warn"
}
},
{
"files": [ "src/**/*.js" ],
Expand Down
20 changes: 8 additions & 12 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module.exports = (grunt) => {
const TARGET_TESTS = path.join(BUILD_DIR, 'vexflow-tests.js');
const TEST_SOURCES = ['tests/vexflow_test_helpers.js', 'tests/mocks.js', 'tests/*_tests.js', 'tests/run.js'];

function webpackConfig(target, preset, mode) {
function webpackConfig(target, mode) {
return {
mode,
mode: mode,
entry: MODULE_ENTRY,
output: {
path: BUILD_DIR,
Expand All @@ -36,27 +36,23 @@ module.exports = (grunt) => {
libraryExport: 'default',
},
resolve: {
extensions: ['.ts', '.js', '.json']
extensions: ['.ts', '.js', '.json'],
},
devtool: process.env.VEX_GENMAP || mode === 'production' ? 'source-map' : false,
module: {
rules: [
{
test: /\.?s?$/,
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'ts-loader',
},
],
test: /(\.ts?$|\.js?$)/,
exclude: /node_modules/,
loader: 'ts-loader',
},
],
},
};
}

const webpackProd = webpackConfig(TARGET_MIN, ['@babel/preset-env'], 'production');
const webpackDev = webpackConfig(TARGET_RAW, ['@babel/preset-env'], 'development');
const webpackProd = webpackConfig(TARGET_MIN, 'production');
const webpackDev = webpackConfig(TARGET_RAW, 'development');

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"docco": "^0.8.0",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-airbnb-typescript": "^12.3.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"glob": "^7.1.6",
"grunt": "^1.0.4",
Expand Down
51 changes: 24 additions & 27 deletions src/music.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

import { Vex } from './vex';

export type KeyValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;

export type RootValue = 0 | 1 | 2 | 3 | 4 | 5 | 6;

export type AccidentalValue = -2 | -1 | 0 | 1 | 2;

export interface NoteAccidental {
note: number;
accidental: AccidentalValue;
Expand All @@ -16,12 +22,6 @@ export interface NoteParts {
type?: string;
}

export type KeyValue = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;

export type RootValue = 0 | 1 | 2 | 3 | 4 | 5 | 6;

export type AccidentalValue = -2 | -1 | 0 | 1 | 2;

export interface Key {
root_index: RootValue;
int_val: KeyValue;
Expand Down Expand Up @@ -202,11 +202,11 @@ export class Music {

getNoteParts(noteString: string): NoteParts {
if (!noteString || noteString.length < 1) {
throw new Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
throw new Vex.RERR('BadArguments', `Invalid note name: ${noteString}`);
}

if (noteString.length > 3) {
throw new Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
throw new Vex.RERR('BadArguments', `Invalid note name: ${noteString}`);
}

const note = noteString.toLowerCase();
Expand All @@ -222,14 +222,13 @@ export class Music {
root,
accidental,
};
} else {
throw new Vex.RERR('BadArguments', 'Invalid note name: ' + noteString);
}
throw new Vex.RERR('BadArguments', `Invalid note name: ${noteString}`);
}

getKeyParts(keyString: string): NoteParts {
if (!keyString || keyString.length < 1) {
throw new Vex.RERR('BadArguments', 'Invalid key: ' + keyString);
throw new Vex.RERR('BadArguments', `Invalid key: ${keyString}`);
}

const key = keyString.toLowerCase();
Expand All @@ -251,9 +250,8 @@ export class Music {
accidental,
type,
};
} else {
throw new Vex.RERR('BadArguments', `Invalid key: ${keyString}`);
}
throw new Vex.RERR('BadArguments', `Invalid key: ${keyString}`);
}

getNoteValue(noteString: string): number {
Expand Down Expand Up @@ -294,13 +292,13 @@ export class Music {
* relative note.
*/
getRelativeNoteValue(noteValue: number, intervalValue: number, direction?: number): number {
if (direction == null) direction = 1;
const dir = direction == null ? 1 : direction;

if (direction !== 1 && direction !== -1) {
if (dir !== 1 && dir !== -1) {
throw new Vex.RERR('BadArguments', `Invalid direction: ${direction}`);
}

let sum = (noteValue + direction * intervalValue) % Music.NUM_TONES;
let sum = (noteValue + dir * intervalValue) % Music.NUM_TONES;
if (sum < 0) sum += Music.NUM_TONES;

return sum;
Expand All @@ -316,12 +314,12 @@ export class Music {
if (interval > 0) multiplier = -1;

// Possibly wrap around. (Add +1 for modulo operator)
const reverse_interval = ((noteValue + 1 + (rootValue + 1)) % Music.NUM_TONES) * multiplier;
const reverseInterval = ((noteValue + 1 + (rootValue + 1)) % Music.NUM_TONES) * multiplier;

if (Math.abs(reverse_interval) > 2) {
if (Math.abs(reverseInterval) > 2) {
throw new Vex.RERR('BadArguments', `Notes not related: ${root}, ${noteValue})`);
} else {
interval = reverse_interval;
interval = reverseInterval;
}
}

Expand All @@ -331,11 +329,11 @@ export class Music {

let relativeNoteName = parts.root;
if (interval > 0) {
for (let i = 1; i <= interval; ++i) {
for (let i = 1; i <= interval; i += 1) {
relativeNoteName += '#';
}
} else if (interval < 0) {
for (let i = -1; i >= interval; --i) {
for (let i = -1; i >= interval; i -= 1) {
relativeNoteName += 'b';
}
}
Expand Down Expand Up @@ -368,17 +366,16 @@ export class Music {
* E.g., Given the scale C, and the note E, returns M3
*/
getIntervalBetween(note1: number, note2: number, direction?: number): number {
if (direction == null) direction = 1;
const dir = direction == null ? 1 : direction;

if (direction !== 1 && direction !== -1) {
if (dir !== 1 && dir !== -1) {
throw new Vex.RERR('BadArguments', `Invalid direction: ${direction}`);
}

if (!this.isValidNoteValue(note1) || !this.isValidNoteValue(note2)) {
throw new Vex.RERR('BadArguments', `Invalid notes: ${note1}, ${note2}`);
}

let difference = direction === 1 ? note2 - note1 : note1 - note2;
let difference = dir === 1 ? note2 - note1 : note1 - note2;

if (difference < 0) difference += Music.NUM_TONES;

Expand All @@ -397,13 +394,13 @@ export class Music {
let keySigString = keySigParts.root;
if (keySigParts.accidental) keySigString += keySigParts.accidental;

if (!scaleName) throw new Vex.RERR('BadArguments', 'Unsupported key type: ' + keySignature);
if (!scaleName) throw new Vex.RERR('BadArguments', `Unsupported key type: ${keySignature}`);

const scale = this.getScaleTones(this.getNoteValue(keySigString), scaleName);
const noteLocation = Music.root_indices[keySigParts.root];

const scaleMap = {} as Record<string, string>;
for (let i = 0; i < Music.roots.length; ++i) {
for (let i = 0; i < Music.roots.length; i += 1) {
const index = (noteLocation + i) % Music.roots.length;
const rootName = Music.roots[index];
let noteName = this.getRelativeNoteName(rootName, scale[i]);
Expand Down

0 comments on commit 98e2206

Please sign in to comment.