Skip to content

Commit

Permalink
lint: configure eslintrc, fix all lint errors, remove tslint from pro…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
sschmid committed Jan 20, 2021
1 parent d6f51d8 commit bae72d2
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 64 deletions.
8 changes: 4 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = {
"error",
{
"multiline": {
"delimiter": "none",
"delimiter": "semi",
"requireLast": true
},
"singleline": {
Expand Down Expand Up @@ -119,7 +119,7 @@ module.exports = {
],*/
"id-match": "error",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
"jsdoc/check-indentation": "off",
"jsdoc/newline-after-description": "off",
"max-len": [
"error",
Expand Down Expand Up @@ -162,10 +162,10 @@ module.exports = {
"no-fallthrough": "error",
"no-multiple-empty-lines": "off",
"no-new-wrappers": "error",
"no-null/no-null": "error",
"no-null/no-null": "off",
"no-redeclare": "error",
"no-trailing-spaces": "error",
"no-underscore-dangle": "error",
"no-underscore-dangle": "off",
"no-unused-labels": "error",
"no-var": "error",
"prefer-const": "error",
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"typings": "build/dist/src/",
"scripts": {
"docs": "typedoc --out ./build/docs --name OpenSheetMusicDisplay --module commonjs --target ES2017 --ignoreCompilerErrors --mode file ./src",
"eslint": "eslint .",
"eslint": "eslint . --ext .ts src/",
"lint": "eslint -c .eslintrc.js --ext .ts src/",
"test": "karma start --single-run --no-auto-watch",
"test:watch": "karma start --no-single-run --auto-watch --browsers ChromeNoSecurity",
Expand Down Expand Up @@ -109,8 +109,6 @@
"pre-commit": "^1.2.2",
"svg2pdf.js": "^1.5.0",
"ts-loader": "^4.1.0",
"tslint": "^5.14.0",
"tslint-loader": "^3.5.4",
"typedoc": "^0.17.3",
"typescript": "^3.9.5",
"webpack": "^4.43.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Common/DataObjects/Fraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class Fraction {
* @param denominator
* @param wholeValue - the integer number, needed for values greater than 1
* @param simplify - If simplify is true, then the fraction is simplified
* to make both the numerator and denominator coprime, and less than maximumAllowedNumber.
* to make both the numerator and denominator coprime, and less than maximumAllowedNumber.
*/
constructor(numerator: number = 0, denominator: number = 1, wholeValue: number = 0, simplify: boolean = true) {
this.numerator = numerator;
Expand Down
8 changes: 4 additions & 4 deletions src/Common/DataObjects/Pitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum NoteEnum {
/** Describes Accidental types.
* Do not use the number values of these enum members directly for calculation anymore.
* To use these for pitch calculation, use pitch.AccidentalHalfTones()
* or Pitch.HalfTonesFromAccidental(accidentalEnum).
* or Pitch.HalfTonesFromAccidental(accidentalEnum).
*/
export enum AccidentalEnum {
SHARP,
Expand Down Expand Up @@ -70,15 +70,15 @@ export class Pitch {
* @param the input pitch
* @param the number of halftones to transpose with
* @returns ret[0] = the transposed fundamental.
* ret[1] = the octave shift (not the new octave!)
* ret[1] = the octave shift (not the new octave!)
* @constructor
*/
public static CalculateTransposedHalfTone(pitch: Pitch, transpose: number): { halftone: number; overflow: number; } {
public static CalculateTransposedHalfTone(pitch: Pitch, transpose: number): { halftone: number, overflow: number } {
const newHalfTone: number = <number>pitch.fundamentalNote + pitch.AccidentalHalfTones + transpose;
return Pitch.WrapAroundCheck(newHalfTone, 12);
}

public static WrapAroundCheck(value: number, limit: number): { halftone: number; overflow: number; } {
public static WrapAroundCheck(value: number, limit: number): { halftone: number, overflow: number } {
let overflow: number = 0;

while (value < 0) {
Expand Down
1 change: 0 additions & 1 deletion src/MusicalScore/Graphical/DrawingEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export enum OutlineAndFillStyleEnum {
Comment10
}

// tslint:disable-next-line:max-line-length A linebreak would be more confusing here
export const OUTLINE_AND_FILL_STYLE_DICT: Dictionary<OutlineAndFillStyleEnum, string> =
new Dictionary<OutlineAndFillStyleEnum, string>();
OUTLINE_AND_FILL_STYLE_DICT.setValue(OutlineAndFillStyleEnum.BaseWritingColor, "Thistle");
Expand Down
4 changes: 2 additions & 2 deletions src/MusicalScore/Graphical/EngravingRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ export class EngravingRules {
public MaxInstructionsConstValue: number;
public NoteDistances: number[] = [1.0, 1.0, 1.3, 1.6, 2.0, 2.5, 3.0, 4.0];
public NoteDistancesScalingFactors: number[] = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0];
public DurationDistanceDict: {[_: number]: number; } = {};
public DurationScalingDistanceDict: {[_: number]: number; } = {};
public DurationDistanceDict: {[_: number]: number } = {};
public DurationScalingDistanceDict: {[_: number]: number } = {};

public AlignRests: number; // 0 = false, 1 = true, 2 = auto
public FillEmptyMeasuresWithWholeRest: FillEmptyMeasuresWithWholeRests | number;
Expand Down
3 changes: 1 addition & 2 deletions src/MusicalScore/Graphical/GraphicalMusicSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ export class GraphicalMusicSheet {
const containers: VerticalGraphicalStaffEntryContainer[] = this.verticalGraphicalStaffEntryContainers;
let leftIndex: number = 0;
let rightIndex: number = containers.length - 1;
let foundIndex: number;
let leftTS: Fraction = undefined;
let rightTS: Fraction = undefined;
if (musicTimestamp.lte(containers[containers.length - 1].AbsoluteTimestamp)) {
Expand Down Expand Up @@ -429,7 +428,7 @@ export class GraphicalMusicSheet {
const diffTS: number = rightTS.RealValue - musicTimestamp.RealValue;

// estimate the interpolated index
foundIndex = rightIndex - (diffTS / diff);
const foundIndex: number = rightIndex - (diffTS / diff);
return Math.min(foundIndex, this.verticalGraphicalStaffEntryContainers.length);
}

Expand Down
10 changes: 4 additions & 6 deletions src/MusicalScore/Graphical/GraphicalSlur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ export class GraphicalSlur extends GraphicalCurve {
// clockwise/counterclockwise Rotation
// after Rotation end2.Y must be 0
// Inverse of RotationMatrix = TransposeMatrix of RotationMatrix
let rotationMatrix: Matrix2D, transposeMatrix: Matrix2D;
rotationMatrix = Matrix2D.getRotationMatrix(startEndLineAngleRadians);
transposeMatrix = rotationMatrix.getTransposeMatrix();
const rotationMatrix: Matrix2D = Matrix2D.getRotationMatrix(startEndLineAngleRadians);
const transposeMatrix: Matrix2D = rotationMatrix.getTransposeMatrix();
end2 = rotationMatrix.vectorMultiplication(end2);
const transformedPoints: PointF2D[] = this.calculateTranslatedAndRotatedPointListAbove(points, startX, startY, rotationMatrix);

Expand Down Expand Up @@ -323,9 +322,8 @@ export class GraphicalSlur extends GraphicalCurve {
// clockwise/counterclockwise Rotation
// after Rotation end2.Y must be 0
// Inverse of RotationMatrix = TransposeMatrix of RotationMatrix
let rotationMatrix: Matrix2D, transposeMatrix: Matrix2D;
rotationMatrix = Matrix2D.getRotationMatrix(-startEndLineAngleRadians);
transposeMatrix = rotationMatrix.getTransposeMatrix();
const rotationMatrix: Matrix2D = Matrix2D.getRotationMatrix(-startEndLineAngleRadians);
const transposeMatrix: Matrix2D = rotationMatrix.getTransposeMatrix();
end2 = rotationMatrix.vectorMultiplication(end2);
const transformedPoints: PointF2D[] = this.calculateTranslatedAndRotatedPointListBelow(points, startX, startY, rotationMatrix);

Expand Down
4 changes: 0 additions & 4 deletions src/MusicalScore/Graphical/MusicSheetCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2331,11 +2331,7 @@ export abstract class MusicSheetCalculator {
accidentalCalculator.checkAccidental(graphicalNote, pitch);
}

// // needed to disable linter, as it doesn't recognize the existing usage of this method.
// // ToDo: check if a newer version doesn't have the problem.
// /* tslint:disable:no-unused-variable */
// private createStaffEntryForTieNote(measure: StaffMeasure, absoluteTimestamp: Fraction, openTie: Tie): GraphicalStaffEntry {
// /* tslint:enable:no-unused-variable */
// let graphicalStaffEntry: GraphicalStaffEntry;
// graphicalStaffEntry = MusicSheetCalculator.symbolFactory.createStaffEntry(openTie.Start.ParentStaffEntry, measure);
// graphicalStaffEntry.relInMeasureTimestamp = Fraction.minus(absoluteTimestamp, measure.parentSourceMeasure.AbsoluteTimestamp);
Expand Down
12 changes: 6 additions & 6 deletions src/MusicalScore/Graphical/VexFlow/VexFlowMeasure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
/** octaveOffset according to active clef */
public octaveOffset: number = 3;
/** The VexFlow Voices in the measure */
public vfVoices: { [voiceID: number]: Vex.Flow.Voice; } = {};
public vfVoices: { [voiceID: number]: Vex.Flow.Voice } = {};
/** Call this function (if present) to x-format all the voices in the measure */
public formatVoices: (width: number, parent: VexFlowMeasure) => void;
/** The VexFlow Ties in the measure */
Expand All @@ -74,17 +74,17 @@ export class VexFlowMeasure extends GraphicalMeasure {
/** VexFlow StaveConnectors (vertical lines) */
protected connectors: Vex.Flow.StaveConnector[] = [];
/** Intermediate object to construct beams */
private beams: { [voiceID: number]: [Beam, VexFlowVoiceEntry[]][]; } = {};
private beams: { [voiceID: number]: [Beam, VexFlowVoiceEntry[]][] } = {};
/** Beams created by (optional) autoBeam function. */
private autoVfBeams: Vex.Flow.Beam[];
/** Beams of tuplet notes created by (optional) autoBeam function. */
private autoTupletVfBeams: Vex.Flow.Beam[];
/** VexFlow Beams */
private vfbeams: { [voiceID: number]: Vex.Flow.Beam[]; };
private vfbeams: { [voiceID: number]: Vex.Flow.Beam[] };
/** Intermediate object to construct tuplets */
protected tuplets: { [voiceID: number]: [Tuplet, VexFlowVoiceEntry[]][]; } = {};
protected tuplets: { [voiceID: number]: [Tuplet, VexFlowVoiceEntry[]][] } = {};
/** VexFlow Tuplets */
private vftuplets: { [voiceID: number]: Vex.Flow.Tuplet[]; } = {};
private vftuplets: { [voiceID: number]: Vex.Flow.Tuplet[] } = {};
// The engraving rules of OSMD.
public rules: EngravingRules;

Expand Down Expand Up @@ -1243,7 +1243,7 @@ export class VexFlowMeasure extends GraphicalMeasure {
protected createOrnaments(): void {
for (let idx: number = 0, len: number = this.staffEntries.length; idx < len; ++idx) {
const graphicalStaffEntry: VexFlowStaffEntry = (this.staffEntries[idx] as VexFlowStaffEntry);
const gvoices: { [voiceID: number]: GraphicalVoiceEntry; } = graphicalStaffEntry.graphicalVoiceEntries;
const gvoices: { [voiceID: number]: GraphicalVoiceEntry } = graphicalStaffEntry.graphicalVoiceEntries;

for (const voiceID in gvoices) {
if (gvoices.hasOwnProperty(voiceID)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {
if (!measure) {
continue;
}
const mvoices: { [voiceID: number]: Vex.Flow.Voice; } = (measure as VexFlowMeasure).vfVoices;
const mvoices: { [voiceID: number]: Vex.Flow.Voice } = (measure as VexFlowMeasure).vfVoices;
const voices: Vex.Flow.Voice[] = [];
for (const voiceID in mvoices) {
if (mvoices.hasOwnProperty(voiceID)) {
Expand Down Expand Up @@ -1045,7 +1045,7 @@ export class VexFlowMusicSheetCalculator extends MusicSheetCalculator {

// Generate all Graphical Slurs and attach them to the staffline
protected calculateSlurs(): void {
const openSlursDict: { [staffId: number]: GraphicalSlur[]; } = {};
const openSlursDict: { [staffId: number]: GraphicalSlur[] } = {};
for (const graphicalMeasure of this.graphicalMusicSheet.MeasureList[0]) { //let i: number = 0; i < this.graphicalMusicSheet.MeasureList[0].length; i++) {
openSlursDict[graphicalMeasure.ParentStaff.idInMusicSheet] = [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/MusicalScore/Graphical/VexFlow/VexFlowVoiceEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class VexFlowVoiceEntry extends GraphicalVoiceEntry {
}
}
if (colorBeam) {
if (vfStaveNote.beam !== null && vfStaveNote.beam.setStyle) {
if (vfStaveNote.beam?.setStyle) {
vfStaveNote.beam.setStyle({ fillStyle: noteheadColor, strokeStyle: noteheadColor});
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/MusicalScore/ScoreIO/InstrumentReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class InstrumentReader {
private musicSheet: MusicSheet;
private slurReader: SlurReader;
private instrument: Instrument;
private voiceGeneratorsDict: { [n: number]: VoiceGenerator; } = {};
private voiceGeneratorsDict: { [n: number]: VoiceGenerator } = {};
private staffMainVoiceGeneratorDict: { [staffId: number]: VoiceGenerator } = {};
private inSourceMeasureInstrumentIndex: number;
private divisions: number = 0;
Expand Down Expand Up @@ -252,10 +252,8 @@ export class InstrumentReader {
let noteTypeXml: NoteType = NoteType.UNDEFINED;
if (typeNode) {
const sizeAttr: Attr = typeNode.attribute("size");
if (sizeAttr !== undefined && sizeAttr !== null) {
if (sizeAttr.value === "cue") {
isCueNote = true;
}
if (sizeAttr?.value === "cue") {
isCueNote = true;
}
noteTypeXml = NoteTypeHandler.StringToNoteType(typeNode.value);
}
Expand Down
3 changes: 2 additions & 1 deletion src/MusicalScore/ScoreIO/MusicSheetReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
}

private initializeReading(partList: IXmlElement[], partInst: IXmlElement[], instrumentReaders: InstrumentReader[]): void {
const instrumentDict: { [_: string]: Instrument; } = this.createInstrumentGroups(partList);
const instrumentDict: { [_: string]: Instrument } = this.createInstrumentGroups(partList);
this.completeNumberOfStaves = this.getCompleteNumberOfStavesFromXml(partInst);
if (partInst.length !== 0) {
this.repetitionInstructionReader.MusicSheet = this.musicSheet;
Expand Down Expand Up @@ -571,6 +571,7 @@ export class MusicSheetReader /*implements IMusicSheetReader*/ {
}
const creditJustify: string = creditChild.attribute("justify")?.value;
const creditY: string = creditChild.attribute("default-y")?.value;
// eslint-disable-next-line no-null/no-null
const creditYGiven: boolean = creditY !== undefined && creditY !== null;
const creditYInfo: number = creditYGiven ? parseFloat(creditY) : Number.MIN_VALUE;
if (creditYGiven && creditYInfo > systemYCoordinates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class ArticulationReader {
currentTechnicalInstruction.value = nodeFingering.value;
currentTechnicalInstruction.placement = PlacementEnum.NotYetDefined;
const placement: Attr = nodeFingering.attribute("placement");
if (placement !== undefined && placement !== null) {
if (placement) {
switch (placement.value) {
case "above":
currentTechnicalInstruction.placement = PlacementEnum.Above;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class ChordSymbolReader {
let rootAlteration: AccidentalEnum = AccidentalEnum.NONE;
if (rootAlter) {
try {
rootAlteration = Pitch.AccidentalFromHalfTones(parseInt(rootAlter.value, undefined));
rootAlteration = Pitch.AccidentalFromHalfTones(parseInt(rootAlter.value, 10));
} catch (ex) {
const errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ChordSymbolError",
"Invalid chord symbol");
Expand Down Expand Up @@ -94,7 +94,7 @@ export class ChordSymbolReader {
let bassAlteration: AccidentalEnum = AccidentalEnum.NONE;
if (bassAlter) {
try {
bassAlteration = Pitch.AccidentalFromHalfTones(parseInt(bassAlter.value, undefined));
bassAlteration = Pitch.AccidentalFromHalfTones(parseInt(bassAlter.value, 10));
} catch (ex) {
const errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ChordSymbolError",
"Invalid chord symbol");
Expand All @@ -118,7 +118,7 @@ export class ChordSymbolReader {

let value: number;
try {
value = parseInt(degreeValue.value.trim(), undefined);
value = parseInt(degreeValue.value.trim(), 10);
} catch (ex) {
const errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ChordSymbolError",
"Invalid chord symbol");
Expand All @@ -129,7 +129,7 @@ export class ChordSymbolReader {

let alter: AccidentalEnum;
try {
alter = Pitch.AccidentalFromHalfTones(parseInt(degreeAlter.value, undefined));
alter = Pitch.AccidentalFromHalfTones(parseInt(degreeAlter.value, 10));
} catch (ex) {
const errorMsg: string = ITextTranslation.translateText("ReaderErrorMessages/ChordSymbolError",
"Invalid chord symbol");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class ExpressionReader {
}

const placeAttr: IXmlAttribute = xmlNode.attribute("placement");
if (placeAttr !== undefined && placeAttr !== null) {
if (placeAttr) {
try {
const placementString: string = placeAttr.value;
if (placementString === "below") {
Expand All @@ -96,21 +96,21 @@ export class ExpressionReader {
const dynamicsNode: IXmlElement = directionTypeNode.element("dynamics");
if (dynamicsNode) {
const defAttr: IXmlAttribute = dynamicsNode.attribute("default-y");
if (defAttr !== undefined && defAttr !== null) {
if (defAttr) {
this.readExpressionPlacement(defAttr, "read dynamics y pos");
}
}
const wedgeNode: IXmlElement = directionTypeNode.element("wedge");
if (wedgeNode) {
const defAttr: IXmlAttribute = wedgeNode.attribute("default-y");
if (defAttr !== undefined && defAttr !== null) {
if (defAttr) {
this.readExpressionPlacement(defAttr, "read wedge y pos");
}
}
const wordsNode: IXmlElement = directionTypeNode.element("words");
if (wordsNode) {
const defAttr: IXmlAttribute = wordsNode.attribute("default-y");
if (defAttr !== undefined && defAttr !== null) {
if (defAttr) {
this.readExpressionPlacement(defAttr, "read words y pos");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ITextTranslation} from "../../Interfaces/ITextTranslation";
import {MusicSheet} from "../../MusicSheet";

export class LyricsReader {
private openLyricWords: { [_: number]: LyricWord; } = {};
private openLyricWords: { [_: number]: LyricWord } = {};
private currentLyricWord: LyricWord;
private musicSheet: MusicSheet;

Expand Down
1 change: 0 additions & 1 deletion src/MusicalScore/VoiceData/NoteType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export enum NoteType {
}

export class NoteTypeHandler {
// tslint:disable-next-line: variable-name
public static NoteTypeXmlValues: string[] = ["", "1024th", "512th", "256th", "128th", "64th", "32nd", "16th",
"eigth", "quarter", "half", "whole", "breve", "long", "maxima"];
// alternative to array: use switch/case
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSheetMusicDisplay/OSMDOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FontStyles } from "../Common/Enums/FontStyles";
/** Possible options for the OpenSheetMusicDisplay constructor and osmd.setOptions(). None are mandatory.
* Note that after using setOptions(), you have to call osmd.render() again to make changes visible.
* Example: osmd.setOptions({defaultColorRest: "#AAAAAA", drawSubtitle: false}); osmd.render();
*
*
* Note that some additional, usually more small scale options are available in EngravingRules,
* though not all of them are meant to be manipulated.
* The OSMDOptions are the main options we support.
Expand Down
Loading

0 comments on commit bae72d2

Please sign in to comment.