Skip to content

Commit 8136488

Browse files
committed
update testcase for node 8
1 parent 555112f commit 8136488

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

tests/fixtures/script-indent/ts-template-literal-type-01.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--{"parserOptions": {"parser":"@typescript-eslint/parser"}}-->
1+
<!--{"parserOptions": {"parser":"@typescript-eslint/parser"}, "requirements": { "@typescript-eslint/parser": ">=4.1.0" } }-->
22
<script lang="ts">
33
type T =
44
`foo`

tests/lib/rules/script-indent.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
const fs = require('fs')
1313
const path = require('path')
14+
const semver = require('semver')
1415
const RuleTester = require('eslint').RuleTester
1516
const rule = require('../../../lib/rules/script-indent')
1617

@@ -36,21 +37,37 @@ const FIXTURE_ROOT = path.resolve(__dirname, '../../fixtures/script-indent/')
3637
* @returns {object} The loaded patterns.
3738
*/
3839
function loadPatterns(additionalValid, additionalInvalid) {
39-
const valid = fs.readdirSync(FIXTURE_ROOT).map((filename) => {
40-
const commentPattern = /^(<!--|\/\*)(.+?)(-->|\*\/)/
41-
const code0 = fs.readFileSync(path.join(FIXTURE_ROOT, filename), 'utf8')
42-
const code = code0.replace(commentPattern, `$1${filename}$3`)
43-
const baseObj = JSON.parse(commentPattern.exec(code0)[2])
44-
if ('parser' in baseObj) {
45-
baseObj.parser = require.resolve(baseObj.parser)
46-
}
47-
if ('parserOptions' in baseObj && 'parser' in baseObj.parserOptions) {
48-
baseObj.parserOptions.parser = require.resolve(
49-
baseObj.parserOptions.parser
50-
)
51-
}
52-
return Object.assign(baseObj, { code, filename })
53-
})
40+
const valid = fs
41+
.readdirSync(FIXTURE_ROOT)
42+
.map((filename) => {
43+
const commentPattern = /^(<!--|\/\*)(.+?)(-->|\*\/)/
44+
const code0 = fs.readFileSync(path.join(FIXTURE_ROOT, filename), 'utf8')
45+
const code = code0.replace(commentPattern, `$1${filename}$3`)
46+
const baseObj = JSON.parse(commentPattern.exec(code0)[2])
47+
if ('parser' in baseObj) {
48+
baseObj.parser = require.resolve(baseObj.parser)
49+
}
50+
if ('parserOptions' in baseObj && 'parser' in baseObj.parserOptions) {
51+
baseObj.parserOptions.parser = require.resolve(
52+
baseObj.parserOptions.parser
53+
)
54+
}
55+
return Object.assign(baseObj, { code, filename })
56+
})
57+
.filter((obj) => {
58+
if (obj.requirements) {
59+
if (
60+
Object.entries(obj.requirements).some(([pkgName, pkgVersion]) => {
61+
const pkg = require(`${pkgName}/package.json`)
62+
return !semver.satisfies(pkg.version, pkgVersion)
63+
})
64+
) {
65+
return false
66+
}
67+
delete obj.requirements
68+
}
69+
return true
70+
})
5471
const invalid = valid
5572
.map((pattern) => {
5673
const kind =

0 commit comments

Comments
 (0)