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

Enable typescript-eslint stylistic #1358

Merged
merged 2 commits into from
Sep 21, 2024
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
continue-on-error: true
strategy:
matrix:
node-version: [ 16.x, 18.x, 20.x, 22.x ]
node-version: [ 18.x, 20.x, 22.x ]
name: Ubuntu NodeJS ${{ matrix.node-version }} sample
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 5 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import tseslint from 'typescript-eslint';
export default tseslint.config(
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
{
rules: {
'quotes': ['error', 'single'],

'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
Expand All @@ -22,6 +26,7 @@ export default tseslint.config(
{
ignores: [
'lib/**/*',
'src/normalize_mappings/suffix-normalize-mapping.ts',
'src/parser/*/peg_parser.ts',
]
}
Expand Down
10 changes: 3 additions & 7 deletions src/chord_sheet/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ const END_TAG_TO_SECTION_TYPE = {
[END_OF_VERSE]: VERSE,
};

interface MapItemsCallback {
(_item: Item): Item | null;
}
type MapItemsCallback = (_item: Item) => Item | null;

interface MapLinesCallback {
(_line: Line): Line | null;
}
type MapLinesCallback = (_line: Line) => Line | null;

/**
* Represents a song in a chord sheet. Currently a chord sheet can only have one song.
Expand Down Expand Up @@ -139,7 +135,7 @@ class Song extends MetadataAccessors {
return this._bodyParagraphs;
}

selectRenderableItems(items: Array<Line | Paragraph>): Array<Line | Paragraph> {
selectRenderableItems(items: (Line | Paragraph)[]): (Line | Paragraph)[] {
const copy = [...items];

while (copy.length && !copy[0].hasRenderableItems()) {
Expand Down
2 changes: 1 addition & 1 deletion src/chord_sheet_serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class ChordSheetSerializer {
});
}

parseExpression(expression: Array<SerializedLiteral | SerializedTernary>): Array<AstType | null> {
parseExpression(expression: (SerializedLiteral | SerializedTernary)[]): (AstType | null)[] {
return (expression || [])
.map((part) => this.parseAstComponent(part))
.filter((part) => part !== null);
Expand Down
4 changes: 2 additions & 2 deletions src/formatter/html_formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import Song from '../chord_sheet/song';
import { scopeCss } from '../utilities';
import Paragraph from '../chord_sheet/paragraph';

export type HtmlTemplateArgs = {
export interface HtmlTemplateArgs {
configuration: Configuration;
song: Song;
renderBlankLines?: boolean;
bodyParagraphs: Paragraph[],
};
}

export type Template = (_args: HtmlTemplateArgs) => string;
export type CSS = Record<string, Record<string, string>>;
Expand Down
4 changes: 2 additions & 2 deletions src/formatter/templates/html_div_formatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HtmlTemplateArgs } from "../html_formatter";
import { HtmlTemplateArgs } from '../html_formatter';
import { renderChord } from '../../helpers';

import {
Expand All @@ -15,7 +15,7 @@ import {
stripHTML,
when,
} from '../../template_helpers';
import {isPresent} from "../../utilities";
import {isPresent} from '../../utilities';

export default (
{
Expand Down
2 changes: 1 addition & 1 deletion src/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ class Key implements KeyProperties {
return this.clone();
}

private set(attributes: KeyProperties, overwrite: boolean = true): Key {
private set(attributes: KeyProperties, overwrite = true): Key {
return new Key({
...(overwrite ? {} : attributes),
grade: this.grade,
Expand Down
4 changes: 2 additions & 2 deletions src/parser/chord_pro/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export function applySoftLineBreaks(lyrics: string): SerializedChordLyricsPair[]
export function breakChordLyricsPairOnSoftLineBreak(
chords: string,
lyrics: string,
): Array<SerializedChordLyricsPair | SerializedSoftLineBreak> {
): (SerializedChordLyricsPair | SerializedSoftLineBreak)[] {
const pairs =
applySoftLineBreaks(lyrics || '') as Array<SerializedChordLyricsPair | SerializedSoftLineBreak>;
applySoftLineBreaks(lyrics || '') as (SerializedChordLyricsPair | SerializedSoftLineBreak)[];
const [_first, ...rest] = pairs;
let first = pairs[0];
let addedLeadingChord: SerializedChordLyricsPair | null = null;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/chord_sheet_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ChordSheetParser {
*/
constructor(
{ preserveWhitespace = true }: { preserveWhitespace?: boolean } = {},
showDeprecationWarning: boolean = true,
showDeprecationWarning = true,
) {
if (showDeprecationWarning) {
deprecate(
Expand Down
18 changes: 9 additions & 9 deletions src/parser/chords_over_words/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@ type NewLine = CarriageReturn | LineFeed | CarriageReturnLineFeed;
type Lyrics = string;
type Chord = { column: number, value: string } & SerializedChord;

type RhythmSymbol = {
interface RhythmSymbol {
type: 'symbol',
value: '/' | '|' | '-' | 'x',
column: number,
};
}

type DirectionLine = SerializedLine;
type InlineMetadata = SerializedLine;

type ChordsLine = {
interface ChordsLine {
type: 'chordsLine',
items: Array<Chord | RhythmSymbol>
};
items: (Chord | RhythmSymbol)[]
}

type LyricsLine = {
interface LyricsLine {
type: 'lyricsLine',
content: Lyrics,
};
}

type ChordSheetLine = DirectionLine | InlineMetadata | ChordsLine | LyricsLine;

Expand All @@ -46,7 +46,7 @@ function combineChordSheetLines(
return [...emptyLines, ...lines, trailingLine].filter(x => x !== null);
}

function applySoftLineBreaks(line: string): Array<SerializedSoftLineBreak | SerializedChordLyricsPair | null> {
function applySoftLineBreaks(line: string): (SerializedSoftLineBreak | SerializedChordLyricsPair | null)[] {
return line
.split(/\\\s+/)
.flatMap((lyric, index) => ([
Expand All @@ -67,7 +67,7 @@ function chordProperties(chord: Chord): ChordProperties {
function constructChordLyricsPairs(
chords: Chord[],
lyrics: string,
): Array<SerializedChordLyricsPair | SerializedSoftLineBreak> {
): (SerializedChordLyricsPair | SerializedSoftLineBreak)[] {
return chords.map((chord, i) => {
const nextChord = chords[i + 1];
const start = chord.column - 1;
Expand Down
38 changes: 19 additions & 19 deletions src/serialized_types.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import { ChordType, Modifier } from './constants';

export type SerializedTraceInfo = {
export interface SerializedTraceInfo {
location?: {
offset: number | null,
line: number | null,
column: number | null,
},
};
}

export type SerializedChord = {
export interface SerializedChord {
type: 'chord',
base: string,
modifier: Modifier | null,
suffix: string | null,
bassBase: string | null,
bassModifier: Modifier | null,
chordType: ChordType,
};
}

export type SerializedChordLyricsPair = {
export interface SerializedChordLyricsPair {
type: 'chordLyricsPair',
chord?: SerializedChord | null,
chords: string,
lyrics: string | null,
annotation?: string | null,
};
}

export type SerializedTag = SerializedTraceInfo & {
type: 'tag',
name: string,
value: string,
};

export type SerializedComment = {
export interface SerializedComment {
type: 'comment',
comment: string,
};
}

export type ContentType = 'tab' | 'abc' | 'ly' | 'grid';

export type SerializedSection = {
export interface SerializedSection {
type: 'section',
sectionType: ContentType,
content: string[],
startTag: SerializedTag,
endTag: SerializedTag,
};
}

export type SerializedLiteral = string;

export interface SerializedTernary extends SerializedTraceInfo {
type: 'ternary',
variable: string | null,
valueTest: string | null,
trueExpression: Array<SerializedLiteral | SerializedTernary>,
falseExpression: Array<SerializedLiteral | SerializedTernary>,
trueExpression: (SerializedLiteral | SerializedTernary)[],
falseExpression: (SerializedLiteral | SerializedTernary)[],
}

export type SerializedComposite = Array<SerializedLiteral | SerializedTernary>;
export type SerializedComposite = (SerializedLiteral | SerializedTernary)[];

export type SerializedSoftLineBreak = {
export interface SerializedSoftLineBreak {
type: 'softLineBreak',
};
}

export type SerializedItem =
SerializedChordLyricsPair |
Expand All @@ -71,15 +71,15 @@ export type SerializedItem =
SerializedTag |
SerializedTernary;

export type SerializedLine = {
export interface SerializedLine {
type: 'line',
items: SerializedItem[],
};
}

export type SerializedSong = {
export interface SerializedSong {
type: 'chordSheet',
lines: SerializedLine[],
};
}

export type SerializedComponent =
SerializedLine |
Expand Down
4 changes: 1 addition & 3 deletions src/template_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import When from './template_helpers/when';
import { Literal } from './index';
import WhenCallback from './template_helpers/when_callback';

interface EachCallback {
(_item: any): string;
}
type EachCallback = (_item: any) => string;

export { hasChordContents, isEvaluatable } from './utilities';
export { renderChord } from './helpers';
Expand Down
2 changes: 1 addition & 1 deletion src/template_helpers/when.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import WhenClause from './when_clause';
import WhenCallback from './when_callback';

class When {
condition: boolean = false;
condition = false;

clauses: WhenClause[] = [];

Expand Down
4 changes: 1 addition & 3 deletions src/template_helpers/when_callback.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
interface WhenCallback {
(): string;
}
type WhenCallback = () => string;

export default WhenCallback;
8 changes: 4 additions & 4 deletions test/parser/chord_pro/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('breakChordLyricsPairOnSoftLineBreak', () => {
it('supports breaking a pair\'s lyrics on a soft line break', () => {
const chords = 'D/A';
const lyrics = 'I am \xA0a barber';
const items: Array<SerializedChordLyricsPair | SerializedSoftLineBreak> =
const items: (SerializedChordLyricsPair | SerializedSoftLineBreak)[] =
breakChordLyricsPairOnSoftLineBreak(chords, lyrics);

expect(items[0]).toEqual({ type: 'chordLyricsPair', chords: 'D/A', lyrics: 'I am ' });
Expand All @@ -45,7 +45,7 @@ describe('breakChordLyricsPairOnSoftLineBreak', () => {
it('supports a soft line break directly following a chord', () => {
const chords = 'D/A';
const lyrics = '\xA0a barber';
const items: Array<SerializedChordLyricsPair | SerializedSoftLineBreak> =
const items: (SerializedChordLyricsPair | SerializedSoftLineBreak)[] =
breakChordLyricsPairOnSoftLineBreak(chords, lyrics);

expect(items[0]).toEqual({ type: 'chordLyricsPair', chords: 'D/A', lyrics: '' });
Expand All @@ -56,7 +56,7 @@ describe('breakChordLyricsPairOnSoftLineBreak', () => {
it('supports a chord without lyrics', () => {
const chords = 'D/A';
const lyrics = '';
const items: Array<SerializedChordLyricsPair | SerializedSoftLineBreak> =
const items: (SerializedChordLyricsPair | SerializedSoftLineBreak)[] =
breakChordLyricsPairOnSoftLineBreak(chords, lyrics);

expect(items[0]).toEqual({ type: 'chordLyricsPair', chords: 'D/A', lyrics: '' });
Expand All @@ -65,7 +65,7 @@ describe('breakChordLyricsPairOnSoftLineBreak', () => {
it('returns an empty array when there are no chords or lyrics', () => {
const chords = '';
const lyrics = '';
const items: Array<SerializedChordLyricsPair | SerializedSoftLineBreak> =
const items: (SerializedChordLyricsPair | SerializedSoftLineBreak)[] =
breakChordLyricsPairOnSoftLineBreak(chords, lyrics);

expect(items).toEqual([]);
Expand Down
12 changes: 6 additions & 6 deletions test/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function createChordLyricsPair(chords, lyrics) {
return new ChordLyricsPair(chords, lyrics);
}

export function createTag(name: string, value: string = '') {
export function createTag(name: string, value = '') {
return new Tag(name, value);
}

Expand Down Expand Up @@ -93,7 +93,7 @@ export function createSongFromAst(lines: SerializedItem[][]): Song {
return new ChordSheetSerializer().deserialize(serializedSong);
}

export function tag(name: string, value: string = ''): SerializedTag {
export function tag(name: string, value = ''): SerializedTag {
return { type: 'tag', name, value };
}

Expand All @@ -115,7 +115,7 @@ export function section(
];
}

export function chordLyricsPair(chords: string, lyrics: string, annotation: string = ''): SerializedChordLyricsPair {
export function chordLyricsPair(chords: string, lyrics: string, annotation = ''): SerializedChordLyricsPair {
return {
type: 'chordLyricsPair', chords, lyrics, annotation,
};
Expand Down Expand Up @@ -151,11 +151,11 @@ export function softLineBreak(): SerializedSoftLineBreak {
return { type: 'softLineBreak' };
}

type TestCaseProps = {
interface TestCaseProps {
[key: string]: any;
outcome: any;
index: string;
};
}

export function eachTestCase(table: string, callback: (_testCase: TestCaseProps) => void): void {
const lines = table.trim().split('\n');
Expand Down Expand Up @@ -205,7 +205,7 @@ export function buildKey(
keyString: string | number,
keyType: ChordType,
modifier?: Modifier | null,
minor: boolean = false,
minor = false,
) {
const resolvedKey = Key.resolve({
key: keyString,
Expand Down