silegis-mg/interpretador-articulacao

View on GitHub

Showing 19 of 27 total issues

Consider simplifying this complex logical expression.
Open

    if (mEmenda) {
        const mEmendaAnterior = anterior ? /^(.+?)(?:-([a-z]))?$/i.exec(anterior.numero || '') : null;

        sequenciaNumericaValida = !!mEmendaAnterior && mEmenda[1] === mEmendaAnterior[1] &&
            (!mEmendaAnterior[2] && mEmenda[2].toUpperCase() === 'A' ||
Severity: Critical
Found in src/interpretador/validadorArticulacao.ts - About 3 hrs to fix

    Function escapar has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        escapar(texto: string, substituir: SubstituirCallback): string {
            const regexpAspas = /[“”‘’"]/g;
            let resultado = '';
            let ultimo = 0;
            let abertura: number;
    Severity: Minor
    Found in src/interpretador/escapamento/impl/EscapeAspas.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 interpretarArticulacao has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    function interpretarArticulacao(textoOriginal: string,
                                    opcoes: IOpcoesInterpretacao = {}): IArticulacaoInterpretada {
        const contexto = new Contexto();
        const regexpLinhas: IParserLinha[] = [
            ...(opcoes.parsersExtras ?? []),
    Severity: Minor
    Found in src/interpretador/interpretarArticulacao.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 escapar has 45 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        escapar(texto: string, substituir: SubstituirCallback): string {
            const regexpAspas = /[“”‘’"]/g;
            let resultado = '';
            let ultimo = 0;
            let abertura: number;
    Severity: Minor
    Found in src/interpretador/escapamento/impl/EscapeAspas.ts - About 1 hr to fix

      Function verificarNumeracao has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      function verificarNumeracao(dispositivo: QualquerDispositivo,
                                  anterior: QualquerDispositivo | undefined,
                                  formatacao: FormatacaoNumerica) {
          const mEmenda = /^(.+?)-([a-z])$/i.exec(dispositivo.numero || '');
          let sequenciaNumericaValida: boolean;
      Severity: Minor
      Found in src/interpretador/validadorArticulacao.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 interpretarArticulacao has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function interpretarArticulacao(textoOriginal: string,
                                      opcoes: IOpcoesInterpretacao = {}): IArticulacaoInterpretada {
          const contexto = new Contexto();
          const regexpLinhas: IParserLinha[] = [
              ...(opcoes.parsersExtras ?? []),
      Severity: Minor
      Found in src/interpretador/interpretarArticulacao.ts - About 1 hr to fix

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

            desfazerEscapes(trecho?: string): string | void {
                if (!this.contexto) {
                    throw new Error('Contexto de escapamento está nulo.');
                }
        
        Severity: Minor
        Found in src/interpretador/escapamento/Escapamento.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 validarArticulacao has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function validarArticulacao(dispositivosOriginais: QualquerDispositivo[],
                                           opcoes: IOpcoesValidacao = {}): Validacao[] {
            let ultimoArtigo: Artigo;
        
            function _validarArticulacao(dispositivos: QualquerDispositivo[]) {
        Severity: Minor
        Found in src/interpretador/validadorArticulacao.ts - About 1 hr to fix

          Function _validarArticulacao has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              function _validarArticulacao(dispositivos: QualquerDispositivo[]) {
                  const ultimos: { [tipo in TipoDispositivoOuAgrupador]?: QualquerDispositivo } = {
                      get artigo() { return ultimoArtigo; },
                      set artigo(artigo) { ultimoArtigo = artigo; }
                  };
          Severity: Minor
          Found in src/interpretador/validadorArticulacao.ts - About 1 hr to fix

            Function desfazerEscapes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                desfazerEscapes(trecho?: string): string | void {
                    if (!this.contexto) {
                        throw new Error('Contexto de escapamento está nulo.');
                    }
            
            Severity: Minor
            Found in src/interpretador/escapamento/Escapamento.ts - About 1 hr to fix

              Function constructor has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  constructor(textoOriginal: string, ...escapesExtras: EscapeInterpretacao[]) {
                      const escapadores = [new EscapeSimboloEscape(), ...escapesExtras];
                  
                      /*
                       * Para cada citação, isto é, texto entre aspas, substitui-se o seu conteúdo
              Severity: Minor
              Found in src/interpretador/escapamento/Escapamento.ts - About 1 hr to fix

                Function textoEscapado has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        this.textoEscapado = escapadores.reduce((prev, cur) => {
                            const escapesAnteriores = [...this.escapes];
                    
                            /**
                             * Determina o índice em que deve inserir o escape de forma ordenada
                Severity: Minor
                Found in src/interpretador/escapamento/Escapamento.ts - About 1 hr to fix

                  Function onMatch has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      onMatch(contexto: Contexto, m: RegExpExecArray): Dispositivo<any> | null {
                          const numero = m[1];
                  
                          if (numero.length === 1 && contexto.ultimoItem && contexto.ultimoItem instanceof Alinea) {
                              // Pode ser que, na verdade, trata-se de uma alínea sendo confundida com um inciso.
                  Severity: Minor
                  Found in src/interpretador/parsers/ParserInciso.ts - About 55 mins 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 validarConteudo has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function validarConteudo(dispositivo: QualquerDispositivo,
                                           proximo: QualquerDispositivo | undefined,
                                           escapes: EscapeInterpretacao[]): boolean {
                      const conteudoParaValidacao =
                          escapes.reduce((prev, cur) => cur.escapar(prev, () => ''), dispositivo.descricao)
                  Severity: Minor
                  Found in src/interpretador/validadorArticulacao.ts - About 35 mins 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 interpretarNumeroRomano has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export function interpretarNumeroRomano(romano: string) {
                      romano = romano.toUpperCase().replace(/ +/g, '');
                      let soma = 0;
                      let i = 0;
                      const mapa = { M: 1000, D: 500, C: 100, L: 50, X: 10, V: 5, I: 1 };
                  Severity: Minor
                  Found in src/util/transformarNumeros.ts - About 35 mins 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 onMatch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      onMatch(contexto: Contexto, m: RegExpExecArray): Dispositivo<any> | null {
                          if (m[2] === '.' && m[1].length > 1 &&
                              (contexto.ultimoItem?.tipo !== TipoDispositivo.ALINEA ||
                                  !contexto.ultimoItem.numero ||
                                  interpretarLetra(contexto.ultimoItem.numero) !== interpretarLetra(m[1]) - 1)) {
                  Severity: Minor
                  Found in src/interpretador/parsers/ParserAlinea.ts - About 25 mins 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 processar has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public processar(contexto: Contexto, linha: string): boolean {
                          if (this.atendeRequisitos(contexto)) {
                              const m = this.regexp.exec(linha);
                  
                              if (m) {
                  Severity: Minor
                  Found in src/interpretador/parsers/ParserLinha.ts - About 25 mins 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 inferirFormatacao has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export function inferirFormatacao(numero: string | null): FormatacaoNumerica {
                      if (!numero) {
                          return FormatacaoNumerica.NENHUMA;
                      }
                  
                  
                  Severity: Minor
                  Found in src/util/transformarNumeros.ts - About 25 mins 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 onMatch has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      onMatch(contexto: Contexto, m: RegExpExecArray): Dispositivo<any> | null {
                          const item = new Item(m[1], m[2]);
                          let container = contexto.getUltimoItemTipo(Alinea);
                  
                          if (!container) {
                  Severity: Minor
                  Found in src/interpretador/parsers/ParserItem.ts - About 25 mins 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