filter comment tokens - fixes babel/babel-eslint#153

This commit is contained in:
Sebastian McKenzie 2015-07-22 01:19:23 +01:00
parent 8baea68c6c
commit c551545f29
2 changed files with 28 additions and 1 deletions

View File

@ -70,7 +70,9 @@ exports.toTokens = function (tokens) {
// transform tokens to type "Template"
convertTemplateType(tokens);
return tokens.map(exports.toToken);
return tokens.filter(function (token) {
return token.type !== "CommentLine" && token.type !== "CommentBlock";
}).map(exports.toToken);
};
function convertTemplateType(tokens) {

View File

@ -1193,4 +1193,29 @@ describe("verify", function () {
[]
);
});
it("excludes comment tokens #153", function () {
verifyAndAssertMessages(
[
"var a = [",
"1,",
"2, // a trailing comment makes this line fail comma-dangle (always-multiline)",
"];",
].join("\n"),
{ "comma-dangle": [2, "always-multiline"] },
[]
);
verifyAndAssertMessages(
[
"switch (a) {",
"// A comment here makes the above line fail brace-style",
"case 1:",
"console.log(a);",
"}"
].join("\n"),
{ "brace-style": 2 },
[]
);
});
});