Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autocorrect from erb_lint #17834

Open
wants to merge 17 commits into
base: dev
Choose a base branch
from
Open

Autocorrect from erb_lint #17834

wants to merge 17 commits into from

Conversation

toy
Copy link
Contributor

@toy toy commented Feb 5, 2025

#!/usr/bin/env ruby

require 'json'
require 'set'
require 'time'

# there are less than 100, no need to go through pages
data = `curl --silent -H "Accept: application/vnd.github.v3+json" 'https://api.github.com/repos/opf/openproject/pulls?state=open&per_page=100'`

threshold = Date.today - 100 # only updated during last 100 days
pr_ids = JSON.parse(data)
  .filter{ Time.iso8601(_1['updated_at']).to_date >= threshold }
  .map{ _1['number'] }

system *%W[git fetch origin dev], *pr_ids.map{ "+refs/pull/#{_1}/head:refs/remotes/origin/pr/#{_1}" }

refs = pr_ids.map{ |pr_id| "origin/pr/#{pr_id}" }
refs += `git for-each-ref --format='%(refname:short)' 'refs/remotes/origin/release/*'`.split("\n")

pr_touched_paths = Set.new

refs.each do |ref|
  pr_touched_paths.merge IO.popen(%W[git diff --name-only ...#{ref}], &:read).split("\n")
end

target_paths = Dir['**/*.erb']

paths = target_paths - pr_touched_paths.to_a

html_paths, non_html_paths = paths.partition{ _1.end_with?('.html.erb', '.turbo_stream.erb') }

system *%w[erb_lint --autocorrect] + html_paths

system *%w[erb_lint --autocorrect --enable-linters rubocop] + non_html_paths

@klaustopher
Copy link
Contributor

Good thing to see all rules in place. Makes it a lot easier to argue about them and some changes. God job 👍

app/views/versions/_overview.html.erb Dismissed Show dismissed Hide dismissed
app/views/versions/_overview.html.erb Dismissed Show dismissed Hide dismissed
@toy
Copy link
Contributor Author

toy commented Feb 7, 2025

Unexpected fix of <input type="text"></input> to <input type="text"><input> was shown by feature specs

@toy toy marked this pull request as ready for review February 7, 2025 11:59
Copy link
Contributor

@NobodysNightmare NobodysNightmare left a comment

Choose a reason for hiding this comment

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

I think this is reasonable. I didn't look through the entire diff, but rather did some spot checking of the auto-correct results.

I am not sure whether all the changes (even the ones I suggested) lead to pure improvement, but I think the main thing we achieve now is consistency. This means when we discuss the next rule changes, we will be able to compare what only such a change will mean to the code base, without the noise from all the other fixes that are necessary as well.

tl;dr: LGTM, but maybe not the last PR of its kind :)

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

Successfully merging this pull request may close these issues.

5 participants