From e333b8b86c6e6d36e1095aa4d16a5023bff0c0fe Mon Sep 17 00:00:00 2001 From: Vesa Laakso Date: Sat, 17 Sep 2016 00:38:42 +0300 Subject: [PATCH] Exempt variables prefixed with underscore from no-unused-vars rule (#640) * Split no-unused-vars ESLint config to multiple lines * Exempt variables prefixed with underscore from no-unused-vars rule This is useful when e.g. using object spread operator to remove only a certain field from the object. For example, this can be used to ignore a property from React component's `this.props`: render() { const { someAttribute: _unused, ...rest } = this.props; return
{ JSON.stringify(rest) }
; } --- config/eslint.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/eslint.js b/config/eslint.js index 9c77d1f7b39..d83c66a85f7 100644 --- a/config/eslint.js +++ b/config/eslint.js @@ -131,7 +131,11 @@ module.exports = { 'no-unreachable': 'warn', 'no-unused-expressions': 'warn', 'no-unused-labels': 'warn', - 'no-unused-vars': ['warn', { vars: 'local', args: 'none' }], + 'no-unused-vars': ['warn', { + vars: 'local', + varsIgnorePattern: '^_', + args: 'none' + }], 'no-use-before-define': ['warn', 'nofunc'], 'no-useless-computed-key': 'warn', 'no-useless-concat': 'warn',