Showing 79 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

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                    relativeVolumeAdjustment(
                        key: string, right: number, left: number, peakRight?: number, peakLeft?: number, rightBack?: number, leftBack?: number, peakRightBack?: number, peakLeftBack?: number,
                        center?: number, peakCenter?: number, bass?: number, peakBass?: number) {
                        this.addFrame<IID3V2.FrameValue.RVA>(key, {
                            right, left, peakRight, peakLeft,
                Severity: Major
                Found in src/lib/id3v2/id3v2.builder.ts and 1 other location - About 1 hr to fix
                src/lib/id3v2/id3v2.builder.v24.ts on lines 557..579

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 66.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                    relativeVolumeAdjustment(
                        key: string,
                        right: number,
                        left: number,
                        peakRight?: number,
                Severity: Major
                Found in src/lib/id3v2/id3v2.builder.v24.ts and 1 other location - About 1 hr to fix
                src/lib/id3v2/id3v2.builder.ts on lines 93..101

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 66.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                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
                  Severity
                  Category
                  Status
                  Source
                  Language