Skip to content

Commit

Permalink
🐛 fix for ESLint 6 (fixes #24) (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored Jun 20, 2019
1 parent 87165ed commit d6a9fd2
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 71 deletions.
8 changes: 8 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ jobs:
nodeVersion: 12.x
eslintVersion: 4.x

- template: .azure-pipelines/test-job.yml
parameters:
name: test_on_linux_node12_eslint6rc
displayName: Test on Node 12, ESLint 6 RC, Linux
vmImage: Ubuntu-16.04
nodeVersion: 12.x
eslintVersion: ^6.0.0-rc.0

- template: .azure-pipelines/test-job.yml
parameters:
name: test_on_windows_node12_eslint5
Expand Down
7 changes: 3 additions & 4 deletions lib/utils/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,9 @@ function convert(messages, sourceCode, ruleId, severity, keepAsIs) {

module.exports = (ruleId = "eslint-comments/no-unused-disable") => {
for (const Linter of getLinters()) {
const verify0 = Linter.prototype.verify

Object.defineProperty(Linter.prototype, "verify", {
value: function verify(
const verify0 = Linter.prototype._verifyWithoutProcessors
Object.defineProperty(Linter.prototype, "_verifyWithoutProcessors", {
value: function _verifyWithoutProcessors(
textOrSourceCode,
config,
filenameOrOptions
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/disable-enable-pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ console.log('This code does not even have any special comments')
},
{
code: `
/*eslint-disable no-unused-var, no-undef */
/*eslint-disable no-unused-vars, no-undef */
var foo = 1
`,
options: [{ allowWholeFile: true }],
Expand Down
36 changes: 18 additions & 18 deletions tests/lib/rules/no-aggregating-enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ const tester = new RuleTester()
tester.run("no-aggregating-enable", rule, {
valid: [
`
/*eslint-disable a*/
/*eslint-enable a*/
/*eslint-disable no-redeclare*/
/*eslint-enable no-redeclare*/
`,
`
/*eslint-disable a*/
/*eslint-enable b*/
/*eslint-disable no-redeclare*/
/*eslint-enable no-shadow*/
`,
`
/*eslint-disable a, b*/
/*eslint-disable no-redeclare, no-shadow*/
/*eslint-enable*/
`,
`
/*eslint-disable a, b*/
/*eslint-enable a, b*/
/*eslint-disable no-redeclare, no-shadow*/
/*eslint-enable no-redeclare, no-shadow*/
`,
`
/*eslint-disable a, b*/
/*eslint-enable a*/
/*eslint-enable b*/
/*eslint-disable no-redeclare, no-shadow*/
/*eslint-enable no-redeclare*/
/*eslint-enable no-shadow*/
`,
],
invalid: [
{
code: `
/*eslint-disable a*/
/*eslint-disable b*/
/*eslint-disable no-redeclare*/
/*eslint-disable no-shadow*/
/*eslint-enable*/
`,
errors: [
Expand All @@ -45,9 +45,9 @@ tester.run("no-aggregating-enable", rule, {
},
{
code: `
/*eslint-disable a*/
/*eslint-disable b*/
/*eslint-disable c*/
/*eslint-disable no-redeclare*/
/*eslint-disable no-shadow*/
/*eslint-disable no-undef*/
/*eslint-enable*/
`,
errors: [
Expand All @@ -56,9 +56,9 @@ tester.run("no-aggregating-enable", rule, {
},
{
code: `
/*eslint-disable a*/
/*eslint-disable b*/
/*eslint-enable a, b*/
/*eslint-disable no-redeclare*/
/*eslint-disable no-shadow*/
/*eslint-enable no-redeclare, no-shadow*/
`,
errors: [
"This `eslint-enable` comment affects 2 `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
Expand Down
87 changes: 46 additions & 41 deletions tests/lib/rules/no-restricted-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,89 +4,93 @@
*/
"use strict"

const RuleTester = require("eslint").RuleTester
const { Linter, RuleTester } = require("eslint")
const rule = require("../../../lib/rules/no-restricted-disable")
const coreRules = new Linter().getRules()
const tester = new RuleTester()

tester.defineRule("foo/no-undef", coreRules.get("no-undef"))
tester.defineRule("foo/no-redeclare", coreRules.get("no-redeclare"))

tester.run("no-restricted-disable", rule, {
valid: [
"/*eslint-disable*/",
"//eslint-disable-line",
"//eslint-disable-next-line",
{
code: "/*eslint-disable b*/",
options: ["a"],
code: "/*eslint-disable eqeqeq*/",
options: ["no-unused-vars"],
},
{
code: "/*eslint-enable a*/",
options: ["a"],
code: "/*eslint-enable eqeqeq*/",
options: ["eqeqeq"],
},
{
code: "/*eslint-disable a*/",
options: ["*", "!a"],
code: "/*eslint-disable eqeqeq*/",
options: ["*", "!eqeqeq"],
},
],
invalid: [
{
code: "/*eslint-disable a*/",
options: ["a"],
errors: ["Disabling 'a' is not allowed."],
code: "/*eslint-disable eqeqeq*/",
options: ["eqeqeq"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
{
code: "/*eslint-disable*/",
options: ["a"],
errors: ["Disabling 'a' is not allowed."],
options: ["eqeqeq"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
{
code: "//eslint-disable-line a",
options: ["a"],
errors: ["Disabling 'a' is not allowed."],
code: "//eslint-disable-line eqeqeq",
options: ["eqeqeq"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
{
code: "//eslint-disable-line",
options: ["a"],
errors: ["Disabling 'a' is not allowed."],
options: ["eqeqeq"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
{
code: "//eslint-disable-next-line a",
options: ["a"],
errors: ["Disabling 'a' is not allowed."],
code: "//eslint-disable-next-line eqeqeq",
options: ["eqeqeq"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
{
code: "//eslint-disable-next-line",
options: ["a"],
errors: ["Disabling 'a' is not allowed."],
options: ["eqeqeq"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},

{
code: "/*eslint-disable a, b, c*/",
options: ["*", "!b", "!c"],
errors: ["Disabling 'a' is not allowed."],
code: "/*eslint-disable eqeqeq, no-undef, no-redeclare*/",
options: ["*", "!no-undef", "!no-redeclare"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
{
code: "/*eslint-disable*/",
options: ["*", "!b", "!c"],
errors: ["Disabling '*,!b,!c' is not allowed."],
options: ["*", "!no-undef", "!no-redeclare"],
errors: ["Disabling '*,!no-undef,!no-redeclare' is not allowed."],
},
{
code: "//eslint-disable-line a, b, c",
options: ["*", "!b", "!c"],
errors: ["Disabling 'a' is not allowed."],
code: "//eslint-disable-line eqeqeq, no-undef, no-redeclare",
options: ["*", "!no-undef", "!no-redeclare"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
{
code: "//eslint-disable-line",
options: ["*", "!b", "!c"],
errors: ["Disabling '*,!b,!c' is not allowed."],
options: ["*", "!no-undef", "!no-redeclare"],
errors: ["Disabling '*,!no-undef,!no-redeclare' is not allowed."],
},
{
code: "//eslint-disable-next-line a, b, c",
options: ["*", "!b", "!c"],
errors: ["Disabling 'a' is not allowed."],
code: "//eslint-disable-next-line eqeqeq, no-undef, no-redeclare",
options: ["*", "!no-undef", "!no-redeclare"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
{
code: "//eslint-disable-next-line",
options: ["*", "!b", "!c"],
errors: ["Disabling '*,!b,!c' is not allowed."],
options: ["*", "!no-undef", "!no-redeclare"],
errors: ["Disabling '*,!no-undef,!no-redeclare' is not allowed."],
},

{
Expand All @@ -100,11 +104,12 @@ tester.run("no-restricted-disable", rule, {
],
},
{
code: "/*eslint-disable a, b, react/a, react/b*/",
options: ["react/*"],
code:
"/*eslint-disable no-undef, no-redeclare, foo/no-undef, foo/no-redeclare*/",
options: ["foo/*"],
errors: [
"Disabling 'react/a' is not allowed.",
"Disabling 'react/b' is not allowed.",
"Disabling 'foo/no-undef' is not allowed.",
"Disabling 'foo/no-redeclare' is not allowed.",
],
},
],
Expand Down
8 changes: 4 additions & 4 deletions tests/lib/rules/no-unlimited-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const tester = new RuleTester()
tester.run("no-unlimited-disable", rule, {
valid: [
"/*eslint-enable*/",
"/*eslint-disable foo*/",
"//eslint-disable-line foo",
"//eslint-disable-next-line foo",
"var foo;\n//eslint-disable-line foo",
"/*eslint-disable eqeqeq*/",
"//eslint-disable-line eqeqeq",
"//eslint-disable-next-line eqeqeq",
"var foo;\n//eslint-disable-line eqeqeq",
],
invalid: [
{
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/rules/no-unused-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,18 @@ var a = b//eslint-disable-line no-undef`,
/*eslint-disable
no-undef,
no-unused-vars,
xxxx
eqeqeq
*/
var a = b
/*eslint-enable*/`,
errors: [
{
message: "'xxxx' rule is disabled but never reported.",
message:
"'eqeqeq' rule is disabled but never reported.",
line: 5,
column: 5,
endLine: 5,
endColumn: 9,
endColumn: 11,
},
],
},
Expand Down

0 comments on commit d6a9fd2

Please sign in to comment.