Skip to content

Commit

Permalink
fix: fix eslint cwd confusion during onCreateComplete hook execution (#…
Browse files Browse the repository at this point in the history
…3212)

* fix: fix eslint cwd confusion during onCreateComplete hook execution

fixes #2554
fixes #3142

* fix: do not mock process.cwd during invoking
  • Loading branch information
haoqunjiang authored Dec 30, 2018
1 parent 300efa9 commit 90d387f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/@vue/cli-plugin-eslint/__tests__/eslintGenerator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {}
}
})
})
11 changes: 11 additions & 0 deletions packages/@vue/cli-plugin-eslint/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 90d387f

Please sign in to comment.