Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
[FIX] [no-triple-slash-reference] fix false positives (#226)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
armano2 authored and bradzacher committed Dec 14, 2018
1 parent 370a558 commit 2df5460
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions lib/rules/no-triple-slash-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ module.exports = {
url: util.metaDocsUrl("no-triple-slash-reference"),
},
schema: [],
messages: {
tripleSlashReference: "Do not use a triple slash reference.",
},
},

create(context) {
const referenceRegExp = /^\/\s*<reference/;
const referenceRegExp = /^\/\s*<reference\s*path=/;
const sourceCode = context.getSourceCode();

//----------------------------------------------------------------------
Expand All @@ -45,7 +48,7 @@ module.exports = {
if (referenceRegExp.test(comment.value)) {
context.report({
node: comment,
message: "Do not use a triple slash reference.",
messageId: "tripleSlashReference",
});
}
});
Expand Down
11 changes: 9 additions & 2 deletions tests/lib/rules/no-triple-slash-reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ const ruleTester = new RuleTester({

ruleTester.run("no-triple-slash-reference", rule, {
valid: [
`/// <reference types="foo" />`,
`/// <reference lib="es2017.string" />`,
`/// <reference no-default-lib="true"/>`,
"/// Non-reference triple-slash comment",
"// <reference path='Animal' />",
`/*
/// <reference path="Animal" />
let a
*/`,
],
invalid: [
{
code: '/// <reference path="Animal" />',
errors: [
{
message: "Do not use a triple slash reference.",
messageId: "tripleSlashReference",
line: 1,
column: 1,
},
Expand All @@ -43,7 +50,7 @@ let a
parser: "typescript-eslint-parser",
errors: [
{
message: "Do not use a triple slash reference.",
messageId: "tripleSlashReference",
line: 2,
column: 1,
},
Expand Down

0 comments on commit 2df5460

Please sign in to comment.