Skip to content

Commit

Permalink
feat: add autocorrect for better lint (#181)
Browse files Browse the repository at this point in the history
* feat: add autocorrect for better lint

* ci: update course pages

* Fix date format

* feat: add autocorrect config file

* recover files to test autocorrect

* add special rules

* feat: add autocorrect handling for badge divs

* ci: update course pages

* fix

* ci: update course pages

* mannual update

* ci: update course pages

* update code

* recover content

* remove temp

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
kowyo and github-actions[bot] authored Nov 2, 2024
1 parent 8c42591 commit 25b1e14
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 11 deletions.
149 changes: 149 additions & 0 deletions .autocorrectrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# yaml-language-server: $schema=https://huacnlee.github.io/autocorrect/schema.json
rules:
# Auto add spacing between CJK (Chinese, Japanese, Korean) and English words.
# 0 - off, 1 - error, 2 - warning
space-word: 1
# Add space between some punctuations.
space-punctuation: 1
# Add space between brackets (), [] when near the CJK.
space-bracket: 1
# Add space between ``, when near the CJK.
space-backticks: 1
# Add space between dash `-`
space-dash: 1
# Convert to fullwidth.
fullwidth: 1
# To remove space near the fullwidth punctuations.
no-space-fullwidth: 1
# To remove space arouned the fullwidth quotes “”, ''.
no-space-fullwidth-quote: 1
# Fullwidth alphanumeric characters to halfwidth.
halfwidth-word: 1
# Fullwidth punctuations to halfwidth in english.
halfwidth-punctuation: 1
# Spellcheck
spellcheck: 0
# Enable or disable in spatial context
context:
# Enable or disable to format codeblock in Markdown or AsciiDoc etc.
codeblock: 1
textRules:
"知识共享署名-非商业性使用-相同方式共享": 0
"ROS2": 0
spellcheck:
words:
# Please do not add a general English word (eg. apple, python) here.
# Users can add their special words to their .autocorrectrc file by their need.
fileTypes:
# ext: grammar_name
# HTML
html: html
htm: html
vue: html
ejs: html
html.erb: html
svelte: html
# YAML
yaml: yaml
yml: yaml
# Rust
rust: rust
rs: rust
# SQL
sql: sql
# Ruby
ruby: ruby
rb: ruby
Gemfile: ruby
Rakefile: ruby
Profile: ruby
gemspec: ruby
# Crystal
crystal: ruby
cr: ruby
# Elixir
elixir: elixir
ex: elixir
exs: elixir
# JavaScript
js: javascript
jsx: javascript
javascript: javascript
ts: javascript
tsx: javascript
typescript: javascript
js.erb: javascript
# CSS
css: css
scss: css
sass: css
less: css
# JSON
json: json
json5: json
# Go
go: go
# Python
python: python
py: python
# Objective-C
objective_c: objective_c
objective-c: objective_c
m: objective_c
h: objective_c
# Strings for Cocoa
strings: strings
# C#
csharp: csharp
cs: csharp
# Java
java: java
proto: java
# Scala
scala: scala
# Swift
swift: swift
# Kotlin
kotlin: kotlin
kt: kotlin
gradle: kotlin
# PHP
php: php
# Dart
dart: dart
# Markdown
markdown: markdown
md: markdown
mdx: markdown
# LaTeX
latex: latex
tex: latex
# AsciiDoc
asciidoc: asciidoc
adoc: asciidoc
asc: asciidoc
# Gettext
po: gettext
pot: gettext
# Conf
properties: conf
conf: conf
ini: conf
cfg: conf
toml: conf
# C / C++
cc: c
cpp: c
c: c
# XML
xml: xml
# Notebook
jupyter: jupyter
ipynb: jupyter
# Shell
sh: ruby
shell: ruby
# Text
text: text
plain: text
txt: text
16 changes: 12 additions & 4 deletions .github/workflows/course.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ jobs:
curl "https://raw.githubusercontent.com/HITSZ-OpenAuto/${line}/main/README.md" -o "temp.md"
tail -n +2 "temp.md" >> "./content/docs/${semester}/${line}.md"
echo '--------wrap badges---------'
python scripts/wrap_badges.py "./content/docs/${semester}/${line}.md"
echo '--------wrap finished---------'
echo >> "./content/docs/${semester}/${line}.md"
echo "## 资料下载" >> "./content/docs/${semester}/${line}.md"
echo >> "./content/docs/${semester}/${line}.md"
Expand Down Expand Up @@ -299,6 +295,18 @@ jobs:
run: |
python scripts/gen_news.py
- name: Wrap badges
run: |
for file in $(find content/docs -name "*.md")
do
python scripts/wrap_badges.py $file
done
- name: AutoCorrect
uses: huacnlee/autocorrect-action@v2
with:
args: --fix content/

- name: Commit and push changes
uses: EndBug/add-and-commit@v9
with:
Expand Down
2 changes: 1 addition & 1 deletion layouts/shortcodes/update-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
{{- $message := .Get "message" -}}

<div class="hx-mt-4 hx-text-gray-500 hx-text-sm hx-flex hx-items-center hx-flex-wrap hx-gap-y-2 hx-text-ellipsis">
<span>最近由 {{$author}} 于{{ $update_time }}更新:{{ $message | markdownify }}</span>
<span>最近由 {{$author}} 于 {{ $update_time }}更新:{{ $message | markdownify }}</span>
</div>
2 changes: 1 addition & 1 deletion scripts/gen_repo_update_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_latest_commit(owner, repo):

def save_latest_update(commit_info):
datetime_object = commit_info['date']
yymmdd = f'{datetime_object.year}{datetime_object.month}{datetime_object.day}日'
yymmdd = f'{datetime_object.year}{datetime_object.month}{datetime_object.day} 日'
message_line = commit_info["message"].split('\n')
result_content = f"""{{{{< update-info update_time="{yymmdd}" author="{commit_info['author']}" message="{message_line[0]}" >}}}}\n"""
with open('result.txt', 'w') as file:
Expand Down
24 changes: 19 additions & 5 deletions scripts/wrap_badges.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import re
import argparse
from pathlib import Path
import urllib.parse

def wrap_badges_with_div(content, div_classes="img-div hx-mt-4 hx-flex-row hx-justify-start hx-items-center"):
"""
Expand All @@ -15,14 +15,21 @@ def wrap_badges_with_div(content, div_classes="img-div hx-mt-4 hx-flex-row hx-ju
processed_lines = []

# badge行的正则表达式
badge_pattern = r'\(https://img\.shields\.io/badge/.*?\)'
badge_pattern = r'!\[.*?\]\(https://img\.shields\.io/badge/.*?\)'

i = 0
while i < len(lines):
# 如果当前行已经在div中,直接添加
if '<div class="img-div' in lines[i]:
while i < len(lines) and '</div>' not in lines[i]:
processed_lines.append(lines[i])
line = lines[i]
# Encode only the Chinese characters in the entire line
line = re.sub(
badge_pattern,
lambda m: m.group(0).replace(m.group(0), re.sub(r'([\u4e00-\u9fff]+)', lambda c: urllib.parse.quote(c.group()), m.group(0))),
line
)
processed_lines.append(line)
i += 1
if i < len(lines):
processed_lines.append(lines[i]) # 添加结束的</div>
Expand All @@ -34,7 +41,14 @@ def wrap_badges_with_div(content, div_classes="img-div hx-mt-4 hx-flex-row hx-ju
# 寻找连续的badge行
badge_block = []
while i < len(lines) and (re.search(badge_pattern, lines[i]) or lines[i].strip() == ''):
badge_block.append(lines[i])
line = lines[i]
# Encode only the Chinese characters in the entire line
line = re.sub(
badge_pattern,
lambda m: m.group(0).replace(m.group(0), re.sub(r'([\u4e00-\u9fff]+)', lambda c: urllib.parse.quote(c.group()), m.group(0))),
line
)
badge_block.append(line)
i += 1

if badge_block:
Expand Down

0 comments on commit 25b1e14

Please sign in to comment.