17 for (const key in colors) {
18 // Each color method calls console.log with the color as the first argument,followed by any additional arguments.
19 Logger.prototype[key] = function(...args) {
20 console.log(colors[key], ...args);21 };
22 }
23 }
98 const email = $('#intern-email').val();
99 const school = $('#intern-school').val();
100
101 console.log("Intern", name, id, email, school);102 // Create new manager object
103 try {
104 const intern = new Intern(name, id, email, school);
73 const email = $('#engineer-email').val();
74 const github = $('#engineer-github').val();
75
76 console.log("Engineer", name, id, email, github); 77 // Create new manager object
78 try {
79 const engineer = new Engineer(name, id, email, github);
48 const email = $('#manager-email').val();
49 const officeNumber = parseInt($('#manager-office').val());
50
51 console.log("Manager", name, id, email, officeNumber); 52 // Create new manager object
53 try {
54 const manager = new Manager(name, id, email, officeNumber);
42 // Add manager-add button listener
43 $('#manager-add').on('click', function () {
44 // Get values from form
45 console.log("Manager button clicked"); 46 const name = $('#manager').val();
47 const id = parseInt($('#manager-id').val());
48 const email = $('#manager-email').val();
306const writeToFile = (documentName, documentBody) => {
307 let fileName = "./dist/" + documentName;
308 fs.writeFile(fileName, documentBody, (err) =>
309 err ? console.error(err) : console.log("HTML document successfully created at " + fileName));310
311}
312
It is considered a best practice to avoid the use of any console
methods in JavaScript code that will run on the browser.
NOTE: If your repository contains a server side project, you can add "nodejs"
to the environment
property of analyzer meta in .deepsource.toml
.
This will prevent this issue from getting raised.
Documentation for the analyzer meta can be found here.
Alternatively, you can silence this issue for your repository as shown here.
If a specific console
call is meant to stay for other reasons, you can add a skipcq comment to that line.
This will inform other developers about the reason behind the log's presence, and prevent DeepSource from flagging it.
Usually, console
methods are only used for debugging, and can leak internal info to the client.
Removing the console
call will fix this issue.
Bad Practice
if (!secure(data)) {
console.log("data is not secure", data) // `data` is visible to the client
}
console.table(tableObj)
Recommended
if (!secure(data)) {
// alter the DOM to inform the user that `data` is insecure.
}
console.table(tableObj) // skipcq: JS-0002 Easter egg. Users are meant to see this.