Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion build/hygiene.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ function hygiene(some, linting = true) {
);
});

const consoleLog = es.through(function (file) {
const lines = file.__lines;

for (let i = 0; i < lines.length; i++) {
if (/^\s*console\.log/.test(lines[i])) {
console.error(
file.relative + '(' + (i + 1) + ',1): Stray console.log'
);
errorCount++;
break;
}
}

this.emit('data', file);
});
Comment on lines +110 to +124

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider detecting all stray console.log statements in a file.

The current implementation stops at the first stray console.log found due to the break statement. This might not catch multiple stray logs in the same file. Consider removing the break statement to continue checking all lines in the file.

-				break;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const consoleLog = es.through(function (file) {
const lines = file.__lines;
for (let i = 0; i < lines.length; i++) {
if (/^\s*console\.log/.test(lines[i])) {
console.error(
file.relative + '(' + (i + 1) + ',1): Stray console.log'
);
errorCount++;
break;
}
}
this.emit('data', file);
});
const consoleLog = es.through(function (file) {
const lines = file.__lines;
for (let i = 0; i < lines.length; i++) {
if (/^\s*console\.log/.test(lines[i])) {
console.error(
file.relative + '(' + (i + 1) + ',1): Stray console.log'
);
errorCount++;
}
}
this.emit('data', file);
});


let input;

if (Array.isArray(some) || typeof some === 'string' || !some) {
Expand All @@ -130,7 +146,9 @@ function hygiene(some, linting = true) {
.pipe(filter(indentationFilter))
.pipe(indentation)
.pipe(filter(copyrightFilter))
.pipe(copyrights);
.pipe(copyrights)
.pipe(filter(tsHygieneFilter))
.pipe(consoleLog);

const streams = [
result.pipe(filter(tsHygieneFilter)).pipe(formatting)
Expand Down