From 43255d54f524b974a0ec1611ba9b8194066920c3 Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Sat, 14 Oct 2023 18:48:39 +0200 Subject: [PATCH 1/2] Add more comments --- analyzer-comments/crystal/ameba/convention.md | 9 +++++++++ analyzer-comments/crystal/ameba/warning.md | 7 +++++++ .../crystal/crystal-hunter/true_false.md | 15 +++++++++++++++ analyzer-comments/crystal/gigasecond/pow.md | 3 +++ .../crystal/leap/do_not_use_if_statement.md | 3 +++ .../crystal/navigation-computer/to_i.md | 14 ++++++++++++++ .../crystal/sieve/do_not_use_div_rem.md | 9 +++++++++ .../do_not_use_if_statement.md | 3 +++ 8 files changed, 63 insertions(+) create mode 100644 analyzer-comments/crystal/ameba/convention.md create mode 100644 analyzer-comments/crystal/ameba/warning.md create mode 100644 analyzer-comments/crystal/crystal-hunter/true_false.md create mode 100644 analyzer-comments/crystal/gigasecond/pow.md create mode 100644 analyzer-comments/crystal/leap/do_not_use_if_statement.md create mode 100644 analyzer-comments/crystal/navigation-computer/to_i.md create mode 100644 analyzer-comments/crystal/sieve/do_not_use_div_rem.md create mode 100644 analyzer-comments/crystal/wellingtons-weather-station/do_not_use_if_statement.md diff --git a/analyzer-comments/crystal/ameba/convention.md b/analyzer-comments/crystal/ameba/convention.md new file mode 100644 index 000000000..2694ef30d --- /dev/null +++ b/analyzer-comments/crystal/ameba/convention.md @@ -0,0 +1,9 @@ +# Ameba convention + +**Line %{line_number}** : %{message} was reported by Ameba. + +Which means this code doesn't follow general [code style][code style] conventions. +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 diff --git a/analyzer-comments/crystal/ameba/warning.md b/analyzer-comments/crystal/ameba/warning.md new file mode 100644 index 000000000..24ca4d411 --- /dev/null +++ b/analyzer-comments/crystal/ameba/warning.md @@ -0,0 +1,7 @@ +# Ameba warning + +**Line %{lineno}** : %{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. diff --git a/analyzer-comments/crystal/crystal-hunter/true_false.md b/analyzer-comments/crystal/crystal-hunter/true_false.md new file mode 100644 index 000000000..1a01430ea --- /dev/null +++ b/analyzer-comments/crystal/crystal-hunter/true_false.md @@ -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 +``` diff --git a/analyzer-comments/crystal/gigasecond/pow.md b/analyzer-comments/crystal/gigasecond/pow.md new file mode 100644 index 000000000..b6edea7fe --- /dev/null +++ b/analyzer-comments/crystal/gigasecond/pow.md @@ -0,0 +1,3 @@ +# use 1e9 not math pow + +Consider writing `%{value}` as `1e9`. \ No newline at end of file diff --git a/analyzer-comments/crystal/leap/do_not_use_if_statement.md b/analyzer-comments/crystal/leap/do_not_use_if_statement.md new file mode 100644 index 000000000..e307763aa --- /dev/null +++ b/analyzer-comments/crystal/leap/do_not_use_if_statement.md @@ -0,0 +1,3 @@ +# do not use if statement + +Consider converting the `if`-statement(s) into a single expression using the `&&` and `||` operators. diff --git a/analyzer-comments/crystal/navigation-computer/to_i.md b/analyzer-comments/crystal/navigation-computer/to_i.md new file mode 100644 index 000000000..e734144f0 --- /dev/null +++ b/analyzer-comments/crystal/navigation-computer/to_i.md @@ -0,0 +1,14 @@ +# to_i{bit} + +Using the `to_i{bit}` method, is a valid way to convert a value to a certain base. +But when defining a [number literal][int], it is more idiomatic to use the `_i{bit}` suffix. + +```crystal +# Rather than: +500034214414.to_i64 + +# Consider: +500034214414_i64 +``` + +[int]: https://crystal-lang.org/reference/latest/syntax_and_semantics/literals/integers.html diff --git a/analyzer-comments/crystal/sieve/do_not_use_div_rem.md b/analyzer-comments/crystal/sieve/do_not_use_div_rem.md new file mode 100644 index 000000000..52bf2cbcd --- /dev/null +++ b/analyzer-comments/crystal/sieve/do_not_use_div_rem.md @@ -0,0 +1,9 @@ +# 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 diff --git a/analyzer-comments/crystal/wellingtons-weather-station/do_not_use_if_statement.md b/analyzer-comments/crystal/wellingtons-weather-station/do_not_use_if_statement.md new file mode 100644 index 000000000..4d8fe8362 --- /dev/null +++ b/analyzer-comments/crystal/wellingtons-weather-station/do_not_use_if_statement.md @@ -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. From b2281e09e888dc1f35ecfde8f93f3e1edeeb6bfe Mon Sep 17 00:00:00 2001 From: meatball <69751659+meatball133@users.noreply.github.com> Date: Wed, 18 Oct 2023 20:17:53 +0200 Subject: [PATCH 2/2] Fixes and additons --- analyzer-comments/crystal/ameba/warning.md | 2 +- .../crystal/leap/use-is-divisable_by.md | 14 ++++++++++++++ .../crystal/sieve/do_not_use_div_rem.md | 2 +- .../crystal/two-fer/string_concatenation.md | 3 ++- 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 analyzer-comments/crystal/leap/use-is-divisable_by.md diff --git a/analyzer-comments/crystal/ameba/warning.md b/analyzer-comments/crystal/ameba/warning.md index 24ca4d411..51e0a640d 100644 --- a/analyzer-comments/crystal/ameba/warning.md +++ b/analyzer-comments/crystal/ameba/warning.md @@ -1,6 +1,6 @@ # 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. diff --git a/analyzer-comments/crystal/leap/use-is-divisable_by.md b/analyzer-comments/crystal/leap/use-is-divisable_by.md new file mode 100644 index 000000000..2643ccd46 --- /dev/null +++ b/analyzer-comments/crystal/leap/use-is-divisable_by.md @@ -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 diff --git a/analyzer-comments/crystal/sieve/do_not_use_div_rem.md b/analyzer-comments/crystal/sieve/do_not_use_div_rem.md index 52bf2cbcd..937fa52c9 100644 --- a/analyzer-comments/crystal/sieve/do_not_use_div_rem.md +++ b/analyzer-comments/crystal/sieve/do_not_use_div_rem.md @@ -1,4 +1,4 @@ -# 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. diff --git a/analyzer-comments/crystal/two-fer/string_concatenation.md b/analyzer-comments/crystal/two-fer/string_concatenation.md index b6474ffe0..b1fa88586 100644 --- a/analyzer-comments/crystal/two-fer/string_concatenation.md +++ b/analyzer-comments/crystal/two-fer/string_concatenation.md @@ -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: