fix: fix eslint cwd confusion during onCreateComplete hook execution (#3212)

* fix: fix eslint cwd confusion during onCreateComplete hook execution

fixes #2554
fixes #3142

* fix: do not mock process.cwd during invoking
This commit is contained in:
Haoqun Jiang
2018-12-30 17:45:07 +08:00
committed by GitHub
parent 300efa94bc
commit 90d387f650
2 changed files with 26 additions and 0 deletions

View File

@@ -163,3 +163,18 @@ test('append to existing .editorconfig', async () => {
expect(editorconfig).toMatch('root = true')
expect(editorconfig).toMatch('[*.{js,jsx,ts,tsx,vue}]')
})
test('airbnb config + typescript + unit-mocha', async () => {
await create('eslint-airbnb-typescript', {
plugins: {
'@vue/cli-plugin-eslint': {
config: 'airbnb',
lintOn: 'commit'
},
'@vue/cli-plugin-typescript': {
classComponent: true
},
'@vue/cli-plugin-unit-mocha': {}
}
})
})

View File

@@ -56,7 +56,18 @@ module.exports = function lint (args = {}, api) {
? args._
: defaultFilesToLint
// mock process.cwd before executing
// See:
// https://github.com/vuejs/vue-cli/issues/2554
// https://github.com/benmosher/eslint-plugin-import/issues/602
// https://github.com/eslint/eslint/issues/11218
const processCwd = process.cwd
if (!api.invoking) {
process.cwd = () => cwd
}
const report = engine.executeOnFiles(files)
process.cwd = processCwd
const formatter = engine.getFormatter(args.format || 'codeframe')
if (config.fix) {