Skip to content

Commit dcd5420

Browse files
authored
Merge pull request #105 from nobodywasishere/nobody/ameba-and-fixes
Add support for ameba + minor bugfixes
2 parents af728d7 + c677a5e commit dcd5420

File tree

12 files changed

+121
-26
lines changed

12 files changed

+121
-26
lines changed

.ameba.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Metrics/CyclomaticComplexity:
2+
Enabled: false
3+
4+
Style/ParenthesesAroundCondition:
5+
Description: Disallows redundant parentheses around control expressions
6+
ExcludeTernary: false
7+
AllowSafeAssignment: true
8+
Enabled: true
9+
Severity: Convention
10+
11+
Documentation/DocumentationAdmonition:
12+
Enabled: false
13+
Severity: Warning
14+
15+
Lint/NotNil:
16+
Description: Identifies usage of `not_nil!` calls
17+
Excluded:
18+
- src/crystalline/analysis/analysis.cr
19+
- src/crystalline/result_cache.cr
20+
- src/crystalline/workspace.cr
21+
Enabled: true
22+
Severity: Warning
23+
24+
Naming/BlockParameterName:
25+
Enabled: false
26+
Severity: Convention
27+
28+
Lint/RedundantStringCoercion:
29+
Description: Disallows redundant string conversions in interpolation
30+
Enabled: true
31+
Severity: Warning
32+
33+
Lint/ShadowingOuterLocalVar:
34+
Description:
35+
Disallows the usage of the same name as outer local variables for block
36+
or proc arguments
37+
Excluded:
38+
- src/crystalline/ext/compiler.cr
39+
Enabled: true
40+
Severity: Warning
41+
42+
Naming/QueryBoolMethods:
43+
Description: Reports boolean properties without the `?` suffix
44+
Enabled: false
45+
Severity: Convention
46+
47+
Style/WhileTrue:
48+
Description: Disallows while statements with a true literal as condition
49+
Enabled: false
50+
Severity: Convention
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Crystal Ameba
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- "**/*.cr"
9+
pull_request:
10+
branches:
11+
- master
12+
paths:
13+
- "**/*.cr"
14+
15+
jobs:
16+
lint:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
ameba-version: [v1.6.4]
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Crystal
27+
uses: crystal-lang/install-crystal@v1
28+
29+
- name: Cache Ameba binary
30+
id: cache-ameba
31+
uses: actions/cache@v3
32+
with:
33+
path: bin/ameba
34+
key: ${{ runner.os }}-ameba-${{ matrix.ameba-version }}
35+
36+
- name: Build Ameba
37+
if: steps.cache-ameba.outputs.cache-hit != 'true'
38+
run: |
39+
git clone --branch ${{ matrix.ameba-version }} --single-branch https://github.com/crystal-ameba/ameba.git
40+
cd ameba
41+
make bin/ameba CRFLAGS='-Dpreview_mt --no-debug'
42+
mkdir -p ../bin
43+
mv bin/ameba ../bin/ameba
44+
cd ..
45+
rm -rf ameba
46+
47+
- name: Run Ameba Linter
48+
run: bin/ameba -c .ameba.yml

src/crystalline/analysis/analysis.cr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Crystalline::Analysis
5151
compiler.stderr = dev_null
5252
compiler.flags = compiler_flags
5353

54-
if lib_path_override = lib_path
54+
if (lib_path_override = lib_path)
5555
path = Crystal::CrystalPath.default_path_without_lib.split(Process::PATH_DELIMITER)
5656
path.insert(0, lib_path_override)
5757
compiler.crystal_path = Crystal::CrystalPath.new(path)
@@ -123,13 +123,13 @@ module Crystalline::Analysis
123123
LSP::Log.debug { "Class of node at cursor: #{node.class} " }
124124
locations = begin
125125
if node.is_a? Crystal::Call
126-
if defs = node.target_defs
126+
if (defs = node.target_defs)
127127
defs.compact_map { |d|
128128
start_location = d.location.try { |loc| loc.expanded_location || loc }.not_nil!
129129
end_location = d.end_location.try { |loc| loc.expanded_location || loc }.not_nil!
130130
{start_location, end_location}
131131
}
132-
elsif expanded_macro = node.expanded_macro
132+
elsif (expanded_macro = node.expanded_macro)
133133
start_location = expanded_macro.location.try { |loc| loc.expanded_location || loc }.not_nil!
134134
end_location = expanded_macro.end_location.try { |loc| loc.expanded_location || loc } || start_location
135135
[{start_location, end_location}]
@@ -152,18 +152,18 @@ module Crystalline::Analysis
152152
elsif node.is_a? Crystal::Union
153153
Utils.locations_from_union(node, nodes)
154154
elsif node.is_a? Crystal::Var
155-
if definition = context[node.to_s]?
155+
if (definition = context[node.to_s]?)
156156
_, location = definition
157157
[{location, location}] if location
158158
end
159159
elsif node.is_a? Crystal::InstanceVar
160-
if ivar = context["self"]?.try &.[0].try &.lookup_instance_var? node.name
161-
if location = ivar.location
160+
if (ivar = context["self"]?.try &.[0].try &.lookup_instance_var? node.name)
161+
if (location = ivar.location)
162162
[{location, location}]
163163
end
164164
end
165165
elsif node.is_a? Crystal::ClassVar
166-
if cvar = context["self"]?.try &.[0].try &.all_class_vars[node.name]? # lookup_raw_class_var? node.name
166+
if (cvar = context["self"]?.try &.[0].try &.all_class_vars[node.name]?) # lookup_raw_class_var? node.name
167167
if (location = cvar.location)
168168
[{location, location}]
169169
end

