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

[Crystal]: New comments #2280

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion analyzer-comments/crystal/ameba/convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Which means this code doesn't follow general [code style][code style] convention
While this type of issue generally doesn't affect the way code _executes_, it can hurt
readability or the performance of automated tools such as documentation generators or test runners.

[code style]: https://crystal-lang.org/reference/latest/conventions/coding_style.html
[code style]: https://crystal-lang.org/reference/latest/conventions/coding_style.html
3 changes: 1 addition & 2 deletions analyzer-comments/crystal/ameba/warning.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Ameba warning

**Line %{lineno}** : %{message} was reported by Ameba.
**Line %{line_number}** : %{message} was reported by Ameba.

There is an issue in the code that could lead to a bug or error in the program.
While this error might not be _severe_, it could lead to more severe issues in the future.
It is recommend the problem be addressed before proceeding further.

15 changes: 15 additions & 0 deletions analyzer-comments/crystal/crystal-hunter/true_false.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# do not compare boolean values to true or false

Comparing boolean values to true or false is redundant.
Using `==` will generate a boolean value, so it is unnecessary to compare it to another hardcoded boolean value.
If wanting to flip the boolean value, use the `!` operator.

```crystal
# Rather than:
some_bool == true
some_bool == false

# Consider:
some_bool
!some_bool
```
3 changes: 3 additions & 0 deletions analyzer-comments/crystal/gigasecond/pow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# use 1e9 not math pow

Consider writing `%{value}` as `1e9`.
3 changes: 3 additions & 0 deletions analyzer-comments/crystal/leap/do_not_use_if_statement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# do not use if statement

Consider converting the `if`-statement(s) into a single expression using the `&&` and `||` operators.
14 changes: 14 additions & 0 deletions analyzer-comments/crystal/leap/use-is-divisable_by.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Modulo

Modulo comparisons is perfectly valid within Crystal, but a more readable way to compare the remainder of a division is with the [divisible_by?][divisible_by] method.
For example:

```crystal
# Rather than:
number % 2 == 0

# Consider:
number.divisible_by?(2)
```

[divisible_by]: https://crystal-lang.org/api/latest/Int.html#divisible_by%3F%28num%29%3ABool-instance-method
2 changes: 1 addition & 1 deletion analyzer-comments/crystal/navigation-computer/to_i.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ But when defining a [number literal][int], it is more idiomatic to use the `_i{b
500034214414_i64
```

[int]: https://crystal-lang.org/reference/latest/syntax_and_semantics/literals/integers.html
[int]: https://crystal-lang.org/reference/latest/syntax_and_semantics/literals/integers.html
4 changes: 2 additions & 2 deletions analyzer-comments/crystal/sieve/do_not_use_div_rem.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# do not use `%` or `/`
# do not use `%%` or `/`

Like the instructions mention, the purpose of this exercise is to build a Sieve of Eratosthenes without the use of operations such as division or modulo division.
Please refer to the [Wikipedia link][wikipedia] for a description of the algorithm.

Building the Sieve of Eratosthenes in an immutable language such as Crystal may feel a bit unnatural,
but it is a beautiful algorithm invented more than two millennia ago that is worth learning and implementing.

[wikipedia]: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
[wikipedia]: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
3 changes: 2 additions & 1 deletion analyzer-comments/crystal/two-fer/string_concatenation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# string concatenation

String concatenation is perfectly valid within Crystal, but a more common way to compose a string is with [string interpolation][interpolation]. For example:
String concatenation is perfectly valid within Crystal, but a more common way to compose a string is with [string interpolation][interpolation].
For example:

```crystal
# Rather than:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# do not use if statement

Consider converting the `if`-statement(s) into a single expression using parentheses(`()`) to control the order of evaluation.