Skip to content

Commit fba3e29

Browse files
armano2JamesHenry
authored andcommitted
[FIX] [no-triple-slash-reference] fix false positives (typescript-eslint#226)
### Disallow `/// <reference path="" />` comments but it's triggered on: - `/// <reference types="foo" />` - `/// <reference lib="es2017.string" />` - `/// <reference no-default-lib="true"/>` types/lib/no-default-lib can't be replaced by es6 imports
1 parent 317834e commit fba3e29

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Diff for: packages/eslint-plugin-typescript/lib/rules/no-triple-slash-reference.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ module.exports = {
1919
url: util.metaDocsUrl("no-triple-slash-reference"),
2020
},
2121
schema: [],
22+
messages: {
23+
tripleSlashReference: "Do not use a triple slash reference.",
24+
},
2225
},
2326

2427
create(context) {
25-
const referenceRegExp = /^\/\s*<reference/;
28+
const referenceRegExp = /^\/\s*<reference\s*path=/;
2629
const sourceCode = context.getSourceCode();
2730

2831
//----------------------------------------------------------------------
@@ -45,7 +48,7 @@ module.exports = {
4548
if (referenceRegExp.test(comment.value)) {
4649
context.report({
4750
node: comment,
48-
message: "Do not use a triple slash reference.",
51+
messageId: "tripleSlashReference",
4952
});
5053
}
5154
});

Diff for: packages/eslint-plugin-typescript/tests/lib/rules/no-triple-slash-reference.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,22 @@ const ruleTester = new RuleTester({
2121

2222
ruleTester.run("no-triple-slash-reference", rule, {
2323
valid: [
24+
`/// <reference types="foo" />`,
25+
`/// <reference lib="es2017.string" />`,
26+
`/// <reference no-default-lib="true"/>`,
2427
"/// Non-reference triple-slash comment",
2528
"// <reference path='Animal' />",
29+
`/*
30+
/// <reference path="Animal" />
31+
let a
32+
*/`,
2633
],
2734
invalid: [
2835
{
2936
code: '/// <reference path="Animal" />',
3037
errors: [
3138
{
32-
message: "Do not use a triple slash reference.",
39+
messageId: "tripleSlashReference",
3340
line: 1,
3441
column: 1,
3542
},
@@ -43,7 +50,7 @@ let a
4350
parser: "typescript-eslint-parser",
4451
errors: [
4552
{
46-
message: "Do not use a triple slash reference.",
53+
messageId: "tripleSlashReference",
4754
line: 2,
4855
column: 1,
4956
},

0 commit comments

Comments
 (0)