Skip to content

Commit 90d387f

Browse files
authored
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
1 parent 300efa9 commit 90d387f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,18 @@ test('append to existing .editorconfig', async () => {
163163
expect(editorconfig).toMatch('root = true')
164164
expect(editorconfig).toMatch('[*.{js,jsx,ts,tsx,vue}]')
165165
})
166+
167+
test('airbnb config + typescript + unit-mocha', async () => {
168+
await create('eslint-airbnb-typescript', {
169+
plugins: {
170+
'@vue/cli-plugin-eslint': {
171+
config: 'airbnb',
172+
lintOn: 'commit'
173+
},
174+
'@vue/cli-plugin-typescript': {
175+
classComponent: true
176+
},
177+
'@vue/cli-plugin-unit-mocha': {}
178+
}
179+
})
180+
})

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,18 @@ module.exports = function lint (args = {}, api) {
5656
? args._
5757
: defaultFilesToLint
5858

59+
// mock process.cwd before executing
60+
// See:
61+
// https://github.com/vuejs/vue-cli/issues/2554
62+
// https://github.com/benmosher/eslint-plugin-import/issues/602
63+
// https://github.com/eslint/eslint/issues/11218
64+
const processCwd = process.cwd
65+
if (!api.invoking) {
66+
process.cwd = () => cwd
67+
}
5968
const report = engine.executeOnFiles(files)
69+
process.cwd = processCwd
70+
6071
const formatter = engine.getFormatter(args.format || 'codeframe')
6172

6273
if (config.fix) {

0 commit comments

Comments
 (0)