fix: lint errors quebram o build (deploys falhando) (#877) · BrasilAPI/BrasilAPI@030480b · GitHub
Skip to content

Commit 030480b

Browse files
lucianopfHermes Agent
andauthored
fix: lint errors quebram o build (deploys falhando) (#877)
* fix: corrige erros de lint introduzidos pelos rebases (#861 #865 #873 #874) - eleicoes/candidaturas: consistent-return — re-throw do erro não-404 (antes o erro era engolido e a função retornava undefined) - holidays: prefer-template - ibge/gov: import sem extensão, === e radix no parseInt - universities: função movida antes do uso (no-use-before-define) e full_name destructured como fullName (camelcase) Esses erros quebram o lint do build (deploys falhando na Vercel). Co-authored-by: Hermes Agent <noreply@nousresearch.com> Ai-tool: hermes Ai-model: deepseek-v4-flash Ai-os: wsl * fix: align prettier endOfLine with editorconfig (lf) and fix lint in rebased pages - .prettierrc: endOfLine crlf -> lf (matches .editorconfig; crlf entered main via #863 rebase and broke EVERY deploy since 08-09 with 'Insert ␍' on every line) - pages/api/diasuteis: convert CRLF blob to LF - pages/api/ibge/cnae/v1/classes: single quotes - pages/api/universities/v1/*: prettier formatting (from #861 rebase) - services/universities.js: prettier formatting --------- Co-authored-by: Hermes Agent <noreply@nousresearch.com>
1 parent 1b3c945 commit 030480b

9 files changed

Lines changed: 117 additions & 118 deletions

File tree

‎.prettierrc‎

Lines changed: 1 addition & 1 deletion
Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
1-
import app from '@/app';
2-
import BaseError from '@/errors/BaseError';
3-
import InternalError from '@/errors/InternalError';
4-
import getHolidays from '@/services/holidays';
5-
6-
const diasUteisHandler = (request, response) => {
7-
const {
8-
dataInicial = '',
9-
dataFinal = '',
10-
incluirFeriadosNacionais = 'true',
11-
// feriadosEstaduais = [], TODO: usar futuramente para considerar feriados estaduais
12-
// feriadosMunicipais = [], TODO: usar futuramente para considerar feriados municipais
13-
} = request.query;
14-
15-
try {
16-
if (!dataInicial || !dataFinal) {
17-
return response.status(400).json({
18-
message: 'Parâmetros dataInicial e dataFinal são obrigatórios',
19-
type: 'DATE_PARAM_MISSING',
20-
});
21-
}
22-
23-
const inicio = new Date(dataInicial);
24-
const fim = new Date(dataFinal);
25-
26-
// para caso tenha mais de um ano entre as datas
27-
const anos = [];
28-
for (let ano = inicio.getFullYear(); ano <= fim.getFullYear(); ano += 1) {
29-
anos.push(ano);
30-
}
31-
32-
const feriados =
33-
incluirFeriadosNacionais === 'true' ? anos.flatMap(getHolidays) : [];
34-
35-
const diasUteis = [];
36-
37-
for (
38-
let data = new Date(inicio);
39-
data <= fim;
40-
data.setDate(data.getDate() + 1)
41-
) {
42-
const dia = data.getDay();
43-
const dataString = data.toISOString().split('T')[0];
44-
const isFeriado = feriados.some((feriado) => feriado.date === dataString);
45-
46-
// getDay(): 0 = domingo, 6 = sábado
47-
const isDiaUtil = dia !== 0 && dia !== 6;
48-
49-
if (isDiaUtil && !isFeriado) diasUteis.push(dataString);
50-
}
51-
52-
return response.status(200).json({ diasUteis });
53-
} catch (error) {
54-
if (error instanceof BaseError) {
55-
throw error;
56-
}
57-
58-
throw new InternalError({
59-
message: 'Erro ao buscar dias úteis',
60-
type: 'business_days_error',
61-
});
62-
}
63-
};
64-
65-
export default app().get(diasUteisHandler);
1+
import app from '@/app';
2+
import BaseError from '@/errors/BaseError';
3+
import InternalError from '@/errors/InternalError';
4+
import getHolidays from '@/services/holidays';
5+
6+
const diasUteisHandler = (request, response) => {
7+
const {
8+
dataInicial = '',
9+
dataFinal = '',
10+
incluirFeriadosNacionais = 'true',
11+
// feriadosEstaduais = [], TODO: usar futuramente para considerar feriados estaduais
12+
// feriadosMunicipais = [], TODO: usar futuramente para considerar feriados municipais
13+
} = request.query;
14+
15+
try {
16+
if (!dataInicial || !dataFinal) {
17+
return response.status(400).json({
18+
message: 'Parâmetros dataInicial e dataFinal são obrigatórios',
19+
type: 'DATE_PARAM_MISSING',
20+
});
21+
}
22+
23+
const inicio = new Date(dataInicial);
24+
const fim = new Date(dataFinal);
25+
26+
// para caso tenha mais de um ano entre as datas
27+
const anos = [];
28+
for (let ano = inicio.getFullYear(); ano <= fim.getFullYear(); ano += 1) {
29+
anos.push(ano);
30+
}
31+
32+
const feriados =
33+
incluirFeriadosNacionais === 'true' ? anos.flatMap(getHolidays) : [];
34+
35+
const diasUteis = [];
36+
37+
for (
38+
let data = new Date(inicio);
39+
data <= fim;
40+
data.setDate(data.getDate() + 1)
41+
) {
42+
const dia = data.getDay();
43+
const dataString = data.toISOString().split('T')[0];
44+
const isFeriado = feriados.some((feriado) => feriado.date === dataString);
45+
46+
// getDay(): 0 = domingo, 6 = sábado
47+
const isDiaUtil = dia !== 0 && dia !== 6;
48+
49+
if (isDiaUtil && !isFeriado) diasUteis.push(dataString);
50+
}
51+
52+
return response.status(200).json({ diasUteis });
53+
} catch (error) {
54+
if (error instanceof BaseError) {
55+
throw error;
56+
}
57+
58+
throw new InternalError({
59+
message: 'Erro ao buscar dias úteis',
60+
type: 'business_days_error',
61+
});
62+
}
63+
};
64+
65+
export default app().get(diasUteisHandler);

‎pages/api/ibge/cnae/v1/classes/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import app from "@/app";
1+
import app from '@/app';
22
import { getCNAEClasses } from '@/services/ibge/cnae';
33

44
const action = async (_, response) => {

‎pages/api/universities/v1/[id].js‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import microCors from 'micro-cors';
22
import { getUniversitiesById } from '../../../../services/universities';
33

4-
const CACHE_CONTROL_HEADER_VALUE = 'max-age=0, s-maxage=86400, stale-while-revalidate';
4+
const CACHE_CONTROL_HEADER_VALUE =
5+
'max-age=0, s-maxage=86400, stale-while-revalidate';
56
const cors = microCors();
67

78
async function UniversityById(request, response) {
@@ -13,22 +14,18 @@ async function UniversityById(request, response) {
1314
const university = await getUniversitiesById(id);
1415

1516
if (!university) {
16-
return response
17-
.status(404)
18-
.json({
19-
message: 'Universidade não encontrada',
20-
type: 'UNIVERSITY_NOT_FOUND',
21-
})
17+
return response.status(404).json({
18+
message: 'Universidade não encontrada',
19+
type: 'UNIVERSITY_NOT_FOUND',
20+
});
2221
}
2322

24-
return response
25-
.status(200)
26-
.json(university)
27-
} catch(error) {
23+
return response.status(200).json(university);
24+
} catch (error) {
2825
response.status(500);
2926

3027
response.json(error);
3128
}
3229
}
3330

34-
export default cors(UniversityById);
31+
export default cors(UniversityById);

‎pages/api/universities/v1/index.js‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import microCors from 'micro-cors';
22
import { getUniversities } from '../../../../services/universities';
33

4-
const CACHE_CONTROL_HEADER_VALUE = 'max-age=0, s-maxage=86400, stale-while-revalidate';
4+
const CACHE_CONTROL_HEADER_VALUE =
5+
'max-age=0, s-maxage=86400, stale-while-revalidate';
56
const cors = microCors();
67

7-
async function Universities(request, response){
8+
async function Universities(request, response) {
89
response.setHeader('Cache-Control', CACHE_CONTROL_HEADER_VALUE);
910

1011
try {
@@ -13,11 +14,11 @@ async function Universities(request, response){
1314
response.status(200);
1415

1516
response.json(universities);
16-
} catch(error) {
17+
} catch (error) {
1718
response.status(500);
18-
19+
1920
response.json(error);
2021
}
2122
}
2223

23-
export default cors(Universities)
24+
export default cors(Universities);

‎services/eleicoes/candidaturas.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,6 @@ export const searchCandidate = async (
7676
notFoundError.name = 'CandidateNotFoundError';
7777
throw notFoundError;
7878
}
79+
throw error;
7980
}
8081
};

‎services/holidays/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function getWeekdayName(dateString) {
7171
'sábado',
7272
];
7373

74-
const date = new Date(dateString + 'T12:00:00');
74+
const date = new Date(`${dateString}T12:00:00`);
7575
return weekdays[date.getDay()];
7676
}
7777

‎services/ibge/gov.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from 'axios';
2-
import mapUfToUfCode from '@/util/mapUfToUfCode.js';
2+
import mapUfToUfCode from '@/util/mapUfToUfCode';
33
import InternalError from '@/errors/InternalError';
44

55
const URL_UF = 'https://servicodados.ibge.gov.br/api/v1/localidades/estados';
@@ -75,7 +75,7 @@ export const getUfEstimatePopulationByCode = async (uf) => {
7575
`${URL_AGGREGATES}/${ESTIMATED_POPULATION_AGGREGATE_ID}/periodos/${LATEST_PERIOD}/variaveis?localidades=N3[${ufCode}]`
7676
);
7777

78-
data = data.find((item) => item.id == ESTIMATED_POPULATION_VARIABLE_ID);
78+
data = data.find((item) => item.id === ESTIMATED_POPULATION_VARIABLE_ID);
7979

8080
if (!data) {
8181
throw new InternalError('Empty data');
@@ -85,7 +85,7 @@ export const getUfEstimatePopulationByCode = async (uf) => {
8585
const key = Object.keys(result)[0];
8686

8787
return {
88-
populacao_estimada: parseInt(result[key]),
88+
populacao_estimada: parseInt(result[key], 10),
8989
periodo: key,
9090
};
9191
};

‎services/universities.js‎

Lines changed: 30 additions & 30 deletions

0 commit comments

Comments
 (0)