Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply some ignored eslint rules #1184

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions __tests__/TestData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// I want to reformat these arrays as tables but I have no idea how
// to do it automatically, and I'm sure not doing it manually.

var validSignal = new Float32Array([
const validSignal = new Float32Array([
0.210053,
0.177877,
0.164105,
Expand Down Expand Up @@ -517,7 +517,7 @@ var validSignal = new Float32Array([
-0.0591427,
]);

var validAmpSpec = new Float32Array([
const validAmpSpec = new Float32Array([
0.19665084779262543,
0.2347041368484497,
0.8820229172706604,
Expand Down Expand Up @@ -776,7 +776,7 @@ var validAmpSpec = new Float32Array([
0.00631281454116106,
]);

var validFFT = {
const validFFT = {
real: new Float32Array([
-0.19665084779262543,
-0.19752468168735504,
Expand Down Expand Up @@ -1808,7 +1808,7 @@ var validFFT = {
length: 512,
};

var expectedPowerSpectrumOutput = new Float32Array([
const expectedPowerSpectrumOutput = new Float32Array([
0.03867155686020851,
0.055086031556129456,
0.7779644131660461,
Expand Down Expand Up @@ -2067,7 +2067,7 @@ var expectedPowerSpectrumOutput = new Float32Array([
0.00003985162766184658,
]);

var barkScale = new Float32Array([
const barkScale = new Float32Array([
0,
0.8502324223518372,
1.694183111190796,
Expand Down
3 changes: 2 additions & 1 deletion __tests__/exports-node.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* This is required to trick typescript into thinking this file is a module
* rather than a script. If this file is a script, it won't get its own scope
Expand Down Expand Up @@ -29,7 +30,7 @@ const EXPECTED_EXPORTS = [

describe("package exports", () => {
test("meyda node exports at least currently expected fields", () => {
var meyda = require("../dist/node/main");
const meyda = require("../dist/node/main");

expect(Object.keys(meyda)).toEqual(EXPECTED_EXPORTS);
});
Expand Down
7 changes: 4 additions & 3 deletions __tests__/exports-web.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @jest-environment jsdom
*/
/* eslint-disable @typescript-eslint/no-var-requires */

/**
* This is required to trick typescript into thinking this file is a module
Expand Down Expand Up @@ -34,7 +35,7 @@ const EXPECTED_EXPORTS = [
describe("package exports", () => {
test("meyda web exports at least currently expected fields", () => {
expect(window["Meyda"]).not.toBeDefined();
var meyda = require("../dist/web/meyda");
const meyda = require("../dist/web/meyda");

expect(Object.keys(meyda)).toEqual(EXPECTED_EXPORTS);
expect(Object.keys(window["Meyda"])).toEqual(EXPECTED_EXPORTS);
Expand All @@ -44,7 +45,7 @@ describe("package exports", () => {

test("meyda web min exports at least currently expected fields", () => {
expect(global["Meyda"]).not.toBeDefined();
var meyda = require("../dist/web/meyda.min");
const meyda = require("../dist/web/meyda.min");

expect(Object.keys(meyda)).toEqual(EXPECTED_EXPORTS);
expect(Object.keys(global["Meyda"])).toEqual(EXPECTED_EXPORTS);
Expand All @@ -55,7 +56,7 @@ describe("package exports", () => {

describe("package exports", () => {
test("meyda node exports at least currently expected fields", () => {
var meyda = require("../dist/node/main");
const meyda = require("../dist/node/main");

expect(Object.keys(meyda)).toEqual(EXPECTED_EXPORTS);
expect(Object.keys(global["Meyda"])).toEqual(EXPECTED_EXPORTS);
Expand Down
17 changes: 10 additions & 7 deletions __tests__/extractors/chroma.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import TestData from "../TestData";
var utilities = require("../../dist/node/utilities");
import * as utilities from "../../dist/node/utilities";

// Setup
var chroma = require("../../dist/node/extractors/chroma");
import chroma from "../../dist/node/extractors/chroma";

describe("chroma", () => {
test("should return correct chroma value given a valid signal", (done) => {
var chromagram = chroma({
const chromagram = chroma({
sampleRate: 44100,
bufferSize: 512,
ampSpectrum: TestData.VALID_AMPLITUDE_SPECTRUM,
chromaFilterBank: utilities.createChromaFilterBank(12, 44100, 512),
});

for (var i in TestData.EXPECTED_CHROMAGRAM_OUTPUT) {
for (const i in TestData.EXPECTED_CHROMAGRAM_OUTPUT) {
expect(
Math.abs(chromagram[i] - TestData.EXPECTED_CHROMAGRAM_OUTPUT[i])
).toBeLessThanOrEqual(1e-5);
Expand All @@ -24,23 +24,26 @@ describe("chroma", () => {

test("should throw an error when passed an empty object", (done) => {
try {
var chromagram = chroma({});
const chromagram = chroma({});
chromagram;
} catch (e) {
done();
}
});

test("should throw an error when not passed anything", (done) => {
try {
var chromagram = chroma();
const chromagram = chroma();
chromagram;
} catch (e) {
done();
}
});

test("should throw an error when passed something invalid", (done) => {
try {
var chromagram = chroma({ ampSpectrum: "not a signal" });
const chromagram = chroma({ ampSpectrum: "not a signal" });
chromagram;
} catch (e) {
done();
}
Expand Down
13 changes: 8 additions & 5 deletions __tests__/extractors/energy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import TestData from "../TestData";

// Setup
var energy = require("../../dist/node/extractors/energy");
import energy from "../../dist/node/extractors/energy";

describe("energy", () => {
test("should return the correct value given a valid signal", (done) => {
var en = energy({
const en = energy({
signal: TestData.VALID_SIGNAL,
});

Expand All @@ -16,23 +16,26 @@ describe("energy", () => {

test("should throw an error when passed an empty object", (done) => {
try {
var en = energy({});
const en = energy({});
en;
} catch (e) {
done();
}
});

test("should throw an error when not passed anything", (done) => {
try {
var en = energy();
const en = energy();
en;
} catch (e) {
done();
}
});

test("should throw an error when passed something invalid", (done) => {
try {
var en = energy({ signal: "not a signal" });
const en = energy({ signal: "not a signal" });
en;
} catch (e) {
done();
}
Expand Down
13 changes: 8 additions & 5 deletions __tests__/extractors/loudness.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import TestData from "../TestData";

// Setup
var loudness = require("../../dist/node/extractors/loudness");
import loudness from "../../dist/node/extractors/loudness";

describe("loudness", () => {
test("should return correct value given a valid signal", (done) => {
var en = loudness({
const en = loudness({
ampSpectrum: TestData.VALID_AMPLITUDE_SPECTRUM,
barkScale: TestData.VALID_BARK_SCALE,
});
Expand All @@ -29,23 +29,26 @@ describe("loudness", () => {

test("should throw an error when passed an empty object", (done) => {
try {
var en = loudness({});
const en = loudness({});
en;
} catch (e) {
done();
}
});

test("should throw an error when not passed anything", (done) => {
try {
var en = loudness();
const en = loudness();
en;
} catch (e) {
done();
}
});

test("should throw an error when passed something invalid", (done) => {
try {
var en = loudness({ signal: "not a signal" });
const en = loudness({ signal: "not a signal" });
en;
} catch (e) {
done();
}
Expand Down
25 changes: 14 additions & 11 deletions __tests__/extractors/mfcc.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import TestData from "../TestData";
var utilities = require("../../dist/node/utilities");
import * as utilities from "../../dist/node/utilities";

// Setup
var mfcc = require("../../dist/node/extractors/mfcc");
import mfcc from "../../dist/node/extractors/mfcc";

describe("mfcc", () => {
test("should return correct mfcc value given a valid signal", (done) => {
var en = mfcc({
const en = mfcc({
sampleRate: 44100,
bufferSize: 512,
ampSpectrum: TestData.VALID_AMPLITUDE_SPECTRUM,
Expand All @@ -23,7 +23,7 @@ describe("mfcc", () => {

expect(expectedValues.length).toEqual(en.length);

for (var index in en) {
for (const index in en) {
expect(Math.abs(en[index] - expectedValues[index])).toBeLessThanOrEqual(
1e-15
);
Expand All @@ -33,7 +33,7 @@ describe("mfcc", () => {
});

test("should return only 3 correct mfcc values given a valid signal", (done) => {
var en = mfcc({
const en = mfcc({
sampleRate: 44100,
bufferSize: 512,
ampSpectrum: TestData.VALID_AMPLITUDE_SPECTRUM,
Expand All @@ -47,7 +47,7 @@ describe("mfcc", () => {

expect(expectedValues.length).toEqual(en.length);

for (var index in en) {
for (const index in en) {
expect(Math.abs(en[index] - expectedValues[index])).toBeLessThanOrEqual(
1e-15
);
Expand All @@ -57,7 +57,7 @@ describe("mfcc", () => {
});

test("should return only 40 correct mfcc values given a valid signal", (done) => {
var en = mfcc({
const en = mfcc({
sampleRate: 44100,
bufferSize: 512,
ampSpectrum: TestData.VALID_AMPLITUDE_SPECTRUM,
Expand All @@ -84,7 +84,7 @@ describe("mfcc", () => {

expect(expectedValues.length).toEqual(en.length);

for (var index in en) {
for (const index in en) {
expect(Math.abs(en[index] - expectedValues[index])).toBeLessThanOrEqual(
1e-15
);
Expand All @@ -95,23 +95,26 @@ describe("mfcc", () => {

test("should throw an error when passed an empty object", (done) => {
try {
var en = mfcc({});
const en = mfcc({});
en;
} catch (e) {
done();
}
});

test("should throw an error when not passed anything", (done) => {
try {
var en = mfcc();
const en = mfcc();
en;
} catch (e) {
done();
}
});

test("should throw an error when passed something invalid", (done) => {
try {
var en = mfcc({ signal: "not a signal" });
const en = mfcc({ signal: "not a signal" });
en;
} catch (e) {
done();
}
Expand Down
13 changes: 8 additions & 5 deletions __tests__/extractors/perceptualSharpness.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import TestData from "../TestData";

// Setup
var percSharp = require("../../dist/node/extractors/perceptualSharpness");
import percSharp from "../../dist/node/extractors/perceptualSharpness";

describe("percSharp", () => {
test("should return percSharp value given a valid signal", (done) => {
var en = percSharp({
const en = percSharp({
signal: TestData.VALID_SIGNAL,
ampSpectrum: TestData.VALID_AMPLITUDE_SPECTRUM,
barkScale: TestData.VALID_BARK_SCALE,
Expand All @@ -18,23 +18,26 @@ describe("percSharp", () => {

test("should throw an error when passed an empty object", (done) => {
try {
var en = percSharp({});
const en = percSharp({});
en;
} catch (e) {
done();
}
});

test("should throw an error when not passed anything", (done) => {
try {
var en = percSharp();
const en = percSharp();
en;
} catch (e) {
done();
}
});

test("should throw an error when passed something invalid", (done) => {
try {
var en = percSharp({ signal: "not a signal" });
const en = percSharp({ signal: "not a signal" });
en;
} catch (e) {
done();
}
Expand Down