Skip to content

fix: only add custom ignorePattern when no .eslintignore exists #3325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test('should not fix with --no-fix option', async () => {
expect(await read('src/main.js')).not.toMatch(';')
})

// #3167
// #3167, #3243
test('should not throw when src folder is ignored by .eslintignore', async () => {
const project = await create('eslint-ignore', {
plugins: {
Expand All @@ -130,11 +130,12 @@ test('should not throw when src folder is ignored by .eslintignore', async () =>
config: 'airbnb',
lintOn: 'commit'
}
}
},
useConfigFiles: true
})

const { write, run } = project
await write('.eslintignore', 'src\n')
await write('.eslintignore', 'src\n.eslintrc.js')

// should not throw
await run('vue-cli-service lint')
Expand Down
25 changes: 17 additions & 8 deletions packages/@vue/cli-plugin-eslint/lint.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs')
const globby = require('globby')

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

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

// .eslintrc.js files (ignored by default)
const dotFiles = [
'.*.js',
'{src,tests}/**/.*.js'
].filter(pattern => globby.sync(path.join(cwd, pattern)).length)
const engine = new CLIEngine(config)

const defaultFilesToLint = [
'src',
'tests',
// root config files
'*.js'
'*.js',
'.*.js'
]
.filter(pattern =>
globby
.sync(path.join(cwd, pattern))
.some(p => !engine.isPathIgnored(p))
)
.concat(dotFiles)

const files = args._ && args._.length
? args._
Expand Down