Skip to content

Commit

Permalink
Merge pull request #933 from bmish/routes-segments-snake-case-fix-spread
Browse files Browse the repository at this point in the history
Fix spread syntax crash in `routes-segments-snake-case` rule
  • Loading branch information
bmish committed Sep 7, 2020
2 parents e3746be + 4efe5b9 commit 670726c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/rules/routes-segments-snake-case.js
Expand Up @@ -31,7 +31,12 @@ module.exports = {
};

const isSegment = function (property) {
return property.key.name === 'path' && routeSegmentRegex.test(property.value.value);
return (
types.isProperty(property) &&
types.isIdentifier(property.key) &&
property.key.name === 'path' &&
routeSegmentRegex.test(property.value.value)
);
};

const getSegmentNames = function (property) {
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/routes-segments-snake-case.js
Expand Up @@ -9,7 +9,7 @@ const RuleTester = require('eslint').RuleTester;
// Tests
// ------------------------------------------------------------------------------

const eslintTester = new RuleTester();
const eslintTester = new RuleTester({ parser: require.resolve('babel-eslint') });
eslintTester.run('routes-segments-snake-case', rule, {
valid: [
'this.route("tree", { path: ":tree_id"});',
Expand All @@ -26,6 +26,7 @@ eslintTester.run('routes-segments-snake-case', rule, {
'this.route("tree", { path: "/test/:tree_id/test-test/:tree_child_id"});',
'this.route("tree", { path: "/test/:tree_id/testTest/:tree_child_id"});',
'this.route("tree", { path: "*:"});',
'this.route("tree", { ...foo });',
],
invalid: [
{
Expand Down

0 comments on commit 670726c

Please sign in to comment.