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

Fix ~2393 linter errors, workaround two linter bugs #369

Merged
merged 8 commits into from
Mar 20, 2024
Merged

Conversation

simnalamburt
Copy link
Contributor

@simnalamburt simnalamburt commented Mar 19, 2024

  1. Removed all remark-lint-table-pipe-alignment linter errors, 754 in total.
  2. Removed majority of remark-lint-table-cell-padding linter errors, ~400 in total
  3. Allow tight list, removed 256 of remark-lint-no-missing-blank-lines linter errors
  4. Removed 156 linter errors using ./run fix-remark-lint-no-missing-blank-lines
  5. Removed 372 linter errors using ./run fix-remark-lint-rule-style
  6. Remove 455 linter errors using ./run fix-remark-lint-maximum-line-length | bash
  7. Workaround Many packages does not distinguish halfwidth and fullwidth characters remarkjs/remark-lint#310
  8. Workaround 'remark-lint-table-pipe-alignment' treats blank cells incorrectly remarkjs/remark-lint#312

See 7aff773 for the codemod used for this PR (#369) and #368

Copy link

vercel bot commented Mar 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
developers ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2024 11:41am

@simnalamburt simnalamburt changed the title Fix ~754 linter errors Fix ~754 linter errors, workaround two linter bugs Mar 19, 2024
@simnalamburt simnalamburt changed the title Fix ~754 linter errors, workaround two linter bugs Fix 754 linter errors, workaround two linter bugs Mar 19, 2024
@simnalamburt simnalamburt marked this pull request as ready for review March 19, 2024 19:29
@simnalamburt simnalamburt self-assigned this Mar 19, 2024
@simnalamburt simnalamburt changed the title Fix 754 linter errors, workaround two linter bugs Fix 1154 linter errors, workaround two linter bugs Mar 19, 2024
@simnalamburt simnalamburt changed the title Fix 1154 linter errors, workaround two linter bugs Fix ~1154 linter errors, workaround two linter bugs Mar 19, 2024
@simnalamburt simnalamburt changed the title Fix ~1154 linter errors, workaround two linter bugs Fix ~ 1410 linter errors, workaround two linter bugs Mar 19, 2024
@simnalamburt simnalamburt changed the title Fix ~ 1410 linter errors, workaround two linter bugs Fix ~1410 linter errors, workaround two linter bugs Mar 19, 2024
@simnalamburt simnalamburt changed the title Fix ~1410 linter errors, workaround two linter bugs Fix ~1566 linter errors, workaround two linter bugs Mar 19, 2024
@simnalamburt simnalamburt changed the title Fix ~1566 linter errors, workaround two linter bugs Fix ~1938 linter errors, workaround two linter bugs Mar 19, 2024
@simnalamburt simnalamburt changed the title Fix ~1938 linter errors, workaround two linter bugs Fix ~2393 linter errors, workaround two linter bugs Mar 20, 2024
@simnalamburt
Copy link
Contributor Author

simnalamburt commented Mar 20, 2024

@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 pnpm build, but it came out in a form that was hard to compare. (filenames were different)

Copy link
Contributor

@XiNiHa XiNiHa left a 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

@XiNiHa XiNiHa merged commit 35ce1c0 into main Mar 20, 2024
3 of 4 checks passed
@XiNiHa XiNiHa deleted the fix-linter-errors branch March 20, 2024 11:45
@simnalamburt
Copy link
Contributor Author

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

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