Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spread syntax crash in routes-segments-snake-case rule #933

Merged
merged 1 commit into from Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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