Showing 75 of 84 total issues

Function write has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    write: async (frame, stream) => {
        const value = <IID3V2.FrameValue.RVA>frame.value;
        const flags = [
            0,
            0,
Severity: Minor
Found in src/lib/id3v2/frames/implementations/id3v2.frame.rva.ts - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function writeRawFrame has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

async function writeRawFrame(frame: IID3V2.Frame, head: IID3V2.TagHeader, defaultEncoding?: string): Promise<IID3V2.RawFrame> {
    const frameHead: IID3V2.FrameHeader = frame.head || {
        size: 0,
        statusFlags: {},
        formatFlags: {}
Severity: Minor
Found in src/lib/id3v2/frames/id3v2.frame.write.ts - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function readFullMPEGFrame has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    private readFullMPEGFrame(chunk: Buffer, pos: number, header: IMP3.FrameRawHeader): boolean {
        if (this.demandData(chunk, pos)) {
            return true;
        }
        header.offset = this.stream.pos - chunk.length + pos;
Severity: Minor
Found in src/lib/mp3/mp3.reader.ts - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function analyzeXING has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    private analyzeXING(data: IMP3.Result, ignoreXingOffOne: boolean): Array<IMP3Analyzer.Warning> {
        if (!data.mpeg || !data.frames) {
            return [];
        }
        const head = data.frames.headers[0];
Severity: Minor
Found in src/lib/mp3/mp3.analyzer.ts - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function parse has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    parse: async (reader, frame) => {
        if (frame.data.length === 0) {
            return {value: {}};
        }
        const flags = reader.readBitsByte();
Severity: Minor
Found in src/lib/id3v2/frames/implementations/id3v2.frame.rva.ts - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function analyzeID3v1 has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    private analyzeID3v1(data: IMP3.Result): Array<IMP3Analyzer.Warning> {
        const result: Array<IMP3Analyzer.Warning> = [];
        const lastframe: IMP3.FrameRawHeaderArray | undefined = data.frames && data.frames.audio.length > 0 ? data.frames.audio[data.frames.audio.length - 1] : undefined;
        if (data.raw && lastframe) {
            const audioEnd = rawHeaderOffSet(lastframe) + rawHeaderSize(lastframe);
Severity: Minor
Found in src/lib/mp3/mp3.analyzer.ts - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

WriterStream has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

export class WriterStream {
    protected wstream: fs.WriteStream;

    constructor() {
        this.wstream = new MemoryStream();
Severity: Minor
Found in src/lib/common/stream-writer.ts - About 2 hrs to fix

    File mp3.reader.ts has 261 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import {Readable} from 'stream';
    import fse from 'fs-extra';
    
    import {IMP3} from './mp3.types';
    import {ID3v1Reader} from '../id3v1/id3v1.reader';
    Severity: Minor
    Found in src/lib/mp3/mp3.reader.ts - About 2 hrs to fix

      Function writeRawFrame has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async function writeRawFrame(frame: IID3V2.Frame, head: IID3V2.TagHeader, defaultEncoding?: string): Promise<IID3V2.RawFrame> {
          const frameHead: IID3V2.FrameHeader = frame.head || {
              size: 0,
              statusFlags: {},
              formatFlags: {}
      Severity: Major
      Found in src/lib/id3v2/frames/id3v2.frame.write.ts - About 2 hrs to fix

        Function expandMPEGFrameFlags has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function expandMPEGFrameFlags(front: number, back: number, offset: number): IMP3.FrameRawHeader | null {
            // AAAAAAAA: frame sync must be 11111111
            // AAA: frame sync must be 111
            const hasSync = (front & 0xFFE0) === 0xFFE0;
            const validVer = (front & 0x18) !== 0x8;
        Severity: Major
        Found in src/lib/mp3/mp3.mpeg.frame.ts - About 2 hrs to fix

          Function removeTags has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async removeTags(filename: string, options: IMP3.RemoveTagsOptions): Promise<IMP3.RemoveResult | undefined> {
                  const stat = await fse.stat(filename);
                  const opts: MP3ReaderOptions = {
                      streamSize: stat.size,
                      id3v2: options.id3v2,
          Severity: Minor
          Found in src/lib/mp3/mp3.ts - About 2 hrs to fix

            Function write has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                write: async (frame, stream) => {
                    const value = <IID3V2.FrameValue.RVA>frame.value;
                    const flags = [
                        0,
                        0,
            Severity: Minor
            Found in src/lib/id3v2/frames/implementations/id3v2.frame.rva.ts - About 2 hrs to fix

              Function followChain has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

              function followChain(frame: IMP3.FrameRawHeaderArray, pos: number, frames: Array<IMP3.FrameRawHeaderArray>): Array<IMP3.FrameRawHeaderArray> {
                  const result: Array<IMP3.FrameRawHeaderArray> = [];
                  // console.log('include start frame:', 'current:', {size: frame.header.size, offset: frame.header.offset});
                  result.push(frame);
                  frames = frames.filter(f => rawHeaderSize(f) > 0);
              Severity: Minor
              Found in src/lib/mp3/mp3.mpeg.chain.ts - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function parse has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  parse: async (reader, frame) => {
                      if (frame.data.length === 0) {
                          return {value: {}};
                      }
                      const flags = reader.readBitsByte();
              Severity: Minor
              Found in src/lib/id3v2/frames/implementations/id3v2.frame.rva.ts - About 1 hr to fix

                Function readID3V2 has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    private async readID3V2(chunk: Buffer, pos: number): Promise<boolean> {
                        if (this.demandData(chunk, pos)) {
                            return true;
                        }
                        const id3Header = this.id3v2reader.headerReader.readID3v2Header(chunk, pos);
                Severity: Minor
                Found in src/lib/mp3/mp3.reader.ts - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function toPlain has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                function toPlain(report: IMP3Analyzer.Report): string {
                    const sl: Array<string> = [report.filename];
                    const features: Array<string> = [];
                    if (report.frames) {
                        features.push(report.frames + ' Frames');
                Severity: Minor
                Found in src/bin/analyzeMP3.ts - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function readFrames has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                    public async readFrames(data: Buffer, tag: IID3V2.RawTag): Promise<Buffer> {
                        const markerLength = ID3v2_FRAME_HEADER_LENGTHS.MARKER[tag.head.ver];
                        const reader = new BufferReader(data);
                        let finish = false;
                        let skip = 0;
                Severity: Minor
                Found in src/lib/id3v2/id3v2.reader.ts - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Function readID3v2Frame has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export async function readID3v2Frame(rawFrame: IID3V2.RawFrame, head: IID3V2.TagHeader): Promise<IID3V2.Frame> {
                    const f = matchFrame(rawFrame.id);
                    let groupId: number | undefined;
                    if (rawFrame.formatFlags && rawFrame.formatFlags.grouping) {
                        groupId = rawFrame.data[0];
                Severity: Minor
                Found in src/lib/id3v2/frames/id3v2.frame.read.ts - About 1 hr to fix

                  Function read has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      async read(filename: string, options: IMP3Analyzer.Options): Promise<IMP3Analyzer.Report> {
                          const mp3 = new MP3();
                          const data = await mp3.read(filename, {id3v1: true, id3v2: true, mpeg: true, raw: true});
                          if (!data || !data.mpeg || !data.frames) {
                              return Promise.reject(Error('No mpeg data in file:' + filename));
                  Severity: Minor
                  Found in src/lib/mp3/mp3.analyzer.ts - About 1 hr to fix

                    Function readFrame has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private readFrame(reader: BufferReader, idbin: Buffer, tag: IID3V2.RawTag, skip: number): number {
                            const markerLength = ID3v2_FRAME_HEADER_LENGTHS.MARKER[tag.head.ver];
                            const pos = reader.position;
                            const frame: IID3V2.RawFrame = this.defaultRawFrame(idbin, tag);
                            frame.size = reader.readUInt(ID3v2_FRAME_HEADER_LENGTHS.SIZE[tag.head.ver]);
                    Severity: Minor
                    Found in src/lib/id3v2/id3v2.reader.ts - About 1 hr to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Severity
                    Category
                    Status
                    Source
                    Language