-
Notifications
You must be signed in to change notification settings - Fork 648
Expand file tree
/
Copy pathno-commented-out-console.ts
More file actions
49 lines (44 loc) · 1.22 KB
/
no-commented-out-console.ts
File metadata and controls
49 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import type {TSESTree} from '@typescript-eslint/utils';
import {createRule} from './utils/ruleCreator.ts';
export default createRule({
name: 'no-commented-out-console',
meta: {
type: 'problem',
docs: {
description: 'check for commented out console.{warn/log/etc} lines',
category: 'Possible Errors',
},
messages: {
foundComment: 'Found a commented out console call.',
},
fixable: 'code',
schema: [], // no options
},
defaultOptions: [],
create: function(context) {
const sourceCode = context.sourceCode;
function checkCommentAndReportError(comment: TSESTree.Comment) {
const trimmed = comment.value.trim();
if (trimmed.startsWith('console.log(')) {
context.report({
node: comment,
messageId: 'foundComment',
});
}
}
return {
Program() {
const comments = sourceCode.getAllComments();
if (!comments) {
return;
}
for (const comment of comments) {
checkCommentAndReportError(comment);
}
},
};
},
});