0

In a javascript file, I get the indentation code quality error:

closeComp() {
    const selectEvent = new CustomEvent('hidemodal', {
        detail: true
    });
    this.dispatchEvent(selectEvent);
}

Error says: A conditionally executed single line should be denoted by indentation

I saw a few articles and they all said it is just a matter of spacing. Like this: https://rules.sonarsource.com/c/RSPEC-3973

I am using the above code and it still did not work.

2 Answers 2

0

Try skipping the creation of Constant like below

closeComp() {
    this.dispatchEvent(new CustomEvent('hidemodal', {
        detail: true
    }));
}
1
  • if you have got answer please mark this as Best answer. Commented Feb 23, 2023 at 8:45
0

The error message you are seeing is a code quality rule that suggests that when a single line of code is executed conditionally (i.e., only if a certain condition is met), it should be indented appropriately to make the code more readable and easier to understand.

in the below example, While this code is technically correct, it may be harder to read and understand because the single line of code is not indented

if (condition) this.foo();

the code provided below is more readable and easier to understand because the single line of code is indented appropriately:

closeComp() {
    const selectEvent = new CustomEvent('hidemodal', {
        detail: true
    });

    // Example condition
    // If this condition is always gonna be true
    // you can use a const variable and set to true
    
    const someCondition=true
    
    if (someCondition) {
        this.dispatchEvent(selectEvent);
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .