Skip to content

Remove unused imports and unused vars #1347

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

Merged
merged 4 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tone/component/analysis/DCMeter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";

import { BasicTests, warns } from "../../../test/helper/Basic.js";
import { BasicTests } from "../../../test/helper/Basic.js";
import { PassAudio } from "../../../test/helper/PassAudio.js";
import { Signal } from "../../signal/Signal.js";
import { DCMeter } from "./DCMeter.js";
Expand Down
2 changes: 0 additions & 2 deletions Tone/component/analysis/Meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { expect } from "chai";

import { BasicTests, warns } from "../../../test/helper/Basic.js";
import { PassAudio } from "../../../test/helper/PassAudio.js";
import { Signal } from "../../signal/Signal.js";
import { Oscillator } from "../../source/oscillator/Oscillator.js";
import { Merge } from "../channel/Merge.js";
import { Panner } from "../channel/Panner.js";
import { Meter } from "./Meter.js";

describe("Meter", () => {
Expand Down
1 change: 0 additions & 1 deletion Tone/component/envelope/AmplitudeEnvelope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from "chai";

import { BasicTests } from "../../../test/helper/Basic.js";
import { CompareToFile } from "../../../test/helper/CompareToFile.js";
import { connectFrom, connectTo } from "../../../test/helper/Connect.js";
import { Offline } from "../../../test/helper/Offline.js";
import { Signal } from "../../signal/Signal.js";
import { Oscillator } from "../../source/oscillator/Oscillator.js";
Expand Down
1 change: 0 additions & 1 deletion Tone/component/filter/EQ3.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from "chai";

import { BasicTests } from "../../../test/helper/Basic.js";
import { connectFrom } from "../../../test/helper/Connect.js";
import { PassAudio } from "../../../test/helper/PassAudio.js";
import { EQ3 } from "./EQ3.js";

Expand Down
1 change: 1 addition & 0 deletions Tone/core/clock/Ticker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class Ticker {
if (this._type === "worker") {
try {
this._createWorker();
// eslint-disable-next-line unused-imports/no-unused-vars
} catch (e) {
// workers not supported, fallback to timeout
this._type = "timeout";
Expand Down
6 changes: 2 additions & 4 deletions Tone/core/clock/TransportRepeatEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class TransportRepeatEvent extends TransportEvent {
*/
invoke(time: Seconds): void {
// create more events if necessary
this._createEvents(time);
this._createEvents();
// call the super class
super.invoke(time);
}
Expand All @@ -107,9 +107,7 @@ export class TransportRepeatEvent extends TransportEvent {
/**
* Push more events onto the timeline to keep up with the position of the timeline
*/
private _createEvents(time: Seconds): void {
// schedule the next event
// const ticks = this.transport.getTicksAtTime(time);
private _createEvents(): void {
// if the next tick is within the bounds set by "duration"
if (
LT(this._nextTick + this._interval, this.floatTime + this.duration)
Expand Down
9 changes: 1 addition & 8 deletions Tone/core/context/Param.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { expect } from "chai";

import { BasicTests, testAudioContext } from "../../../test/helper/Basic.js";
import { Compare, Plot } from "../../../test/helper/compare/index.js";
import { Plot } from "../../../test/helper/compare/index.js";
import { atTime, Offline } from "../../../test/helper/Offline.js";
import { Signal } from "../../signal/Signal.js";
import { getContext } from "../Global.js";
import {
BPM,
Decibels,
Frequency,
Positive,
Seconds,
Time,
Unit,
UnitName,
} from "../type/Units.js";
import { Param } from "./Param.js";
Expand Down
1 change: 0 additions & 1 deletion Tone/core/context/ToneWithContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { TransportClass } from "../clock/Transport.js";
import { getContext } from "../Global.js";
import { Tone } from "../Tone.js";
import { FrequencyClass } from "../type/Frequency.js";
Expand Down
13 changes: 12 additions & 1 deletion Tone/core/util/Draw.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ import { expect } from "chai";
import { DrawClass } from "./Draw.js";

describe("Draw", () => {
const originalRAF = window.requestAnimationFrame;
before(async () => {
window.requestAnimationFrame = (callback) => {
return setTimeout(callback, 10);
};
});

after(() => {
window.requestAnimationFrame = originalRAF;
});

it("can schedule a callback at a AudioContext time", (done) => {
const draw = new DrawClass();
const scheduledTime = draw.now() + 0.2;
draw.schedule(() => {
done();
expect(draw.context.currentTime).to.be.closeTo(scheduledTime, 0.05);
draw.dispose();
done();
}, scheduledTime);
});

Expand Down
22 changes: 10 additions & 12 deletions Tone/event/PatternGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type PatternName =
/**
* Start at the first value and go up to the last
*/
function* upPatternGen<T>(numValues: number): IterableIterator<number> {
function* upPatternGen(numValues: number): IterableIterator<number> {
let index = 0;
while (index < numValues) {
index = clamp(index, 0, numValues - 1);
Expand All @@ -30,7 +30,7 @@ function* upPatternGen<T>(numValues: number): IterableIterator<number> {
/**
* Start at the last value and go down to 0
*/
function* downPatternGen<T>(numValues: number): IterableIterator<number> {
function* downPatternGen(numValues: number): IterableIterator<number> {
let index = numValues - 1;
while (index >= 0) {
index = clamp(index, 0, numValues - 1);
Expand All @@ -42,7 +42,7 @@ function* downPatternGen<T>(numValues: number): IterableIterator<number> {
/**
* Infinitely yield the generator
*/
function* infiniteGen<T>(
function* infiniteGen(
numValues: number,
gen: typeof upPatternGen
): IterableIterator<number> {
Expand All @@ -54,7 +54,7 @@ function* infiniteGen<T>(
/**
* Alternate between two generators
*/
function* alternatingGenerator<T>(
function* alternatingGenerator(
numValues: number,
directionUp: boolean
): IterableIterator<number> {
Expand All @@ -79,7 +79,7 @@ function* alternatingGenerator<T>(
/**
* Starting from the bottom move up 2, down 1
*/
function* jumpUp<T>(numValues: number): IterableIterator<number> {
function* jumpUp(numValues: number): IterableIterator<number> {
let index = 0;
let stepIndex = 0;
while (index < numValues) {
Expand All @@ -93,7 +93,7 @@ function* jumpUp<T>(numValues: number): IterableIterator<number> {
/**
* Starting from the top move down 2, up 1
*/
function* jumpDown<T>(numValues: number): IterableIterator<number> {
function* jumpDown(numValues: number): IterableIterator<number> {
let index = numValues - 1;
let stepIndex = 0;
while (index >= 0) {
Expand All @@ -107,7 +107,7 @@ function* jumpDown<T>(numValues: number): IterableIterator<number> {
/**
* Choose a random index each time
*/
function* randomGen<T>(numValues: number): IterableIterator<number> {
function* randomGen(numValues: number): IterableIterator<number> {
while (true) {
const randomIndex = Math.floor(Math.random() * numValues);
yield randomIndex;
Expand All @@ -117,7 +117,7 @@ function* randomGen<T>(numValues: number): IterableIterator<number> {
/**
* Randomly go through all of the values once before choosing a new random order
*/
function* randomOnce<T>(numValues: number): IterableIterator<number> {
function* randomOnce(numValues: number): IterableIterator<number> {
// create an array of indices
const copy: number[] = [];
for (let i = 0; i < numValues; i++) {
Expand All @@ -134,7 +134,7 @@ function* randomOnce<T>(numValues: number): IterableIterator<number> {
/**
* Randomly choose to walk up or down 1 index
*/
function* randomWalk<T>(numValues: number): IterableIterator<number> {
function* randomWalk(numValues: number): IterableIterator<number> {
// randomly choose a starting index
let index = Math.floor(Math.random() * numValues);
while (true) {
Expand All @@ -157,12 +157,10 @@ function* randomWalk<T>(numValues: number): IterableIterator<number> {
* according to the passed in pattern that can be used as indexes into an array of size numValues.
* @param numValues The size of the array to emit indexes for
* @param pattern The name of the pattern use when iterating over
* @param index Where to start in the offset of the values array
*/
export function* PatternGenerator(
numValues: number,
pattern: PatternName = "up",
index = 0
pattern: PatternName = "up"
): Iterator<number> {
// safeguards
assert(numValues >= 1, "The number of values must be at least one");
Expand Down
3 changes: 1 addition & 2 deletions Tone/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export { getContext, setContext } from "./core/Global.js";
import { Context } from "./core/context/Context.js";
export * from "./classes.js";
export { getContext, setContext } from "./core/Global.js";
export * from "./version.js";
import { ToneAudioBuffer } from "./core/context/ToneAudioBuffer.js";
import { getContext } from "./core/Global.js";
Expand Down
1 change: 0 additions & 1 deletion Tone/signal/Abs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BasicTests } from "../../test/helper/Basic.js";
import { connectFrom, connectTo } from "../../test/helper/Connect.js";
import { ConstantOutput } from "../../test/helper/ConstantOutput.js";
import { Abs } from "./Abs.js";
import { Signal } from "./Signal.js";
Expand Down
1 change: 0 additions & 1 deletion Tone/signal/AudioToGain.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect } from "chai";

import { BasicTests } from "../../test/helper/Basic.js";
import { connectFrom, connectTo } from "../../test/helper/Connect.js";
import { ConstantOutput } from "../../test/helper/ConstantOutput.js";
import { Offline } from "../../test/helper/Offline.js";
import { Oscillator } from "../source/oscillator/Oscillator.js";
Expand Down
1 change: 0 additions & 1 deletion Tone/signal/GainToAudio.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { BasicTests } from "../../test/helper/Basic.js";
import { connectFrom, connectTo } from "../../test/helper/Connect.js";
import { ConstantOutput } from "../../test/helper/ConstantOutput.js";
import { GainToAudio } from "./GainToAudio.js";
import { Signal } from "./Signal.js";
Expand Down
2 changes: 0 additions & 2 deletions Tone/signal/Signal.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { expect } from "chai";

import { BasicTests } from "../../test/helper/Basic.js";
import { connectFrom, connectTo } from "../../test/helper/Connect.js";
import { ConstantOutput } from "../../test/helper/ConstantOutput.js";
import { Offline } from "../../test/helper/Offline.js";
import { Gain } from "../core/context/Gain.js";
import { Decibels, Frequency, Time } from "../core/type/Units.js";
import { Signal } from "./Signal.js";

describe("Signal", () => {
Expand Down
3 changes: 2 additions & 1 deletion Tone/signal/SyncedSignal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { TransportClass } from "../core/clock/Transport.js";
import "../core/clock/Transport.js";

import { OutputNode } from "../core/context/ToneAudioNode.js";
import { TransportTimeClass } from "../core/type/TransportTime.js";
import {
Expand Down
17 changes: 15 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// @ts-check
import tseslint from "typescript-eslint";
import stylisticJs from "@stylistic/eslint-plugin-js";
import stylisticTs from "@stylistic/eslint-plugin-ts";
import jsdoc from "eslint-plugin-jsdoc";
import html from "eslint-plugin-html";
import jsdoc from "eslint-plugin-jsdoc";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import unusedImports from "eslint-plugin-unused-imports";
import tseslint from "typescript-eslint";

/** @type {import("typescript-eslint").ConfigWithExtends} */
const customConfig = {
Expand All @@ -15,6 +16,7 @@ const customConfig = {
jsdoc,
html,
"simple-import-sort": simpleImportSort,
"unused-imports": unusedImports,
},
rules: {
"@typescript-eslint/array-type": "off",
Expand Down Expand Up @@ -86,6 +88,16 @@ const customConfig = {
},
},
],
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [
"warn",
{
vars: "all",
varsIgnorePattern: "^_",
args: "after-used",
argsIgnorePattern: "^_",
},
],
},
};

Expand All @@ -96,6 +108,7 @@ export default tseslint.config(
files: ["**/*.test.ts", "./test/**/*.ts"],
rules: {
"@typescript-eslint/no-unused-expressions": "off",
"unused-imports/no-unused-vars": "off",
},
},
{
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"eslint-plugin-html": "^8.1.2",
"eslint-plugin-jsdoc": "^50.6.11",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-unused-imports": "^4.1.4",
"fft-windowing": "^0.1.4",
"fourier-transform": "^1.1.2",
"fs-fixture": "^2.7.1",
Expand Down
1 change: 0 additions & 1 deletion test/helper/Connect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Gain } from "../../Tone/core/context/Gain.js";
import { ToneAudioNode } from "../../Tone/core/context/ToneAudioNode.js";

export function connectFrom(): Gain {
return new Gain();
Expand Down
1 change: 0 additions & 1 deletion test/helper/MonophonicTests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { expect } from "chai";

import { Monophonic } from "../../Tone/instrument/Monophonic.js";
import { Offline } from "./Offline.js";

export function MonophonicTest(Constr, note, constrArg?): void {
Expand Down
2 changes: 1 addition & 1 deletion test/helper/SourceTests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// import APITest from "helper/APITest";
import { expect } from "chai";

import { connectFrom, connectTo } from "./Connect.js";
import { connectTo } from "./Connect.js";
import { Offline } from "./Offline.js";
import { OutputAudio } from "./OutputAudio.js";

Expand Down
1 change: 0 additions & 1 deletion test/web-test-runner.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { resolve } from "node:path";
import { fileURLToPath } from "node:url";

import rollupCommonjs from "@rollup/plugin-commonjs";
import { esbuildPlugin } from "@web/dev-server-esbuild";
import { fromRollup } from "@web/dev-server-rollup";
import { puppeteerLauncher } from "@web/test-runner-puppeteer";

Expand Down