From 34baf7a780232d70dbeaf5195e584910d7fc9efb Mon Sep 17 00:00:00 2001 From: Jannick Garthen Date: Mon, 10 Apr 2017 12:10:52 +0200 Subject: [PATCH] fix(no-unused-styles): allow use of spread operator The linter crashes with an error when the spread operator was used in a stylesheet object. This fix will ignore all styles that are not of type Property. Fix #129 --- lib/util/stylesheet.js | 3 ++- tests/lib/rules/no-unused-styles.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/util/stylesheet.js b/lib/util/stylesheet.js index dc1acf6..0711376 100644 --- a/lib/util/stylesheet.js +++ b/lib/util/stylesheet.js @@ -140,7 +140,8 @@ const astHelpers = { return node .init .arguments[0] - .properties; + .properties + .filter(property => property.type === 'Property'); } return []; diff --git a/tests/lib/rules/no-unused-styles.js b/tests/lib/rules/no-unused-styles.js index 04e5013..27f17f6 100644 --- a/tests/lib/rules/no-unused-styles.js +++ b/tests/lib/rules/no-unused-styles.js @@ -247,6 +247,25 @@ ruleTester.run('no-unused-styles', rule, { classes: true, jsx: true, }, + }, { + code: [ + 'const additionalStyles = {};', + 'const styles = StyleSheet.create({', + ' name: {},', + ' ...additionalStyles', + '});', + 'const Hello = React.createClass({', + ' render: function() {', + ' return Hello {this.props.name};', + ' }', + '});', + ].join('\n'), + parser: 'babel-eslint', + ecmaFeatures: { + classes: true, + jsx: true, + spread: true, + }, }], invalid: [{