Skip to content

Commit

Permalink
Fixed test case
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi committed May 11, 2020
1 parent 882083c commit 2b34e17
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 60 deletions.
8 changes: 8 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jobs:
nodeVersion: 12.x
eslintVersion: ^6.0.0-rc.0

- template: .azure-pipelines/test-job.yml
parameters:
name: test_on_linux_node14_eslint7
displayName: Test on Node 14, ESLint 7, Linux
vmImage: Ubuntu-16.04
nodeVersion: 14.x
eslintVersion: ^7.0.0

- template: .azure-pipelines/test-job.yml
parameters:
name: test_on_windows_node12_eslint5
Expand Down
8 changes: 6 additions & 2 deletions tests/lib/illegal-eslint-disable-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ 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.
Expand Down Expand Up @@ -52,7 +54,7 @@ function runESLint(code) {
})
}

describe("no-unused-disable", () => {
describe("multi-line eslint-disable-line comments", () => {
before(() => {
// Register this plugin.
const selfPath = path.resolve(__dirname, "../../")
Expand Down Expand Up @@ -82,7 +84,9 @@ no-undef*/
]) {
it(code, () =>
runESLint(code).then(messages => {
assert.strictEqual(messages.length > 0, true)
if (semver.satisfies(eslintVersion, ">=5.0.0")) {
assert.strictEqual(messages.length > 0, true)
}
const normalMessages = messages.filter(
message => message.ruleId != null
)
Expand Down
42 changes: 26 additions & 16 deletions tests/lib/rules/disable-enable-pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
"use strict"

const semver = require("semver")
const eslintVersion = require("eslint/package").version
const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/disable-enable-pair")
const tester = new RuleTester()
Expand Down Expand Up @@ -79,14 +81,18 @@ var foo = 1
options: [{ allowWholeFile: true }],
},
// -- description
`
...(semver.satisfies(eslintVersion, ">=7.0.0 || <6.0.0")
? [
`
/*eslint-disable no-undef -- description*/
/*eslint-enable no-undef*/
`,
`
`
/*eslint-disable no-undef,no-unused-vars -- description*/
/*eslint-enable no-undef,no-unused-vars*/
`,
]
: []),
],
invalid: [
{
Expand Down Expand Up @@ -205,23 +211,27 @@ console.log();
],
},
// -- description
{
code: `
...(semver.satisfies(eslintVersion, ">=7.0.0 || <6.0.0")
? [
{
code: `
{
/*eslint-disable no-unused-vars -- description */
}
`,
options: [{ allowWholeFile: true }],
errors: [
{
message:
"Requires 'eslint-enable' directive for 'no-unused-vars'.",
line: 3,
column: 18,
endLine: 3,
endColumn: 32,
},
],
},
options: [{ allowWholeFile: true }],
errors: [
{
message:
"Requires 'eslint-enable' directive for 'no-unused-vars'.",
line: 3,
column: 18,
endLine: 3,
endColumn: 32,
},
],
},
]
: []),
],
})
18 changes: 12 additions & 6 deletions tests/lib/rules/no-aggregating-enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
"use strict"

const semver = require("semver")
const eslintVersion = require("eslint/package").version
const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/no-aggregating-enable")
const tester = new RuleTester()
Expand Down Expand Up @@ -65,15 +67,19 @@ tester.run("no-aggregating-enable", rule, {
],
},
// -- description
{
code: `
...(semver.satisfies(eslintVersion, ">=7.0.0 || <6.0.0")
? [
{
code: `
/*eslint-disable no-redeclare*/
/*eslint-disable no-shadow*/
/*eslint-enable -- description*/
`,
errors: [
"This `eslint-enable` comment affects 2 `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
],
},
errors: [
"This `eslint-enable` comment affects 2 `eslint-disable` comments. An `eslint-enable` comment should be for an `eslint-disable` comment.",
],
},
]
: []),
],
})
31 changes: 19 additions & 12 deletions tests/lib/rules/no-duplicate-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
"use strict"

const semver = require("semver")
const eslintVersion = require("eslint/package").version
const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/no-duplicate-disable")
const tester = new RuleTester()
Expand Down Expand Up @@ -121,20 +123,25 @@ tester.run("no-duplicate-disable", rule, {
],
},
// -- description
{
code: `
...(semver.satisfies(eslintVersion, ">=7.0.0 || <6.0.0")
? [
{
code: `
// eslint-disable-next-line no-undef -- description
// eslint-disable-line no-undef -- description
`,
errors: [
{
message: "'no-undef' rule has been disabled already.",
line: 3,
column: 24,
endLine: 3,
endColumn: 32,
},
],
},
errors: [
{
message:
"'no-undef' rule has been disabled already.",
line: 3,
column: 24,
endLine: 3,
endColumn: 32,
},
],
},
]
: []),
],
})
16 changes: 11 additions & 5 deletions tests/lib/rules/no-restricted-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
"use strict"

const semver = require("semver")
const eslintVersion = require("eslint/package").version
const { Linter, RuleTester } = require("eslint")
const rule = require("../../../lib/rules/no-restricted-disable")
const coreRules = new Linter().getRules()
Expand Down Expand Up @@ -155,10 +157,14 @@ tester.run("no-restricted-disable", rule, {
],
},
// -- description
{
code: "/*eslint-disable -- description*/",
options: ["eqeqeq"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
...(semver.satisfies(eslintVersion, ">=7.0.0 || <6.0.0")
? [
{
code: "/*eslint-disable -- description*/",
options: ["eqeqeq"],
errors: ["Disabling 'eqeqeq' is not allowed."],
},
]
: []),
],
})
18 changes: 12 additions & 6 deletions tests/lib/rules/no-unlimited-disable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
"use strict"

const semver = require("semver")
const eslintVersion = require("eslint/package").version
const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/no-unlimited-disable")
const tester = new RuleTester()
Expand Down Expand Up @@ -93,11 +95,15 @@ tester.run("no-unlimited-disable", rule, {
],
},
// -- description
{
code: "/*eslint-disable -- description */",
errors: [
"Unexpected unlimited 'eslint-disable' comment. Specify some rule names to disable.",
],
},
...(semver.satisfies(eslintVersion, ">=7.0.0 || <6.0.0")
? [
{
code: "/*eslint-disable -- description */",
errors: [
"Unexpected unlimited 'eslint-disable' comment. Specify some rule names to disable.",
],
},
]
: []),
],
})
32 changes: 19 additions & 13 deletions tests/lib/rules/no-unused-enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
"use strict"

const semver = require("semver")
const eslintVersion = require("eslint/package").version
const RuleTester = require("eslint").RuleTester
const rule = require("../../../lib/rules/no-unused-enable")
const tester = new RuleTester()
Expand Down Expand Up @@ -85,18 +87,22 @@ var a = b
],
},
// -- description
{
code: "/*eslint-enable -- description*/",
errors: [
{
message:
"ESLint rules are re-enabled but those have not been disabled.",
line: 1,
column: 0,
endLine: 1,
endColumn: 33,
},
],
},
...(semver.satisfies(eslintVersion, ">=7.0.0 || <6.0.0")
? [
{
code: "/*eslint-enable -- description*/",
errors: [
{
message:
"ESLint rules are re-enabled but those have not been disabled.",
line: 1,
column: 0,
endLine: 1,
endColumn: 33,
},
],
},
]
: []),
],
})

0 comments on commit 2b34e17

Please sign in to comment.