'client' is already declared in the upper scope on line 3 column 8
93
94 static async validate(req, res){
95
96 const client = await this.findById(req) 97 const clientKey = await Validator.createAuthToken({id: client.id, name: client.name}, process.env.CLIENT_TOKEN_KEY)
98
99 if(res.cookie != null && Validator.verify(res.cookie, clientKey).id == client.id){ //Duda, porque se usa el res y no el req?
'client' is already declared in the upper scope on line 3 column 8
57 static async login(req, res){
58
59 //const client = await Validator.createAuthToken({id: 123,nombre:"ezequiel"}, "123")
60 const client = await Validator.createAuthToken({id: client.id, name: client.name}, process.env.CLIENT_TOKEN_KEY) 61 return res.json(client)
62
63
Description
Two variables can have the same name if they're declared in different scopes.
In the example below, the parameter x
is said to "shadow" the variable x
declared above it.
The outer x
can no longer be accessed inside the sum
function.
const x = 1
function add(x, y) {
return x + y
}
While shadowing does not cause any problems most of the time, it does make the code harder to read and understand. We highly recommend against shadowing. However, if you want to shadow some variable name and don't want DeepSource to flag it, add a skipcq comment alongside an explanation:
const x = 1
function add(x, y) { // skipcq: JS-0123 - `x` can be safely shadowed
return x + y
}
If you want to disable this issue project-wide, you can add it to the list of disabled issues in the project dashboard.
Bad Practice
const file = "data.txt"
function readFile(file) {
// The parameter `file` shadows the toplevel variable `file`.
if (fs.existsSync(file)) {
return fs.readFileSync(file)
}
return null
}
Recommended
// Prefer variable names that are distinct and convey as much
// meaning as possible.
const dataFile = "data.txt"
function readFile(filePath) {
if (fs.existsSync(filePath)) {
return fs.readFileSync(filePath)
}
return null
}
Alternatively:
const file = "data.txt"
function readFile(file) { // skipcq: JS-0123 - Shadowing is safe here
// ...
}