From 5e927d281b4d0cf68a36efbe1c0e323151100844 Mon Sep 17 00:00:00 2001 From: Toru Nagashima Date: Sat, 17 Dec 2016 20:06:48 +0900 Subject: [PATCH] Chore: fix the tests for core rules --- test/core-rules.js | 52 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/test/core-rules.js b/test/core-rules.js index d73a333a..b7279216 100644 --- a/test/core-rules.js +++ b/test/core-rules.js @@ -19,7 +19,30 @@ const RuleTester = require("./fixtures/eslint/lib/testers/rule-tester") const RULES_ROOT = path.join(__dirname, "fixtures/eslint/tests/lib/rules") const PARSER_PATH = path.resolve(__dirname, "../index.js") +const EXCEPTIONS = new Set([ + // Those rules check outside `` + } return `` } @@ -40,13 +67,19 @@ function wrapCode(code) { */ function modifyPattern(pattern) { if (typeof pattern === "string") { + if (pattern.startsWith("#!")) { + return null + } return { code: wrapCode(pattern), filename: "test.vue", parser: PARSER_PATH, } } - if (pattern.parser != null || pattern.filename != null) { + if (pattern.parser != null || + pattern.filename != null || + pattern.code.startsWith("#!") + ) { return null } @@ -58,12 +91,14 @@ function modifyPattern(pattern) { } if (Array.isArray(pattern.errors)) { for (const error of pattern.errors) { - if (typeof error === "object") { + if (typeof error === "object" && !processed.has(error)) { + processed.add(error) + if (error.line != null) { - error.line += 1 + error.line = Number(error.line) + 1 } if (error.endLine != null) { - error.endLine += 1 + error.endLine = Number(error.endLine) + 1 } } } @@ -97,10 +132,17 @@ RuleTester.prototype.run = overrideRun try { describe("Tests of ESLint core rules", () => { for (const fileName of fs.readdirSync(RULES_ROOT)) { + if (path.extname(fileName) !== ".js" || + EXCEPTIONS.has(path.basename(fileName, ".js")) + ) { + continue + } + require(path.join(RULES_ROOT, fileName)) } }) } finally { RuleTester.prototype.run = originalRun + processed.clear() }