-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inherit from BaseLinter for HTML class checking
BaseLinter already has class checking and exception count functionality. We did have to modify BaseLinter to allow an empty `TAGS` array constant, thereby checking all tags.
- Loading branch information
Showing
5 changed files
with
38 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
lib/primer/view_components/linters/disallow_view_component_html_classes.rb
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
lib/primer/view_components/linters/view_component_html_classes_counter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "base_linter" | ||
|
||
# Load all the other linters so we can filter out their restricted | ||
# CLASSES—they will be responsible for complaining about the use of | ||
# those HTML classes. | ||
Dir[File.join(__dir__, "*.rb")].sort.each do |file| | ||
require file unless file == __FILE__ | ||
end | ||
|
||
module ERBLint | ||
module Linters | ||
# Counts the number of times a class reserved for ViewComponents is used | ||
class ViewComponentHtmlClassesCounter < BaseLinter | ||
CLASSES = ( | ||
JSON.parse( | ||
File.read( | ||
File.join(__dir__, "..", "..", "..", "..", "static", "classes.json") | ||
) | ||
) - BaseLinter.subclasses.reduce([]) do |html_classes, klass| | ||
html_classes.concat(klass.const_get(:CLASSES)) | ||
end | ||
).freeze | ||
|
||
TAGS = nil | ||
MESSAGE = "Primer ViewComponents defines some HTML classes with associated styles that should not be used outside those components. (These classes might have their styles changed or even disappear in the future.) Instead of using this class directly, please use its component if appropriate or define the styles you need some other way." | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters