Files
vue-cli/packages/@vue/cli-plugin-eslint/index.js
Haoqun Jiang b70e0f6970 feat!: require ESLint as a peer dependency (#3852)
BREAKING CHANGE:
Users will have to explicitly list their required ESLint version in the
project's package.json.

The major concern behind this change is that ESLint release schedule is
never aligned with Vue CLI's.
See https://eslint.org/blog/2019/04/eslint-v6.0.0-alpha.0-released
So even if we upgraded our built-in ESLint version to v5, we'll see a
new major release of ESLint in the coming months. Meanwhile we can't
easily upgrade the built-in ESLint version again without bumping our
major version number. This could become a maintenance nightmare.
2019-04-30 10:18:03 +08:00

84 lines
2.7 KiB
JavaScript

const path = require('path')
module.exports = (api, options) => {
if (options.lintOnSave) {
const extensions = require('./eslintOptions').extensions(api)
// Use loadModule to allow users to customize their ESLint dependency version.
const { resolveModule, loadModule } = require('@vue/cli-shared-utils')
const cwd = api.getCwd()
const eslintPkg = loadModule('eslint/package.json', cwd, true)
// eslint-loader doesn't bust cache when eslint config changes
// so we have to manually generate a cache identifier that takes the config
// into account.
const { cacheIdentifier } = api.genCacheConfig(
'eslint-loader',
{
'eslint-loader': require('eslint-loader/package.json').version,
eslint: eslintPkg.version
},
[
'.eslintrc.js',
'.eslintrc.yaml',
'.eslintrc.yml',
'.eslintrc.json',
'.eslintrc',
'package.json'
]
)
api.chainWebpack(webpackConfig => {
webpackConfig.resolveLoader.modules.prepend(
path.join(__dirname, 'node_modules')
)
const { lintOnSave } = options
const allWarnings = lintOnSave === true || lintOnSave === 'warning'
const allErrors = lintOnSave === 'error'
webpackConfig.module
.rule('eslint')
.pre()
.exclude
.add(/node_modules/)
.add(path.dirname(require.resolve('@vue/cli-service')))
.end()
.test(/\.(vue|(j|t)sx?)$/)
.use('eslint-loader')
.loader('eslint-loader')
.options({
extensions,
cache: true,
cacheIdentifier,
emitWarning: allWarnings,
// only emit errors in production mode.
emitError: allErrors,
eslintPath: resolveModule('eslint', cwd),
formatter: loadModule('eslint/lib/formatters/codeframe', cwd, true)
})
})
}
api.registerCommand(
'lint',
{
description: 'lint and fix source files',
usage: 'vue-cli-service lint [options] [...files]',
options: {
'--format [formatter]': 'specify formatter (default: codeframe)',
'--no-fix': 'do not fix errors or warnings',
'--no-fix-warnings': 'fix errors, but do not fix warnings',
'--max-errors [limit]':
'specify number of errors to make build failed (default: 0)',
'--max-warnings [limit]':
'specify number of warnings to make build failed (default: Infinity)'
},
details:
'For more options, see https://eslint.org/docs/user-guide/command-line-interface#options'
},
args => {
require('./lint')(args, api)
}
)
}