Skip to content

Commit

Permalink
Fix rescue modifier comment
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Nov 1, 2023
1 parent 50ee221 commit e13f2e4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2221,8 +2221,8 @@ nodes:
comment: |
Represents an expression modified with a rescue.
foo rescue nil
^^^^^^^^^^^^^^
foo rescue nil
^^^^^^^^^^^^^^
- name: RescueNode
fields:
- name: keyword_loc
Expand Down
6 changes: 3 additions & 3 deletions rakelib/char.rake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace :generate do
row =
slice.map do |codepoint|
character = codepoint.chr

value = 0
value |= (1 << 0) if ["\t", "\n", "\v", "\f", "\r", " "].include?(character)
value |= (1 << 1) if ["\t", "\v", "\f", "\r", " "].include?(character)
value |= (1 << 2) if ["e", "i", "m", "n", "o", "s", "u", "x"].include?(character)

"%d," % value
end

Expand All @@ -42,7 +42,7 @@ namespace :generate do

"0x%02x," % value
end

puts " #{row.join(" ")} // #{row_index.to_s(16).upcase}x\n"
end
puts "};"
Expand Down
39 changes: 27 additions & 12 deletions rakelib/lint.rake
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,43 @@ task :lint do
exit(1)
end

nodes = config.fetch("nodes").map { |node| node.fetch("name") }
if nodes.sort != nodes
nodes = config.fetch("nodes")
names = nodes.map { |node| node.fetch("name") }
if names.sort != names
warn("Nodes are not sorted alphabetically")

nodes.sort.zip(nodes).each do |(sorted, unsorted)|
names.sort.zip(names).each do |(sorted, unsorted)|
warn("Expected #{sorted} got #{unsorted}") if sorted != unsorted
end

exit(1)
end

# Check for trailing spaces
if (uncommented = nodes.select { |node| !node.key?("comment") }).any?
names = uncommented.map { |node| node.fetch("name") }
warn("Expected all nodes to be commented, missing comments for #{names.join(", ")}")
exit(1)
end

if (uncommented = nodes.select { |node| !%w[MissingNode ProgramNode].include?(node.fetch("name")) && !node.fetch("comment").match?(/^\s{4}/) }).any?
names = uncommented.map { |node| node.fetch("name") }
warn("Expected all nodes to have an example, missing comments for #{names.join(", ")}")
exit(1)
end

trailing_spaces_found = false
Dir.glob("**/*.{c,h,erb,rb,yml}")
.reject { |filepath| filepath.start_with?("tmp") || filepath.start_with?("vendor/") }
.each do |path|
File.readlines(path).each_with_index do |line, index|
if line.match(/[ \t]+$/)
warn("Trailing spaces found in #{path} on line #{index + 1}")
trailing_spaces_found = true
end
extensions = %w[.c .h .erb .rb .yml .rake]

`git ls-files -z`.split("\x0").each do |filepath|
next unless extensions.include?(File.extname(filepath))

File.foreach(filepath).with_index(1) do |line, index|
if line.match?(/[ \t]+$/)
warn("Trailing spaces found in #{filepath} on line #{index}")
trailing_spaces_found = true
end
end
end

exit(1) if trailing_spaces_found
end

0 comments on commit e13f2e4

Please sign in to comment.