src/crystalline/analysis/cursor_visitor.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module Crystalline::Analysis
7575
end
7676

7777
def visit(node)
78-
if node_location = node.location
78+
if (node_location = node.location)
7979
node_end_location = nearest_end_location(node)
8080

8181
if @top_level

src/crystalline/analysis/symbols_visitor.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module Crystalline::Analysis
2121
(@parent_symbol.try(&.children) || @symbols) << symbol
2222
end
2323

24-
private def with_parent(symbol : LSP::DocumentSymbol)
24+
private def with_parent(symbol : LSP::DocumentSymbol, &)
2525
append_symbol(symbol)
2626
old_parent = @parent_symbol
2727
@parent_symbol = symbol
@@ -91,7 +91,7 @@ module Crystalline::Analysis
9191
end
9292

9393
def visit(node : Crystal::Arg)
94-
if (@parent_symbol.try &.kind.enum?)
94+
if @parent_symbol.try &.kind.enum?
9595
symbol = create_symbol_from_node(node, :enum_member)
9696
append_symbol(symbol)
9797
end

src/crystalline/broken_source_fixer.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Crystalline::BrokenSourceFixer
6565
end
6666
end
6767

68-
while line_info = stack.pop?
68+
while (line_info = stack.pop?)
6969
lines[-1] = "#{lines[-1]}; #{closing_keyword(line_info)}"
7070
end
7171

@@ -142,7 +142,7 @@ class Crystalline::BrokenSourceFixer
142142
keyword : String?,
143143
closing_keyword : String?,
144144
last_info : LineInfo,
145-
line : String
145+
line : String,
146146
)
147147
# If the indent is less than the opening one it's definitely wrong.
148148
if indent < last_info.indent

src/crystalline/controller.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Crystalline::Controller
2121
# Compile the workspace at once.
2222
spawn same_thread: true do
2323
workspace.projects.each do |p|
24-
if entry_point = p.entry_point?
24+
if (entry_point = p.entry_point?)
2525
workspace.compile(@server, entry_point)
2626
end
2727
end

src/crystalline/ext/compiler.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Crystal
1818
class SemanticVisitor < Visitor
1919
# Make it possible to visit in-memory.
2020
def visit(node : Require)
21-
if expanded = node.expanded
21+
if (expanded = node.expanded)
2222
expanded.accept self
2323
return false
2424
end
@@ -103,7 +103,7 @@ module Crystal
103103
# Will not raise if the semantic analysis fails.
104104
def error_tolerant_semantic(node : ASTNode, cleanup = true) : ASTNode
105105
node, processor = top_level_semantic(node)
106-
error_tolerant = true
106+
@error_tolerant = true
107107
error_stack.clear
108108

109109
begin

src/crystalline/project.cr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class Crystalline::Project
7575
# Finds the path-wise distance to the given file URI. If the file URI is not a
7676
# dependency of this workspace's entry point, returns nil.
7777
def distance_to_dependency(file_uri : URI) : Int32?
78-
file_path = file_uri.decoded_path
7978
relative = Path[file_uri.decoded_path].relative_to?(root_uri.decoded_path)
8079

8180
# If we can't get a relative path, give it the maximum distance possible, so

src/crystalline/text_document.cr

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ class Crystalline::TextDocument
2525
@inner_contents.size
2626
end
2727

28-
alias ContentChange = {contents: String, range: LSP::Range?}
29-
30-
def update_contents(content_changes = Array(ContentChange), version : Number? = nil)
28+
def update_contents(content_changes : Array({String, LSP::Range?}), version : Number? = nil)
3129
content_changes.each { |change|
3230
update_contents(*change, version: version)
3331
}

0 commit comments

Comments
 (0)