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 crash with variable path in route-path-style rule #919

Merged
merged 1 commit into from Aug 18, 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: 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