From 400eb533106e72ffb71c88b14bb89ccef793a96c Mon Sep 17 00:00:00 2001 From: Bryan Mishkin <698306+bmish@users.noreply.github.com> Date: Tue, 18 Aug 2020 18:33:39 -0400 Subject: [PATCH] fix: route-path-style variable path crash --- lib/rules/route-path-style.js | 7 +++++-- tests/lib/rules/route-path-style.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/rules/route-path-style.js b/lib/rules/route-path-style.js index 4e99e76e43..656613dc3b 100644 --- a/lib/rules/route-path-style.js +++ b/lib/rules/route-path-style.js @@ -44,9 +44,12 @@ module.exports = { const pathValueNode = hasExplicitPathOption ? getPropertyByKeyName(node.arguments[1], 'path').value : node.arguments[0]; - const pathValue = pathValueNode.value; - const urlSegments = getStaticURLSegments(pathValue); + if (!types.isStringLiteral(pathValueNode)) { + return; + } + + const urlSegments = getStaticURLSegments(pathValueNode.value); if (urlSegments.some((urlPart) => !isKebabCase(urlPart))) { context.report(pathValueNode, ERROR_MESSAGE); diff --git a/tests/lib/rules/route-path-style.js b/tests/lib/rules/route-path-style.js index 6c0e4f1b0d..854b92ceb0 100644 --- a/tests/lib/rules/route-path-style.js +++ b/tests/lib/rules/route-path-style.js @@ -11,7 +11,12 @@ const { ERROR_MESSAGE } = rule; // Tests //------------------------------------------------------------------------------ -const ruleTester = new RuleTester(); +const ruleTester = new RuleTester({ + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + }, +}); ruleTester.run('route-path-style', rule, { valid: [ // Implicit path: @@ -78,6 +83,10 @@ ruleTester.run('route-path-style', rule, { // Incorrect usage: 'this.route();', + + // With variable: + "this.route('team', { path: myPath });", + "this.route('team', { path: `part-${some-variable}` });", // eslint-disable-line no-template-curly-in-string ], invalid: [ {