It's pointing to this line let stackThird = stackSecond + "/" + stackFirst.stackTags() + "/" + stackFirst.stackFour(); // +" "+Time;
providing code below.
https://github.com/Microsoft/tslint-microsoft-contrib
Unnecessary local variable: stackThird
public stackTags(): any {
let stackFirst = new Date();
let stackSecond = stackFirst.stackFive();
stackSecond++;
let stackThird = stackSecond + "/" + stackFirst.stackTags() + "/" + stackFirst.stackFour(); // +" "+Time;
return stackThird;
}
Change
let stackThird = stackSecond + "/" + stackFirst.stackTags() + "/" + stackFirst.stackFour();
return stackThird;`
to
return stackSecond + "/" + stackFirst.stackTags() + "/" + stackFirst.stackFour();
It is complaining because you are creating an unnecessary variable(stackThird).
Since you aren't doing anything with it after declaring/assigning it, it is complaining because you should just return that value from the method instead of assigning it to a variable and then returning the variable.
The rule no-unnecessary-local-variable
is this one:
Do not declare a variable only to return it from the function on the next line. It is always less code to simply return the expression that initializes the variable.
It is not part of the standard tslint, but come from tslint-microsoft-contrib , which are a set of rules even more strict.
You can disable this rule if you don't like it (personnaly, that's what I've done in my projects):
// tslint.json
{
"rulesDirectory": [
"node_modules/tslint-microsoft-contrib"
],
"rules": {
"no-unnecessary-local-variable": false
}
}
Or you can fix it by returning the computed result without using the variable:
return stackSecond + "/" + stackFirst.stackTags() + "/" + stackFirst.stackFour();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.