Skip to content

Commit 2c8b987

Browse files
committed
feat: switch to eslint class
1 parent e20d4dc commit 2c8b987

File tree

1 file changed

+29
-36
lines changed

1 file changed

+29
-36
lines changed

tests-integrations/flat-config.ts

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
11
import cp from 'child_process'
22
import path from 'path'
33
import assert from 'assert'
4-
import semver from 'semver'
5-
import { readPackageJson } from './helper'
64

75
const TEST_CWD = path.join(__dirname, 'flat-config')
8-
const ESLINT = `.${path.sep}node_modules${path.sep}.bin${path.sep}eslint`
96

10-
describe('Integration with flat config', () => {
7+
describe('Integration with Flat config', () => {
118
let originalCwd: string
129

1310
before(() => {
14-
originalCwd = process.cwd();
15-
process.chdir(TEST_CWD);
16-
try {
17-
cp.execSync('yarn', { stdio: 'inherit' });
18-
} catch (error) {
19-
console.error('Error running yarn:', error);
20-
throw error;
21-
}
22-
});
11+
originalCwd = process.cwd()
12+
process.chdir(TEST_CWD)
13+
cp.execSync('yarn', { stdio: 'inherit' })
14+
})
2315
after(() => {
24-
originalCwd && process.chdir(originalCwd)
16+
process.chdir(originalCwd)
2517
})
2618

27-
it('should work with flat config', async () => {
28-
if (
29-
!semver.satisfies(
30-
process.version,
31-
readPackageJson(
32-
path.resolve(__dirname, './flat-config/node_modules/eslint')
33-
).engines.node
34-
)
35-
) {
36-
return
37-
}
38-
const cliResult = cp.execSync(`${ESLINT} src/* --format=json`, {
39-
encoding: 'utf-8'
19+
it('should work with Flat config', async () => {
20+
const ESLint = require('./flat-config/node_modules/eslint').ESLint
21+
const engine = new ESLint({
22+
cwd: TEST_CWD
4023
})
4124

42-
const result = JSON.parse(cliResult)
25+
try {
26+
const results = await engine.lintFiles(['./src'])
4327

44-
const aSvelte = result.find(
45-
(r: { filePath: string }) => path.basename(r.filePath) === 'a.svelte'
46-
)
47-
assert.strictEqual(aSvelte.messages.length, 1)
48-
assert.strictEqual(
49-
aSvelte.messages[0].ruleId,
50-
'@intlify/svelte/no-raw-text'
51-
)
28+
const aSvelte = results.find(
29+
(r: { filePath: string }) => path.basename(r.filePath) === 'a.svelte'
30+
)
31+
32+
if (!aSvelte) {
33+
throw new Error('a.svelte file not found in lint results')
34+
}
35+
36+
assert.strictEqual(aSvelte.messages.length, 1)
37+
assert.strictEqual(
38+
aSvelte.messages[0].ruleId,
39+
'@intlify/svelte/no-raw-text'
40+
)
41+
} catch (error) {
42+
console.error('Error during linting:', error)
43+
throw error
44+
}
5245
})
5346
})

0 commit comments

Comments
 (0)