Skip to content

Commit ea6151f

Browse files
fix: eslint formatter path error (#6134)
Co-authored-by: Binwei Fang <[email protected]>
1 parent 663bbd7 commit ea6151f

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

packages/@vue/cli-plugin-eslint/__tests__/eslintPlugin.spec.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
jest.setTimeout(35000)
1+
jest.setTimeout(300000)
22

33
const path = require('path')
44
const { linkBin } = require('@vue/cli/lib/util/linkBin')
@@ -225,3 +225,46 @@ test('should persist cache', async () => {
225225

226226
expect(has('node_modules/.cache/eslint/cache.json')).toBe(true)
227227
})
228+
229+
test(`should use formatter 'codeframe'`, async () => {
230+
const project = await create('eslint-formatter-codeframe', {
231+
plugins: {
232+
'@vue/cli-plugin-babel': {},
233+
'@vue/cli-plugin-eslint': {
234+
config: 'airbnb',
235+
lintOn: 'save'
236+
}
237+
}
238+
})
239+
const { read, write, run } = project
240+
const main = await read('src/main.js')
241+
expect(main).toMatch(';')
242+
243+
let done
244+
const donePromise = new Promise(resolve => {
245+
done = resolve
246+
})
247+
// remove semicolons
248+
const updatedMain = main.replace(/;/g, '')
249+
await write('src/main.js', updatedMain)
250+
251+
const server = run('vue-cli-service serve')
252+
253+
let isFirstMsg = true
254+
server.stdout.on('data', data => {
255+
data = data.toString()
256+
if (isFirstMsg) {
257+
expect(data).toMatch(/Failed to compile with \d error/)
258+
isFirstMsg = false
259+
} else if (data.match(/semi/)) {
260+
// check the format of output
261+
// https://eslint.org/docs/user-guide/formatters/#codeframe
262+
expect(data).toMatch(`error: Missing semicolon (semi) at src${path.sep}main.js`)
263+
264+
server.stdin.write('close')
265+
done()
266+
}
267+
})
268+
269+
await donePromise
270+
})

packages/@vue/cli-plugin-eslint/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = (api, options) => {
5252
resolveModule('eslint/package.json', cwd) ||
5353
resolveModule('eslint/package.json', __dirname)
5454
),
55-
formatter: loadModule('eslint/lib/formatters/codeframe', cwd, true)
55+
formatter: 'codeframe'
5656
}
5757
webpackConfig.plugin('eslint').use(eslintWebpackPlugin, [eslintWebpackPluginOptions])
5858
})

0 commit comments

Comments
 (0)