-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add support for
eslint-disable-line
block comments and directive …
…comments with descriptions. (#43)
- Loading branch information
Showing
14 changed files
with
704 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* Test that multi-line eslint-disable-line comments are not false positives. | ||
*/ | ||
"use strict" | ||
|
||
const assert = require("assert") | ||
const fs = require("fs") | ||
const path = require("path") | ||
const spawn = require("cross-spawn") | ||
const rimraf = require("rimraf") | ||
const semver = require("semver") | ||
const eslintVersion = require("eslint/package").version | ||
|
||
/** | ||
* Run eslint CLI command with a given source code. | ||
* @param {string} code The source code to lint. | ||
* @returns {Promise<Message[]>} The result message. | ||
*/ | ||
function runESLint(code) { | ||
return new Promise((resolve, reject) => { | ||
const cp = spawn( | ||
"eslint", | ||
[ | ||
"--stdin", | ||
"--stdin-filename", | ||
"test.js", | ||
"--no-eslintrc", | ||
"--plugin", | ||
"eslint-comments", | ||
"--format", | ||
"json", | ||
], | ||
{ stdio: ["pipe", "pipe", "inherit"] } | ||
) | ||
const chunks = [] | ||
let totalLength = 0 | ||
|
||
cp.stdout.on("data", chunk => { | ||
chunks.push(chunk) | ||
totalLength += chunk.length | ||
}) | ||
cp.stdout.on("end", () => { | ||
try { | ||
const resultsStr = String(Buffer.concat(chunks, totalLength)) | ||
const results = JSON.parse(resultsStr) | ||
resolve(results[0].messages) | ||
} catch (error) { | ||
reject(error) | ||
} | ||
}) | ||
cp.on("error", reject) | ||
|
||
cp.stdin.end(code) | ||
}) | ||
} | ||
|
||
describe("multi-line eslint-disable-line comments", () => { | ||
before(() => { | ||
// Register this plugin. | ||
const selfPath = path.resolve(__dirname, "../../") | ||
const pluginPath = path.resolve( | ||
__dirname, | ||
"../../node_modules/eslint-plugin-eslint-comments" | ||
) | ||
|
||
if (fs.existsSync(pluginPath)) { | ||
rimraf.sync(pluginPath) | ||
} | ||
fs.symlinkSync(selfPath, pluginPath, "junction") | ||
}) | ||
|
||
describe("`eslint-comments/*` rules are valid", () => { | ||
for (const code of [ | ||
`/* eslint eslint-comments/no-use:[error, {allow: ['eslint']}] */ | ||
/* eslint-disable-line | ||
*/ | ||
/* eslint-disable-next-line | ||
*/`, | ||
`/* eslint eslint-comments/no-duplicate-disable:error */ | ||
/*eslint-disable no-undef*/ | ||
/*eslint-disable-line | ||
no-undef*/ | ||
`, | ||
]) { | ||
it(code, () => | ||
runESLint(code).then(messages => { | ||
if (semver.satisfies(eslintVersion, ">=5.0.0")) { | ||
assert.strictEqual(messages.length > 0, true) | ||
} | ||
const normalMessages = messages.filter( | ||
message => message.ruleId != null | ||
) | ||
assert.strictEqual(normalMessages.length, 0) | ||
}) | ||
) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.