Skip to content

Commit

Permalink
Add test for ESLint v8 (#122)
Browse files Browse the repository at this point in the history
* Add test for ESLint v8

* fix

* fix

* fix

* fix

* fix babel

* fix

* fix test

* fix

* fix

* fix

* fix

* fix

* fix
  • Loading branch information
ota-meshi committed Aug 19, 2021
1 parent 36f1766 commit 184dc09
Show file tree
Hide file tree
Showing 51 changed files with 1,227 additions and 209 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
name: Test
strategy:
matrix:
eslint: [7]
node: [14]
eslint: [7, '8.0.0-0']
node: [14, 16]
os: [ubuntu-latest]
include:
# On other platforms
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"semver": "^6.3.0"
},
"devDependencies": {
"@babel/core": "^7.15.0",
"@babel/eslint-parser": "^7.15.0",
"@babel/plugin-syntax-decorators": "^7.14.5",
"@babel/plugin-syntax-pipeline-operator": "^7.15.0",
"@babel/plugin-syntax-typescript": "^7.14.5",
"@mysticatea/eslint-plugin": "^13.0.0",
"@types/debug": "0.0.30",
"@types/eslint": "^7.2.6",
Expand Down Expand Up @@ -67,7 +72,7 @@
"pretest": "run-s build lint",
"test": "npm run -s test:mocha",
"test:mocha": "nyc mocha \"test/*.js\" --reporter dot --timeout 60000",
"test:debug": "mocha --inspect --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 60000",
"test:debug": "mocha --require ts-node/register/transpile-only \"test/*.js\" --reporter dot --timeout 60000",
"preupdate-fixtures": "npm run -s build",
"update-fixtures": "node scripts/update-fixtures-ast.js && node scripts/update-fixtures-document-fragment.js",
"preversion": "npm test",
Expand Down
10 changes: 5 additions & 5 deletions scripts/ci-install-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function sh(command) {
return new Promise((resolve, reject) => {
spawn(command, [], { shell: true, stdio: "inherit" })
.on("error", reject)
.on("exit", exitCode => {
.on("exit", (exitCode) => {
if (exitCode) {
reject(new Error(`Exit with non-zero ${exitCode}`))
} else {
Expand All @@ -29,19 +29,19 @@ function sh(command) {
: `^${requestedVersion}`

// Install ESLint of the requested version
await sh(`npm install eslint@${requestedVersionSpec}`)
await sh(`npm install eslint@${requestedVersionSpec} --legacy-peer-deps`)

// Install ESLint submodule of the requested version
const installedVersion = require("eslint").CLIEngine.version
const installedVersion = require("eslint/package.json").version
cd("test/fixtures/eslint")
if (!installedVersion.startsWith("7.")) {
await sh(`git checkout v${installedVersion}`)
}
if (installedVersion.startsWith("5.")) {
await sh("npm install eslint-utils@1.4.0")
}
await sh("npm install")
})().catch(error => {
await sh("npm install --legacy-peer-deps")
})().catch((error) => {
console.error(error)
process.exitCode = 1
})
7 changes: 5 additions & 2 deletions scripts/update-fixtures-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ for (const name of TARGETS) {
: {}
if (
Object.entries(requirements).some(([pkgName, pkgVersion]) => {
const pkg = require(`${pkgName}/package.json`)
return !semver.satisfies(pkg.version, pkgVersion)
const version =
pkgName === "node"
? process.version
: require(`${pkgName}/package.json`).version
return !semver.satisfies(version, pkgVersion)
})
) {
continue
Expand Down
7 changes: 5 additions & 2 deletions test/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,11 @@ describe("Template AST", () => {

if (
Object.entries(requirements).some(([pkgName, pkgVersion]) => {
const pkg = require(`${pkgName}/package.json`)
return !semver.satisfies(pkg.version, pkgVersion)
const version =
pkgName === "node"
? process.version
: require(`${pkgName}/package.json`).version
return !semver.satisfies(version, pkgVersion)
})
) {
continue
Expand Down
27 changes: 25 additions & 2 deletions test/core-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@ function modifyPattern(ruleId, pattern) {

// Ignore for now
if (
ruleId === "newline-per-chained-call" &&
pattern.code === "foo.bar()['foo' + \u2029 + 'bar']()"
(ruleId === "newline-per-chained-call" &&
pattern.code === "foo.bar()['foo' + \u2029 + 'bar']()") ||
(ruleId === "no-nonoctal-decimal-escape" &&
pattern.code === "'\\\r\n\\9'") ||
// The location is reported as a fixed value: { line: 1, column: 0 }.
(ruleId === "consistent-return" &&
pattern.parserOptions &&
pattern.parserOptions.ecmaFeatures &&
pattern.parserOptions.ecmaFeatures.globalReturn === true)
) {
return null
}
Expand Down Expand Up @@ -151,6 +158,22 @@ function modifyPattern(ruleId, pattern) {
}
}

// `no-shadow` rule is special a bit.
if (ruleId === "no-shadow") {
// The data that the rule gives to the message contains the location.
if (
error.data &&
error.data &&
Object.hasOwnProperty.call(
error.data,
"shadowedLine"
) &&
typeof error.data.shadowedLine === "number"
) {
error.data.shadowedLine++
}
}

// Wrap the code by `<script>` tag.
if (Array.isArray(error.suggestions)) {
for (const suggestion of error.suggestions) {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/ast/end-of-line01/requirements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint": "<8"
}
3 changes: 3 additions & 0 deletions test/fixtures/ast/end-of-line02/requirements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eslint": "<8"
}
Loading

0 comments on commit 184dc09

Please sign in to comment.