Skip to content

Commit 9041497

Browse files
committed
fix(cli-plugin-eslint): fix(eslint-config-airbnb): default rules accept mutation of vuex „state“ argument.
close #3954
1 parent b916635 commit 9041497

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exports.config = api => {
1+
exports.config = (api, _config) => {
22
const config = {
33
root: true,
44
env: { node: true },
@@ -8,6 +8,22 @@ exports.config = api => {
88
'no-debugger': makeJSOnlyValue(`process.env.NODE_ENV === 'production' ? 'error' : 'off'`)
99
}
1010
}
11+
if (_config === 'airbnb') {
12+
config.rules['no-param-reassign'] = ['error', {
13+
props: true,
14+
ignorePropertyModificationsFor: [
15+
'state', // for vuex state
16+
'acc', // for reduce accumulators
17+
'e', // for e.returnvalue
18+
'ctx', // for Koa routing
19+
'req', // for Express requests
20+
'request', // for Express requests
21+
'res', // for Express responses
22+
'response', // for Express responses
23+
'$scope', // for Angular 1 scopes
24+
]
25+
}]
26+
}
1127
if (!api.hasPlugin('typescript')) {
1228
config.parserOptions = {
1329
parser: 'babel-eslint'

packages/@vue/cli-plugin-eslint/generator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = (api, { config, lintOn = [] }, _, invoking) => {
66
lintOn = lintOn.split(',')
77
}
88

9-
const eslintConfig = require('../eslintOptions').config(api)
9+
const eslintConfig = require('../eslintOptions').config(api, config)
1010

1111
const pkg = {
1212
scripts: {

packages/@vue/cli/__tests__/invoke.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,25 @@ async function assertUpdates (project) {
4343

4444
const eslintrc = parseJS(await project.read('.eslintrc.js'))
4545
expect(eslintrc).toEqual(Object.assign({}, baseESLintConfig, {
46-
extends: ['plugin:vue/essential', '@vue/airbnb']
46+
extends: ['plugin:vue/essential', '@vue/airbnb'],
47+
rules: {
48+
'no-console': 'off',
49+
'no-debugger': 'off',
50+
'no-param-reassign': ['error', {
51+
props: true,
52+
ignorePropertyModificationsFor: [
53+
'state', // for vuex state
54+
'acc', // for reduce accumulators
55+
'e', // for e.returnvalue
56+
'ctx', // for Koa routing
57+
'req', // for Express requests
58+
'request', // for Express requests
59+
'res', // for Express responses
60+
'response', // for Express responses
61+
'$scope' // for Angular 1 scopes
62+
]
63+
}]
64+
}
4765
}))
4866

4967
const lintedMain = await project.read('src/main.js')

0 commit comments

Comments
 (0)