Skip to content
Merged
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
27 changes: 14 additions & 13 deletions fontes/infraestrutura/formatadores/formatador-lmht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@
if (valores) {
// Preprocessamento: Parciais
const parciaisResolvidas: string[] = [];
let parciais: string[] = [];
let parciais: string[] | undefined = [];
if (this.verificarEstruturaParcial(textoBase)) {
parciais = this.devolverParciais(textoBase);
const textoParcial = parciais.map((parcial) => {
const textoParcial = parciais?.map((parcial) => {

Check warning on line 56 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 56 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 56 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 56 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return `<lmht><corpo>${parcial}</corpo></lmht>`;
});

Check warning on line 58 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 58 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
textoParcial.map((parcial) => {
textoParcial?.map((parcial) => {

Check warning on line 59 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 59 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 59 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 59 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const result = this.preprocessadorLmhtParciais.processarParciais(parcial);
if (result instanceof Error) {
throw result;
}
parciaisResolvidas.push(result.conteudo);
});

Check warning on line 65 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 65 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 66 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

textoBase = this.formatarTextoBase(textoBase, parciais, parciaisResolvidas);
textoBase = this.formatarTextoBase(textoBase, parciais as string[], parciaisResolvidas);

// Preprocessamento: Handlebars
textoBase = this.preprocessadorHandlebars.processar(textoBase);
Expand All @@ -83,17 +83,18 @@
private resolverVisaoCorrespondente(
caminhoRota: string
): { visaoCorrespondente: string | undefined, caminhosTentados: string[] } {
const caminhoRotaParametrosResolvidos = caminhoRota.replace(/:([\w]+)(\/)?/i, `[$1]`);
const caminhoRotaNormalizado = caminhoRota.replace(/^\//, '');
const caminhoRotaParametrosResolvidos = caminhoRotaNormalizado.replace(/:([\w]+)(\/)?/i, `[$1]`);
const diretorioOuArquivo = caminho.join(this.diretorioBase, 'visoes', caminhoRotaParametrosResolvidos);
const retorno = {
visaoCorrespondente: '',
const retorno: { visaoCorrespondente: string | undefined, caminhosTentados: string[] } = {
visaoCorrespondente: undefined,
caminhosTentados: [
diretorioOuArquivo,
diretorioOuArquivo + '.lmht'
]
}

let visaoCorrespondente: string;
let visaoCorrespondente: string | undefined;
if (caminhoRotaParametrosResolvidos.endsWith(']')) {
// Quando o caminho termina em um símbolo de parâmetro, significa que a visão correspondente
// é a de detalhes.
Expand Down Expand Up @@ -134,7 +135,7 @@
* @returns Todos os valores normalizados como dicionários, ou ainda dicionários de dicionários.
*/
private resolverValores(valores: {[nome: string]: any}) {
const valoresResolvidos = {};
const valoresResolvidos = {} as {[nome: string]: any};
for (const [nome, valor] of Object.entries(valores)) {
// eslint-disable-next-line no-prototype-builtins
let valorResolvido = valor.hasOwnProperty('valor') ? valor.valor : valor;
Expand All @@ -149,7 +150,7 @@
}

private obterPropriedadesDeObjetoComoDicionario(objeto: ObjetoDeleguaClasse) {
const dicionarioPropriedades = {};
const dicionarioPropriedades = {} as {[nome: string]: any};

Check warning on line 153 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
for (const [nome, valor] of Object.entries(objeto.propriedades)) {
dicionarioPropriedades[nome] = valor;
}
Expand All @@ -168,14 +169,14 @@
return textoBase;
}

private devolverParciais(textoLmht: string): string[] {
return textoLmht.match(this.regexParcial).map((parcial) => {
private devolverParciais(textoLmht: string): string[] | undefined {

Check warning on line 172 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return textoLmht.match(this.regexParcial)?.map((parcial) => {

Check warning on line 173 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 173 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 173 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 173 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
return parcial.toString();
});

Check warning on line 175 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 175 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

private verificarEstruturaParcial(textoLmht: string): boolean {
const matches = textoLmht.match(this.regexParcial);
return matches?.length > 0 ? true : false;
return (matches?.length ?? 0) > 0;

Check warning on line 180 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 180 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 180 in fontes/infraestrutura/formatadores/formatador-lmht.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}
}
Loading