Skip to content

[RFC] Slice Linting #79

@jgwhite

Description

@jgwhite

Summary

Add linting and/or tests that promote the addition of validation to Slice models.

Motivation

Templates that depend upon data which may not be available is a common source of errors in Slices.

For example, consider FooSlice:

# app/slices/foo/foo_slice.rb

class FooSlice < Slice
  field :bar, type: String
end
<!-- app/slices/foo/views/show.html.erb -->

<p><%= bar.upcase %></p>

If bar is nil (which it will be by default) this will raise a NoMethodError and the entire page will fail to render.

Rather than introduce null checking to templates, we would prefer to enforce these dependencies at the slice-model level:

# app/slices/foo/foo_slice.rb

class FooSlice < Slice
  field :bar, type: String
  validates :bar, presence: true
end

This enforces consistency at a lower level and prevents both full blown render failures and incorrect renders.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions