forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-commented-out-import.js
44 lines (41 loc) · 1.1 KB
/
no-commented-out-import.js
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
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* @type {import('eslint').Rule.RuleModule}
*/
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'check for commented out import statements',
category: 'Possible Errors',
},
fixable: 'code',
messages: {
foundImport: 'Commented-out import statements should be deleted.'
},
schema: [] // no options
},
create: function(context) {
const sourceCode = context.sourceCode ?? context.getSourceCode();
function checkImportAndReportError(comment) {
const trimmed = comment.value.trim();
if (trimmed.startsWith('import ')) {
context.report({node: comment, messageId: 'foundImport'});
}
}
return {
Program() {
const comments = sourceCode.getAllComments();
if (!comments) {
return;
}
for (const comment of comments) {
checkImportAndReportError(comment);
}
}
};
}
};