Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Highlighting error not using parentheses inside an if condition #418

Closed
Mariede opened this issue Nov 2, 2021 · 7 comments
Closed

Highlighting error not using parentheses inside an if condition #418

Mariede opened this issue Nov 2, 2021 · 7 comments
Labels

Comments

@Mariede
Copy link

Mariede commented Nov 2, 2021

Hi there, I am sorry to say that but maybe we got a little bug within this release:

  • When not using the parenthesis inside this if condition:
    image

  • When using it, things go fine:
    image

Thank's for helping.

@Thom1729
Copy link
Contributor

Thom1729 commented Nov 2, 2021

Can you paste an example as text?

@Mariede
Copy link
Author

Mariede commented Nov 3, 2021

Can you paste an example as text?

sure, I will paste the head of the function together with the scoped validation function where code starts to break the highlight.

Starts here:

(checkVazaoFimEscala < checkVazaoMaximo || (checkVazaoMaximo < checkVazaoNormal) || (checkVazaoNormal < checkVazaoMinimo))

Strange but this same code does not break the highlight inside a functional react component.

const calculate1 = async (req, res) => {
	// Parametros de sessao


		...


	// Validacoes nos valores recebidos
	const _validateData = ( ... some params ... ) => {
		const limitsValues = enumData.validateLimitsValues;
		const errorStack = [];
		const decimalsAfter = 6;


		...


		_limitsCheck(
			errorStack,
			_valorTemperaturaAfterCooler,
			limitsValues.temperatura[0],
			limitsValues.temperatura[1],
			`Umidade relativa: temperatura (aftercooler ou outro) deve estar entre ${functions.formatNumberToString(limitsValues.temperatura[0])} ${temperaturaUnidadePadrao} e ${functions.formatNumberToString(limitsValues.temperatura[1])} ${temperaturaUnidadePadrao} (${functions.formatNumberToString(_valorTemperaturaAfterCooler)} ${temperaturaUnidadePadrao})`
		);

		// Valor viscosidade dinamica
		_limitsCheck(
			errorStack,
			_valorViscosidadeDinamica,
			limitsValues.viscosidadeDinamica[0],
			limitsValues.viscosidadeDinamica[1],
			`Viscosidade dinâmica: valor deve estar entre ${functions.formatNumberToString(limitsValues.viscosidadeDinamica[0])} e ${functions.formatNumberToString(limitsValues.viscosidadeDinamica[1])} (${functions.formatNumberToString(_valorViscosidadeDinamica)})`
		);
		// -------------------------------

		// Checagem vazao (minimo e maximo)
		if (_valorVazaoMinimo !== '' || _valorVazaoNormal !== '' || _valorVazaoMaximo !== '' || _valorVazaoFimEscala !== '') {
			const checkVazaoMinimo = (_valorVazaoMinimo === '' || _valorVazaoMinimo === 0 ? (_valorVazaoNormal || 0) : _valorVazaoMinimo);
			const checkVazaoNormal = (_valorVazaoNormal === '' ? 0 : _valorVazaoNormal); // Vazao normal sempre presente
			const checkVazaoMaximo = (_valorVazaoMaximo === '' || _valorVazaoMaximo === 0 ? (_valorVazaoFimEscala || _valorVazaoNormal || 0) : _valorVazaoMaximo);
			const checkVazaoFimEscala = (_valorVazaoFimEscala === '' ? (_valorVazaoMaximo || _valorVazaoNormal || 0) : _valorVazaoFimEscala);

			if (checkVazaoFimEscala < checkVazaoMaximo || (checkVazaoMaximo < checkVazaoNormal) || (checkVazaoNormal < checkVazaoMinimo)) {
				errorStack.push('Vazão: valor de fim de escala deve ser maior ou igual ao valor máximo, que deve ser maior ou igual ao valor normal, que deve ser maior ou igual ao valor mínimo (caso exista)');
			}
		}
		// -------------------------------

		// Checagem pressao diferencial (minimo e maximo)
		if (_valorPressaoDiferencialNormal !== '' || _valorPressaoDiferencialFimEscala !== '') {
			const checkPressaoDiferencialNormal = (_valorPressaoDiferencialNormal === '' ? (_valorPressaoDiferencialFimEscala || 0) : _valorPressaoDiferencialNormal);
			const checkPressaoDiferencialFimEscala = (_valorPressaoDiferencialFimEscala === '' ? (_valorPressaoDiferencialNormal || 0) : _valorPressaoDiferencialFimEscala);

			if (checkPressaoDiferencialFimEscala < checkPressaoDiferencialNormal) {
				errorStack.push('Pressão diferencial: valor de fim de escala deve ser maior ou igual ao valor normal (caso exista)');
			}
		}
		// -------------------------------




		...


@Thom1729 Thom1729 added the bug label Nov 3, 2021
@Thom1729
Copy link
Contributor

Thom1729 commented Nov 3, 2021

Looks like the problem is that the < in checkVazaoFimEscala < is being parsed as the beginning of function type arguments. This is almost certainly a bug in the Flow extension. It looks like it's pretty hard to trigger — you need something like foo < bar < baz, or foo < bar | baz < xyzzy.

I'll take a look. There may be a similar bug in the core TypeScript definition as well.

@Mariede
Copy link
Author

Mariede commented Nov 3, 2021

wow looks bigger than i thought... if you need help with some other test let me know ok. Thanks

@Thom1729
Copy link
Contributor

Thom1729 commented Nov 3, 2021

In this particular case, which uses the || operator, I could hack around it (such a hack is already in place for TypeScript), but the bug would still appear in foo < bar | baz < xyzzy. I'm currently opening a core issue for a change that would help, but that's not a short-term solution (or a guaranteed solution at all).

I might come up with a clean solution, and if that fails I'll probably implement a dirty one, but I'd use parens there in the meantime.

@Thom1729
Copy link
Contributor

Should be fixed in v11.1.1. It's the hacky fix, not a clean one, but it should do the right thing in most cases and it shouldn't make anything worse.

@Mariede
Copy link
Author

Mariede commented Nov 11, 2021

Although it is not a clean solution, it is a welcome help! Thank's

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants