-
Notifications
You must be signed in to change notification settings - Fork 27
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
Fix ~2393 linter errors, workaround two linter bugs #369
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
44eb3b1
to
426b23c
Compare
426b23c
to
87251d7
Compare
711ecb8
to
1dc6064
Compare
14772f7
to
1583a6c
Compare
@XiNiHa This change is less trivial than #368. I expect the build results to be exactly the same with before as #368. Is there any good way to programmatically compare the MDX rendering results? I tried to compare the output of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually checked all the changed files for each commit, and fixed various broken contents
Since the codemod used in this PR will be GC'd instead of staying in the tree, I'm going to back it up as follows. commit 2368d951c109600988ba8946e4baeb3b444241e0
Author: Hyeon Kim <[email protected]>
Date: 2024-03-13 02:07:27 +0900
run: Temporary codemod for MDX
See `./run help` for the details
diff --git a/run b/run
new file mode 100755
index 0000000..a5b57cd
--- /dev/null
+++ b/run
@@ -0,0 +1,193 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+require 'base64'
+require 'stringio'
+require 'zlib'
+
+def help
+ puts <<~HELP
+ usage: ./run <command> [<options>]
+
+ commands:
+ cat print the raw linter output
+ stats print the statics of linter output
+ help print this help message
+
+ filter <pattern> filter the linter output
+ --vim show the command to open the file in vim
+
+ fix-remark-lint-unordered-list-marker-style
+ fix-remark-lint-no-missing-blank-lines
+ fix-remark-lint-rule-style
+ fix-remark-lint-maximum-line-length
+ HELP
+end
+
+# base64 decode DATA then un-gzip
+LINES = begin
+ Zlib::GzipReader.open('eslint-output.gz').drop(5)
+rescue
+ STDERR.puts <<~ERROR
+ error: eslint-output.gz not found
+
+ Create 'eslint-output.gz' by running the following command:
+
+ pnpm lint | tee >(gzip --stdout > eslint-output.gz)
+ ERROR
+ exit!
+end
+
+def each_line
+ return to_enum(__method__) unless block_given?
+
+ filename = nil
+ content = nil
+
+ for line in LINES
+ line.chomp!
+
+ break if line.start_with?('✖')
+ if line.start_with?('/Users/simnalamburt/workspace/developers.portone.io/')
+ filename = line
+ content = open(filename).read.lines
+ next
+ end
+
+ if line == ''
+ filename = nil
+ content = nil
+ next
+ end
+
+ args = line.split(/ +/)
+ case args.length
+ when 4, 5
+ when 1
+ next
+ else
+ STDERR.puts 'Unexpected format'
+ exit!
+ end
+
+ yield filename, content, args
+ end
+end
+
+case ARGV
+in ['cat']
+ puts LINES
+in ['stats']
+ dict = Hash.new(0)
+ each_line do |filename, content, args|
+ reason = args[-1]
+ msg = case args.length
+ when 5
+ # Plain lint failure
+ reason
+ when 4
+ # error
+ if reason.match(/^Preprocessing error: Cannot read properties of undefined \(reading '.*?'\)$/)
+ 'Preprocessing error: Cannot read properties of undefined (reading \'...\')'
+ elsif reason.match(/^Parsing error: Unexpected token .*$/)
+ 'Parsing error: Unexpected token ...'
+ elsif reason.match(/^Parsing error: ESLint was configured to run on `<tsconfigRootDir>.*?` using `parserOptions.project`: .*$/)
+ 'Parsing error: ESLint was configured to run on `...` using `parserOptions.project`: ...'
+ else
+ reason
+ end
+ end
+
+ # increment count
+ dict[msg] += 1
+ end
+ # print stats, order by count
+ dict.sort_by { |msg, count| -count }.each do |msg, count|
+ puts '%8d %s' % [count, msg]
+ end
+in ['filter', msg, *options]
+ last_line = nil
+
+ each_line do |filename, content, args|
+ next if args[-1] != msg
+
+ rel = filename.delete_prefix(Dir.getwd + '/')
+ line, col = args[1].split(':').map(&:to_i)
+ case [msg, *options]
+ in ['remark-lint-table-pipe-alignment', '--vim'] | ['remark-lint-table-cell-padding', '--vim']
+ if last_line.nil? || (last_line - line).abs > 1
+ puts 'vim %s +%d' % [rel, line]
+ end
+ last_line = line
+ in ['remark-lint-maximum-line-length', '--vim']
+ puts 'vim %s +%d' % [rel, line]
+ in [_, '--vim']
+ cmd = if col == 1
+ 'vim %s +%d' % [rel, line]
+ else
+ 'vim %s \'+normal %dG%d|\'' % [rel, line, col]
+ end
+ puts "%-120s \x1b[90m%s\x1b[0m" % [cmd, content[line-1][col-1..-1][..50].chomp]
+ in [_]
+ puts "%-80s %5d:%-5d %s" % [rel, line, col, content[line-1][col-1..-1]]
+ end
+ end
+in ['fix-remark-lint-unordered-list-marker-style']
+ each_line do |filename, content, args|
+ next if args[-1] != 'remark-lint-unordered-list-marker-style'
+
+ rel = filename.delete_prefix(Dir.getwd + '/')
+ line, col = args[1].split(':').map(&:to_i)
+ content[line-1][col-1] = '-'
+ puts "Updating %-80s %5d:%-5d %s" % [rel, line, col, content[line-1][col-1..-1]]
+ open(filename, 'w') { |f| f.write(content.join) }
+ end
+ puts 'Done'
+in ['fix-remark-lint-no-missing-blank-lines']
+ each_line do |filename, content, args|
+ next if args[-1] != 'remark-lint-no-missing-blank-lines'
+
+ rel = filename.delete_prefix(Dir.getwd + '/')
+ line, col = args[1].split(':').map(&:to_i)
+ next if col != 1
+
+ content[line-1].prepend("\n")
+ puts "Updating %s#L%d" % [rel, line]
+ open(filename, 'w') { |f| f.write(content.join) }
+ end
+ puts 'Done'
+in ['fix-remark-lint-rule-style']
+ each_line do |filename, content, args|
+ next if args[-1] != 'remark-lint-rule-style'
+
+ rel = filename.delete_prefix(Dir.getwd + '/')
+ line, col = args[1].split(':').map(&:to_i)
+
+ ch = content[line-1][col-1]
+ last = (col-1...).each do |i|
+ break i if content[line-1][i] != ch
+ end
+ for i in (col-1)...last
+ content[line-1][i] = '-'
+ end
+
+ puts "Updating %s#L%d:%d" % [rel, line, col]
+ open(filename, 'w') { |f| f.write(content.join) }
+ end
+ puts 'Done'
+in ['fix-remark-lint-maximum-line-length']
+ puts <<~'EOF'
+ set -euo pipefail; IFS=$'\r\n'
+ EOF
+ each_line.reverse_each do |filename, content, args|
+ next if args[-1] != 'remark-lint-maximum-line-length'
+ rel = filename.delete_prefix(Dir.getwd + '/')
+ line, col = args[1].split(':').map(&:to_i)
+
+ puts "nvim -u NONE #{rel} '+set textwidth=100' '+normal #{line}G#{col}|vipgqZZ'"
+ end
+in ['help']
+ help
+else
+ help
+ exit!
+end
|
./run fix-remark-lint-no-missing-blank-lines
./run fix-remark-lint-rule-style
./run fix-remark-lint-maximum-line-length | bash
See 7aff773 for the codemod used for this PR (#369) and #368