Sonarlint Not Detecting Issues in Intelij

Please provide

  • Operating system:Windows 11 Pro Version 23H2 ,OS build 22631.3527
  • SonarLint plugin version: 10.5.0.78339
    *InteliJ 2024.1
  • Programming language you’re coding in: Javascript
  • Is connected mode used: No
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

Sonarlint has stopped detecting certain issues in Intelijj, but still detects them in Vscode. Attached are the same lines of code, one from Intelij, and one from Vscode. Rolling back to a previous Intelij version fixes the issue, and the problems are detected.


These are just some examples, I could not upload more screenshots.

Hi @Emil_Yordanov

Can you share with me which rule it is?

Thank you

Hello Emil, I have not reproduced the issue. With the following code snippet:

const character_affection_pairs = [];

const sorted_affection_pairs = character_affection_pairs.sort((first_pair, second_pair) => {
    return first_pair[1] >= second_pair[1] ? -1 : 1;
});

These two issues are raised on IntelliJ:

However, not declaring the variable character_affection_pairs does not raise any issue, but this behavior is the same as on VS Code. I do not notice a difference in the two IDEs.

Could you please tell us which version of Nodejs you are using in IntelliJ? Could you also make sure that you restarted the IDE in case you modified the Nodejs path on the SonarLint settings?

Thank you

Hey guys, thanks for the replies!

I will try to give as much information as possible. I am using nodejs v20. I restarted the IDE several times just in case. The issue seems persistent on Windows and Linux when I install a fresh version of the IDE. I have attached two screenshots - one from a working instance on Windows and one on Linux where the problem mentioned can be seen. Again, this happens on both operating systems.

What seems even stranger is that it reports flaky tests (jest retry times being used) on the problematic instance - javascript:s5937 but does not report it on the other ones.

So basically in one case it is reporting the jest retry times and nothing else. And before it did not report that one, but did report all else (which is my desired behavior)




Thank you, @Emil_Yordanov, for the detailed information you provided, and I apologize for the late reply.

Would it be possible to send us a reproducible example of the code you are using?

Thanks for the reply, Nicolas! And sorry, I am taking long to respond as well.

Here is the exact code for the examples:

test(`Verify Sort by Grade`, async ({ given, and, when, then }) => {
			const { girl_position_wrapper, sort_by_select, sort_by_grade_option, sort_by_wrapper } = test_data.selectors;
			const girl_position_selector = girl_position_wrapper.selector;

			let character_affection_pairs = [];

			given(/^I open the game with (.*)$/, async (character_affection_pair_json) => {
				test_browser.logger.setTestName('Verify Sort by Grade');
				test_browser.logger.setStepName(`I open the game with ${character_affection_pair_json}`);

				const state_management_instructions = { hero_girls: [] };
				character_affection_pairs = JSON.parse(character_affection_pair_json)[skin.domain];

				for(const [id, affection_grade ] of character_affection_pairs) {
					state_management_instructions.hero_girls.push({ id, affection_grade });
				}

				await test_helper.setUserState(skin.product_id, test_product_data, state_management_instructions);
				await test_browser.loadUrl('', 'hh_game');
			});

			andLogsIn(and, test_browser);
			andOpensCollection(and, test_browser);
			givenIOpenFiltersPanel(given, test_browser);

			when('I sort the girl list by Grade', async () => {
				test_browser.logger.setStepName(`I sort the girl list by Grade`);

				await test_browser.waitForElementToAppear(sort_by_select);
				await test_browser.click(sort_by_select);

				await test_browser.tryBrowserScrollingIntoView(sort_by_wrapper, sort_by_grade_option, 200);
				await test_browser.click(sort_by_grade_option);

				const first_girl = {
					...girl_position_wrapper,
					selector: girl_position_wrapper.selector.replace('girl_position', '1')
				};

				await test_browser.waitForElementAttributeToChange(first_girl, 'id_girl');
			});

			then('the girls with the most affection grades unlocked are at the top of the list', async () => {
				test_browser.logger.setStepName(`the girls with the most affection grades unlocked are at the top of the list`);

				const sorted_affection_pairs = character_affection_pairs.sort((first_pair, second_pair) => {
					return first_pair[1] >= second_pair[1] ? -1 : 1;
				});

				for(let character_position = 1; character_position <= sorted_affection_pairs.length; character_position++) {

					const current_character_wrapper = getCurrentGirl(girl_position_wrapper, character_position, girl_position_selector);

					const is_displayed = await test_browser.isDisplayed(current_character_wrapper);
					expect(is_displayed).toBeTruthy();

					const id_girl = await test_browser.getElementAttribute(current_character_wrapper, 'id_girl');
					expect(+id_girl).toEqual(sorted_affection_pairs[character_position - 1][0]);
				}

				test_browser.logger.cleanLogs();
			});
		});


And another test:

test(`Verify Sort by Name`, async ({ given, and, when, then }) => {
			const { character_name_position_wrapper, sort_by_select, sort_by_name_option, sort_by_wrapper, girl_position_wrapper } = test_data.selectors;
			const character_position_selector = character_name_position_wrapper.selector;

			let character_ids = [];

			given(/^I open the game with (.*)$/, async (character_ids_json) => {
				test_browser.logger.setTestName('Verify Sort by Name');
				test_browser.logger.setStepName(`I open the game with ${character_ids_json}`);

				const state_management_instructions = { hero_girls: [] };
				character_ids = JSON.parse(character_ids_json)[skin.domain];

				for(const id of character_ids) {
					state_management_instructions.hero_girls.push({ id });
				}

				await test_helper.setUserState(skin.product_id, test_product_data, state_management_instructions);
				await test_browser.loadUrl('', 'hh_game');
			});

			andLogsIn(and, test_browser);
			andOpensCollection(and, test_browser);
			givenIOpenFiltersPanel(given, test_browser);

			when('I sort the girl list by Name', async () => {
				test_browser.logger.setStepName(`I sort the girl list by Name`);

				await test_browser.waitForElementToAppear(sort_by_select);
				await test_browser.click(sort_by_select);

				await test_browser.tryBrowserScrollingIntoView(sort_by_wrapper, sort_by_name_option);
				await test_browser.click(sort_by_name_option);

				if(skin.domain !== 'game3') {
					const first_girl = {
						...girl_position_wrapper,
						selector: girl_position_wrapper.selector.replace('girl_position', '2')
					};

					await test_browser.waitForElementAttributeToChange(first_girl, 'id_girl');
				}
			});

			then('the girl list is sorted alphabetically', async () => {
				test_browser.logger.setStepName(`the girl list is sorted alphabetically`);

				const character_names = [];

				for(let character_position = 1; character_position <= character_ids.length; character_position++) {

					const current_character_wrapper = getCurrentGirl(character_name_position_wrapper, character_position, character_position_selector);

					const is_displayed = await test_browser.isDisplayed(current_character_wrapper);
					expect(is_displayed).toBeTruthy();

					const character_name = await test_browser.getElementText(current_character_wrapper);
					character_names.push(character_name);
				}

				const sorted_character_names = [...character_names].sort();
				expect(character_names).toEqual(sorted_character_names);

				test_browser.logger.cleanLogs();
			});
		});


The code examples are from automation tests with javascript and jest.

1 Like

Hi @Emil_Yordanov ,

I could not reproduce this issue. Can you update to the latest version and check again?