Skip to content

Commit 5623695

Browse files
committed
fix: only add custom ignorePattern when no .eslintignore exists
closes vuejs#3243
1 parent 108d801 commit 5623695

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ test('should not fix with --no-fix option', async () => {
121121
expect(await read('src/main.js')).not.toMatch(';')
122122
})
123123

124-
// #3167
124+
// #3167, #3243
125125
test('should not throw when src folder is ignored by .eslintignore', async () => {
126126
const project = await create('eslint-ignore', {
127127
plugins: {
@@ -130,11 +130,12 @@ test('should not throw when src folder is ignored by .eslintignore', async () =>
130130
config: 'airbnb',
131131
lintOn: 'commit'
132132
}
133-
}
133+
},
134+
useConfigFiles: true
134135
})
135136

136137
const { write, run } = project
137-
await write('.eslintignore', 'src\n')
138+
await write('.eslintignore', 'src\n.eslintrc.js')
138139

139140
// should not throw
140141
await run('vue-cli-service lint')

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

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs')
12
const globby = require('globby')
23

34
const renamedArrayArgs = {
@@ -31,26 +32,34 @@ module.exports = function lint (args = {}, api) {
3132
cwd
3233
}, argsConfig)
3334

34-
const engine = new CLIEngine(config)
35+
if (!fs.existsSync(api.resolve('.eslintignore'))) {
36+
// .eslintrc.js files (ignored by default)
37+
// However, we need to lint & fix them so as to make the default generated project's
38+
// code style consistent with user's selected eslint config.
39+
// Though, if users provided their own `.eslintignore` file, we don't want to
40+
// add our own customized ignore pattern here (in eslint, ignorePattern is
41+
// an addition to eslintignore, i.e. it can't be overriden by user),
42+
// following the principle of least astonishment.
43+
config.ignorePattern = [
44+
'!.*.js',
45+
'!{src,tests}/**/.*.js'
46+
]
47+
}
3548

36-
// .eslintrc.js files (ignored by default)
37-
const dotFiles = [
38-
'.*.js',
39-
'{src,tests}/**/.*.js'
40-
].filter(pattern => globby.sync(path.join(cwd, pattern)).length)
49+
const engine = new CLIEngine(config)
4150

4251
const defaultFilesToLint = [
4352
'src',
4453
'tests',
4554
// root config files
46-
'*.js'
55+
'*.js',
56+
'.*.js'
4757
]
4858
.filter(pattern =>
4959
globby
5060
.sync(path.join(cwd, pattern))
5161
.some(p => !engine.isPathIgnored(p))
5262
)
53-
.concat(dotFiles)
5463

5564
const files = args._ && args._.length
5665
? args._

0 commit comments

Comments
 (0)