betterlint icon indicating copy to clipboard operation
betterlint copied to clipboard

Add linting rule for site prism pages

Open AndrewSwerlick opened this issue 1 year ago • 0 comments

To make site prism pages more discoverable, I propose we have a linter rule which enforces that the module namespaces for a site prism page matches the value passed to set_url.

The general rules would be something like

  • Each static segment of the url that's not the final segment should have a module declaration, in the same order they appear in the url
  • Dynamic segments of the url are ignored
  • If the last segment of a url is dynamic, then the class name can be anything as long as it ends in Page
  • If the last segment of the url is not dynamic, then it needs to be <CamelCasedSegment>Page

Here are some thoughts on what should pass and fail

Good

class UsersPage
  set_url "users"
end
module Users
  class ShowPage
    set_url "users/{id}"
  end
end
module Users
  class EditPage
    set_url "users/{id}/edit"
  end
end
module Users
  class NewPage
    set_url "users/{id}/new"
  end
end
module Users
  class PostsPage
    set_url "users/{id}/posts"
  end
end

Bad

class UsersPostsPage
  set_url "users/{id}/posts"
end
class UserPage
    set_url "users/{id}"
end  

AndrewSwerlick avatar Mar 14 '23 18:03 AndrewSwerlick