Skip to content

Commit

Permalink
Merge pull request #919 from bmish/route-path-style-fix-variable-path
Browse files Browse the repository at this point in the history
Fix crash with variable path in `route-path-style` rule
  • Loading branch information
bmish committed Aug 18, 2020
2 parents 384ccdd + 400eb53 commit d9107e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/rules/route-path-style.js
Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion tests/lib/rules/route-path-style.js
Expand Up @@ -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:
Expand Down Expand Up @@ -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: [
{
Expand Down

0 comments on commit d9107e1

Please sign in to comment.