Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Handle relative paths in exceptions for react-no-dangerous-html rule #539

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/reactNoDangerousHtmlRule.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ts from 'typescript';
import {Utils} from './utils/Utils';
import * as Lint from 'tslint';

import {ErrorTolerantWalker} from './utils/ErrorTolerantWalker';
Expand Down Expand Up @@ -117,7 +118,7 @@ class NoDangerousHtmlWalker extends ErrorTolerantWalker {
}
let found = false;
exceptions.forEach((exception : Exception) : void => {
if (exception.file === this.getSourceFile().fileName) {
if (Utils.absolutePath(exception.file) === this.getSourceFile().fileName) {
if (exception.method === methodName) {
if (exception.comment != null) {
found = true;
Expand Down
11 changes: 6 additions & 5 deletions src/tests/ChaiPreferContainsToIndexOfRuleTests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Utils} from '../utils/Utils';
import {TestHelper} from './TestHelper';

/**
Expand Down Expand Up @@ -33,7 +34,7 @@ describe('chaiPreferContainsToIndexOfRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with indexOf that can be converted to .contain assertion: ",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-prefer-contains-to-index-of",
"startPosition": { "character": 13, "line": 2 }
}
Expand All @@ -48,7 +49,7 @@ describe('chaiPreferContainsToIndexOfRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with indexOf that can be converted to .contain assertion: ",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-prefer-contains-to-index-of",
"startPosition": { "character": 13, "line": 2 }
}
Expand All @@ -63,7 +64,7 @@ describe('chaiPreferContainsToIndexOfRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with indexOf that can be converted to .contain assertion: ",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-prefer-contains-to-index-of",
"startPosition": { "character": 13, "line": 2 }
}
Expand All @@ -78,11 +79,11 @@ describe('chaiPreferContainsToIndexOfRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with indexOf that can be converted to .contain assertion: ",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-prefer-contains-to-index-of",
"startPosition": { "character": 13, "line": 2 }
}
]);
});

});
});
71 changes: 36 additions & 35 deletions src/tests/ChaiVagueErrorsRuleTests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Utils} from '../utils/Utils';
import {TestHelper} from './TestHelper';

/**
Expand Down Expand Up @@ -39,25 +40,25 @@ describe('chaiVagueErrorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 4 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 5 }
}
Expand All @@ -74,19 +75,19 @@ describe('chaiVagueErrorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 4 }
}
Expand All @@ -103,19 +104,19 @@ describe('chaiVagueErrorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 4 }
}
Expand All @@ -132,19 +133,19 @@ describe('chaiVagueErrorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 4 }
}
Expand All @@ -161,19 +162,19 @@ describe('chaiVagueErrorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 4 }
}
Expand All @@ -194,43 +195,43 @@ describe('chaiVagueErrorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 4 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 5 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 6 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 7 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 8 }
}
Expand All @@ -249,31 +250,31 @@ describe('chaiVagueErrorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 4 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 5 }
},
{
"failure": "Found chai call with vague failure message. Please add an explicit failure message",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 6 }
}
Expand All @@ -292,28 +293,28 @@ describe('chaiVagueErrorsRule', () : void => {
{
"failure": "Found chai call with vague failure message. " +
"Move the strict equality comparison from the expect call into the assertion value",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. " +
"Move the strict equality comparison from the expect call into the assertion value",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
},
{
"failure": "Found chai call with vague failure message. " +
"Move the strict inequality comparison from the expect call into the assertion value. ",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 4 }
},
{
"failure": "Found chai call with vague failure message. " +
"Move the strict inequality comparison from the expect call into the assertion value. ",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 5 }
}
Expand All @@ -330,17 +331,17 @@ describe('chaiVagueErrorsRule', () : void => {
{
"failure": "Found chai call with vague failure message. " +
"Move the strict inequality comparison from the expect call into the assertion value. ",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 2 }
},
{
"failure": "Found chai call with vague failure message. " +
"Move the strict equality comparison from the expect call into the assertion value",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "chai-vague-errors",
"startPosition": { "character": 13, "line": 3 }
}
]);
});
});
});
Loading