Skip to content

Commit

Permalink
Update .ameba.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Apr 10, 2024
1 parent d40e484 commit b2b3be3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 33 deletions.
58 changes: 36 additions & 22 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
# This configuration file was generated by `ameba --gen-config`
# on 2024-04-03 14:18:15 UTC using Ameba version 1.6.1.
# on 2024-04-10 10:06:54 UTC using Ameba version 1.6.1.
# The point is for the user to remove these configuration records
# one by one as the reported problems are removed from the code base.

# Problems found: 7
# Problems found: 4
# Run `ameba --only Lint/NotNil` for details
Lint/NotNil:
Description: Identifies usage of `not_nil!` calls
Excluded:
- src/translater/selenium/session.cr
- src/translater/ali.cr
- src/translater.cr
Enabled: true
Severity: Warning

# Problems found: 9
# Run `ameba --only Style/ParenthesesAroundCondition` for details
Style/ParenthesesAroundCondition:
Description: Disallows redundant parentheses around control expressions
ExcludeTernary: false
AllowSafeAssignment: false
Excluded:
- src/translater/selenium/session.cr
- src/translater/bing.cr
- src/translater/youdao.cr
- src/translater/baidu.cr
- src/translater/tencent.cr
- src/translater/volc.cr
- src/cli.cr
Enabled: true
Severity: Warning
Severity: Convention

# Problems found: 8
# Problems found: 11
# Run `ameba --only Naming/BlockParameterName` for details
Naming/BlockParameterName:
Description: Disallows non-descriptive block parameter names
MinNameLength: 3
AllowNamesEndingInNumbers: true
Excluded:
- src/translater/ali.cr
- src/translater.cr
- src/cli.cr
- src/translater.cr
AllowedNames:
- _
- e
Expand All @@ -52,12 +62,13 @@ Naming/BlockParameterName:
Enabled: true
Severity: Convention

# Problems found: 1
# Problems found: 2
# Run `ameba --only Documentation/DocumentationAdmonition` for details
Documentation/DocumentationAdmonition:
Description: Reports documentation admonitions
Timezone: UTC
Excluded:
- src/translater/volc.cr
- src/cli.cr
Admonitions:
- TODO
Expand All @@ -66,23 +77,26 @@ Documentation/DocumentationAdmonition:
Enabled: true
Severity: Warning

# Problems found: 1
# Run `ameba --only Lint/ShadowingOuterLocalVar` for details
Lint/ShadowingOuterLocalVar:
Description: Disallows the usage of the same name as outer local variables for block
or proc arguments
# Problems found: 2
# Run `ameba --only Metrics/CyclomaticComplexity` for details
Metrics/CyclomaticComplexity:
Description: Disallows methods with a cyclomatic complexity higher than `MaxComplexity`
MaxComplexity: 10
Excluded:
- src/cli.cr
- src/translater.cr
Enabled: true
Severity: Warning

# Problems found: 2
# Run `ameba --only Style/ParenthesesAroundCondition` for details
Style/ParenthesesAroundCondition:
Description: Disallows redundant parentheses around control expressions
ExcludeTernary: false
AllowSafeAssignment: false
# Run `ameba --only Lint/DebugCalls` for details
Lint/DebugCalls:
Description: Disallows debug-related calls
Excluded:
- src/cli.cr
- 1.cr
MethodNames:
- p
- p!
- pp
- pp!
Enabled: true
Severity: Convention
Severity: Warning
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

默认会随机选择一个支持的引擎来翻译,这可以避免过于频繁的使用某一翻译引擎而导致 IP 被封。

搭配 [goldendict](https://github.com/goldendict/goldendict) 作为词典之一,一起食用效果更佳!

```sh
╰─ $ bin/translater 'hello world!'
Using Ali
Expand Down
11 changes: 6 additions & 5 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ PROFILE_DB_FILE = "sqlite3:#{find_db_path("profile.db")}"
SESSION_DB_FILE = "sqlite3:#{find_db_path("session.db")}"

def profile_db_exists?
# TODO: 还要检测文件大小
File.exists?(PROFILE_DB_FILE.split(':')[1])
db_file = PROFILE_DB_FILE.split(':')[1]

File.exists?(db_file) && File.info(db_file).size > 0
end

enum TargetLanguage
Expand Down Expand Up @@ -104,8 +105,8 @@ USAGE
inputs = e.split(",")
engine_list = [] of String

inputs.each do |input|
if (engine = Engine.parse?(input))
inputs.each do |i|
if (engine = Engine.parse?(i))
engine_list << engine.to_s
else
abort "Supported options: #{Engine.names.map(&.downcase).join ", "}"
Expand All @@ -122,7 +123,7 @@ USAGE
db.query "select name from fastest_engine limit 1;" do |rs|
rs.each do
# If fastest_engine is empty, this block will be ignored.
if engine = Engine.parse(rs.read(String))
if (engine = Engine.parse(rs.read(String)))
engine_list = [engine.to_s]
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/translater/bing.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Translater
gets
end

while result = document_manager.execute_script(%{return document.querySelector("#{output_selector}").value})
while (result = document_manager.execute_script %{return document.querySelector("#{output_selector}").value})
break unless result.strip == "..."

sleep 0.1
Expand Down
6 changes: 3 additions & 3 deletions src/translater/selenium/session.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Selenium::Session
element : Selenium::Element? = nil

timeout(seconds) do
until element = find_by_selector(selector, was_hidden: was_hidden)
until (element = find_by_selector selector, was_hidden: was_hidden)
sleep 0.1
end
end
Expand All @@ -36,7 +36,7 @@ class Selenium::Session
element = nil

loop do
until element = find_by_selector(selector, was_hidden: was_hidden)
until (element = find_by_selector selector, was_hidden: was_hidden)
sleep 0.1
end

Expand All @@ -52,7 +52,7 @@ class Selenium::Session
end

def find_by_selector_wait!(selector : String, *, was_hidden : Bool = false) : Selenium::Element
until element = find_by_selector(selector, was_hidden: was_hidden)
until (element = find_by_selector selector, was_hidden: was_hidden)
sleep 0.1
end

Expand Down
4 changes: 2 additions & 2 deletions src/translater/volc.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# FIXME: still not work!
# FIXME: volc still not work!

class Translater
class Volc
Expand Down Expand Up @@ -80,7 +80,7 @@ class Translater
output_editor_selector = "div.slate-editor[contenteditable='false']"

# 这两个有内容时才存在
input_selector = "#{input_editor_selector} span[data-slate-string='true']"
_input_selector = "#{input_editor_selector} span[data-slate-string='true']"
output_selector = "#{output_editor_selector} span[data-slate-string='true']"

input_ele = session.find_by_selector_wait! input_editor_selector
Expand Down

0 comments on commit b2b3be3

Please sign in to comment.