Skip to content

Commit d9107e1

Browse files
authored
Merge pull request #919 from bmish/route-path-style-fix-variable-path
Fix crash with variable path in `route-path-style` rule
2 parents 384ccdd + 400eb53 commit d9107e1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

lib/rules/route-path-style.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ module.exports = {
4444
const pathValueNode = hasExplicitPathOption
4545
? getPropertyByKeyName(node.arguments[1], 'path').value
4646
: node.arguments[0];
47-
const pathValue = pathValueNode.value;
4847

49-
const urlSegments = getStaticURLSegments(pathValue);
48+
if (!types.isStringLiteral(pathValueNode)) {
49+
return;
50+
}
51+
52+
const urlSegments = getStaticURLSegments(pathValueNode.value);
5053

5154
if (urlSegments.some((urlPart) => !isKebabCase(urlPart))) {
5255
context.report(pathValueNode, ERROR_MESSAGE);

tests/lib/rules/route-path-style.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ const { ERROR_MESSAGE } = rule;
1111
// Tests
1212
//------------------------------------------------------------------------------
1313

14-
const ruleTester = new RuleTester();
14+
const ruleTester = new RuleTester({
15+
parserOptions: {
16+
ecmaVersion: 6,
17+
sourceType: 'module',
18+
},
19+
});
1520
ruleTester.run('route-path-style', rule, {
1621
valid: [
1722
// Implicit path:
@@ -78,6 +83,10 @@ ruleTester.run('route-path-style', rule, {
7883

7984
// Incorrect usage:
8085
'this.route();',
86+
87+
// With variable:
88+
"this.route('team', { path: myPath });",
89+
"this.route('team', { path: `part-${some-variable}` });", // eslint-disable-line no-template-curly-in-string
8190
],
8291
invalid: [
8392
{

0 commit comments

Comments
 (0)