Showing 21 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' ||
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;
- Read upRead up
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 ?? []),
- Read upRead up
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!container) {
let artigo = contexto.getUltimoItemTipo([Artigo, Paragrafo]);
if (!artigo) {
artigo = new Artigo('', '');
- Read upRead up
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 86.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!inciso) {
let artigo = contexto.getUltimoItemTipo([Artigo, Paragrafo]);
if (!artigo) {
artigo = new Artigo('', '');
- Read upRead up
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 86.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
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;
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;
- Read upRead up
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 ?? []),
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.');
}
- Read upRead up
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[]) {
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; }
};
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.');
}
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
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
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.
- Read upRead up
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)
- Read upRead up
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 };
- Read upRead up
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)) {
- Read upRead up
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) {
- Read upRead up
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;
}
- Read upRead up
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"