forked from typescript-eslint/typescript-eslint
/
no-triple-slash-reference.ts
42 lines (39 loc) · 1.05 KB
/
no-triple-slash-reference.ts
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
import * as util from '../util';
export default util.createRule({
name: 'no-triple-slash-reference',
meta: {
type: 'suggestion',
docs: {
description: 'Disallow `/// <reference path="" />` comments',
category: 'Best Practices',
recommended: 'error',
},
schema: [],
deprecated: true,
replacedBy: ['triple-slash-reference'],
messages: {
noTripleSlashReference: 'Do not use a triple slash reference.',
},
},
defaultOptions: [],
create(context) {
const referenceRegExp = /^\/\s*<reference\s*path=/;
const sourceCode = context.getSourceCode();
return {
Program(program): void {
const commentsBefore = sourceCode.getCommentsBefore(program);
commentsBefore.forEach(comment => {
if (comment.type !== 'Line') {
return;
}
if (referenceRegExp.test(comment.value)) {
context.report({
node: comment,
messageId: 'noTripleSlashReference',
});
}
});
},
};
},
});