Skip to content

Commit

Permalink
Merge pull request #931 from bmish/no-unnecessary-route-path-option-f…
Browse files Browse the repository at this point in the history
…ix-spread

Fix spread syntax crash in `no-unnecessary-route-path-option` rule
  • Loading branch information
bmish authored Sep 7, 2020
2 parents f0fdaa8 + 27b51d9 commit b77e14f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/rules/no-unnecessary-route-path-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ function hasPropertyWithKeyName(objectExpression, keyName) {
}

function getPropertyByKeyName(objectExpression, keyName) {
return objectExpression.properties.find((property) => property.key.name === keyName);
return objectExpression.properties.find(
(property) =>
types.isProperty(property) &&
types.isIdentifier(property.key) &&
property.key.name === keyName
);
}

function pathMatchesRouteName(path, routeName) {
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/no-unnecessary-route-path-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ const { ERROR_MESSAGE } = rule;
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester();
const ruleTester = new RuleTester({ parser: require.resolve('babel-eslint') });
ruleTester.run('no-unnecessary-route-path-option', rule, {
valid: [
'this.route("blog");',
'this.route("blog", function() {});',
'this.route("blog", { ...foo });',
'this.route("blog", { path: undefined });',
'this.route("blog", { path: "" });',
'this.route("blog", { path: "/" });',
Expand Down

0 comments on commit b77e14f

Please sign in to comment.