Skip to content

Mark the error pages written by rails new as generated - #8191

Open
irinanazarova wants to merge 3 commits into
github-linguist:mainfrom
irinanazarova:rails-generated-error-pages
Open

irinanazarova wants to merge 3 commits into
github-linguist:mainfrom
irinanazarova:rails-generated-error-pages

Conversation

@irinanazarova

Copy link
Copy Markdown

Treat the five error pages that rails new writes into public/ as generated, so that a new Ruby on Rails application is classified as Ruby rather than HTML.

Description

Motivation

Every new Rails application since Rails 8.0 is reported as an HTML repository on GitHub. Measured on a uniform sample of 20,000 HTML-primary repositories per year, Rails applications reported as HTML run at about 600 a month in 2025 and about 1,100 a month in 2026. Any statistic derived from GitHub language data, such as new Rails applications or new Ruby developers, undercounts Ruby.

rails new writes five static error pages (400.html, 404.html, 406-unsupported-browser.html, 422.html, 500.html). Since Rails 8.0 they total about 36 KB of HTML, while a freshly generated application contains about 24 KB of Ruby. Linguist picks the primary language by byte count, so the application is HTML until its author has written roughly 13 KB of Ruby.

Reproduction

Before: https://github.com/irinanazarova/rails-new is the unmodified output of rails _8.1.3.1_ new rails-new --skip-bundle. GitHub reports it as HTML (57.9% HTML, 35.5% Ruby).

After: https://github.com/irinanazarova/rails-new-amended is the same application with the five files marked linguist-generated in .gitattributes. GitHub reports it as Ruby (80%).

Detail

Adds generated_rails_error_page? to generated.rb. A file qualifies only if its path is public/<one of the five names>.html and it contains the marker comment the Rails generator has written into each page since Rails 3.0, naming that same path (<!-- This file lives in public/404.html -->). A page a developer has rewritten without the marker, or the same content under another path, is not affected. Fixtures are the untouched output of rails new on Rails 8.1.3.1, plus a hand-written public/404.html asserting no match.

Why in Linguist, given the Rails-side fix

Rails has merged the companion change, rails/rails#58693, which adds these five linguist-generated entries to the .gitattributes of every newly generated application. That covers applications generated with future Rails releases. It does not reach the applications generated with Rails 8.0 and 8.1 since November 2024, nor applications created with --skip-git, which get no .gitattributes. This heuristic covers those on their next statistics run.

Checklist:

  • I am adding new or changing current functionality
  • I have added or updated the tests for the new or changed functionality.

Rails writes five static error pages into public/ (400, 404,
406-unsupported-browser, 422 and 500). Since Rails 8.0 they total
about 36 KB of HTML, more than the ~24 KB of Ruby in a freshly
generated application, so a new Rails application is reported as an
HTML repository until enough Ruby has been written.

A file is treated as generated when its path is one of the five
public/*.html names and it contains the comment Rails has written into
each page since 3.0, naming that same path:

    <!-- This file lives in public/404.html -->

A page rewritten without the comment, or the same content under
another path, is not affected. Fixtures are untouched output of
rails new on Rails 8.1.3.1, plus a hand-written 404.html that must
not match.

Rails has merged the same exclusion for newly generated applications
via .gitattributes (rails/rails#58693); this covers applications
generated with Rails 8.0 and 8.1 before that change, and those created
with --skip-git, which get no .gitattributes.
@irinanazarova
irinanazarova requested a review from a team as a code owner September 13, 2026 05:11

@lildude lildude left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See inline comment.

Comment thread lib/linguist/generated.rb Outdated
return lines[0].include?("% Generated by roxygen2: do not edit by hand")
end

RAILS_ERROR_PAGES = %w[400 404 406-unsupported-browser 422 500]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for a constant as this isn't going to be used anywhere else. Please put this line in the method.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing!! Just moved it into a method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants