Commit Graph

570 Commits

Author SHA1 Message Date
Vitalii Elenhaupt 7192b64df0
Fix rest of the specs 2022-03-11 18:00:25 +02:00
Vitalii Elenhaupt 1cfc926a28
Fix specs for tokenizer 2022-03-11 16:18:33 +02:00
Vitalii Elenhaupt 03adc20872
Pass on crystal-nightly 2022-03-11 14:15:05 +02:00
Sijawusz Pur Rahnama dad72341cb
Merge pull request #258 from crystal-ameba/bump-large-numbers-min-int-digits
Bump default value of `LargeNumbers#int_min_digits` to 6
2022-03-08 14:48:45 +01:00
Sijawusz Pur Rahnama 1795bd2959 Bump default value of `LargeNumbers#int_min_digits` to 6
As most of the error codes are smaller than 6 digits
2022-03-08 14:42:32 +01:00
Sijawusz Pur Rahnama 9e81777e7e
Disable `Style/LargeNumbers` by default 2022-03-05 22:38:36 +01:00
Sijawusz Pur Rahnama 66ee7642cf Add `Lint/DebugCalls` rule 2021-12-31 16:44:02 +01:00
fn ⌃ ⌥ f288cc3c4f
Add `Style/GuardClause` rule (#254) 2021-12-09 21:33:47 +01:00
fn ⌃ ⌥ 63a6c73dc0
Autocorrect various rules (#253) 2021-11-16 22:30:33 +01:00
Vitalii Elenhaupt 429f76f8b6
Do not report unreachable code after loops
closes #251
2021-11-10 09:16:14 +02:00
fn ⌃ ⌥ 01dfcbe76a Add tests for `AST::Util#control_exp_code` 2021-11-09 11:52:31 -08:00
fn ⌃ ⌥ c9ba487373 Add custom `NodeVisitor` subclass for `Style/VariableNames` 2021-11-09 09:26:00 -08:00
fn ⌃ ⌥ 72a3487bb6 Autocorrect `Stye/WhileTrue` 2021-11-08 14:24:11 -08:00
fn ⌃ ⌥ 571969265f Convert `Style/VerboseBlock` spec 2021-11-08 14:24:11 -08:00
fn ⌃ ⌥ e93dfe9cdc Convert `Style/VariableNames` spec 2021-11-08 14:24:11 -08:00
fn ⌃ ⌥ e7cfe387d6 Autocorrect `Stye/RedundantNext` and `Style/RedundantReturn` 2021-11-08 14:07:35 -08:00
fn ⌃ ⌥ 7b437fbd2f
Remove `normalize` parameter from `expect_issue` (#249)
* Add `normalize` parameter to `expect_correction`

* Convert Style/IsAFilter spec

* Revert "Add `normalize` parameter to `expect_correction`"

This reverts commit 4b67e4b900.

* Remove `normalize` parameter from `expect_issue`

* Require indentation if multiple issues on a single line

* Update `Style/IsAFilter` spec

* Update `ExpectIssue` documentation

* Add missing `expect_no_corrections`

* Use carets and space with issues at column 1 or 2

* Update `expect_issue` docs
2021-11-06 15:15:19 +02:00
Sijawusz Pur Rahnama 7cb0c15747
Merge pull request #248 from FnControlOption/autocorrect
Add autocorrect
2021-11-01 20:24:43 +01:00
fn ⌃ ⌥ c2aa2fedb6 Return `source` from `expect_issue` 2021-10-31 22:44:48 -07:00
fn ⌃ ⌥ 470e41cb7b Raise error if attempting to both explain issue and autocorrect 2021-10-31 22:23:14 -07:00
fn ⌃ ⌥ a40fdee33f Revert "Add autocorrect checks to `ExplainFormatter`"
This reverts commit 1b6fe40a3b.
2021-10-31 22:12:21 -07:00
Vitalii Elenhaupt 3e1df339ae
Consistent parser options 2021-11-01 02:08:16 +02:00
fn ⌃ ⌥ 61fc99e107 Inline the `do_combine` method 2021-10-27 11:19:15 -07:00
fn ⌃ ⌥ 73e97ac42e Avoid using iterators and throw-away heap allocations 2021-10-27 11:08:18 -07:00
fn ⌃ ⌥ b7bb282b99 Apply suggestions from code review 2021-10-27 10:08:36 -07:00
fn ⌃ ⌥ d51ef27d54 Add `remove_preceding`, `remove_leading`, `remove_trailing` 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ 1b6fe40a3b Add autocorrect checks to `ExplainFormatter` 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ 8d3b76003e Add autocorrect checks to Flycheck, JSON, and TODO formatters 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ 749c53527e Add documentation 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ 437584f9db Raise error if infinite correction loop 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ 16608965f5 Allowed named arguments with `Rule::Base.issue_for` 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ 3b11491cea Add `insert_*` overloads that accept both location and end_location 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ e8c0f49cb8 Delete redundant alias `SourceLocation` 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ f87d99a83b Add `Corrector` method overloads that accept `ASTNode` 2021-10-26 22:22:22 -07:00
fn ⌃ ⌥ 1d5f554e88 Apply suggestions from code review 2021-10-26 12:06:24 -07:00
fn ⌃ ⌥ f39a7a4cd4 Re-run autocorrect until all correctable issues have been corrected 2021-10-25 15:09:44 -07:00
fn ⌃ ⌥ 573881cb8a Autocorrect `Layout/TrailingBlankLines` partially 2021-10-25 12:38:29 -07:00
fn ⌃ ⌥ e5fb0526e0 Autocorrect `Style/LargeNumbers` 2021-10-25 12:38:29 -07:00
fn ⌃ ⌥ 99e7ccd23b Add `--autocorrect` CLI option 2021-10-25 12:38:29 -07:00
fn ⌃ ⌥ d3d3ccd7e3 Add `expect_correction` and `expect_no_corrections` 2021-10-25 12:38:29 -07:00
fn ⌃ ⌥ c1b4add094 Add `Source::Corrector` and `Source::Rewriter` 2021-10-25 12:38:29 -07:00
fn ⌃ ⌥ 9f0b9a709e Allow named replacements in expect_issue 2021-10-23 01:37:24 -07:00
fn ⌃ ⌥ 3d432fdee8
Add expect_issue and expect_no_issues spec helpers (#245) 2021-10-22 19:54:39 +02:00
fn ⌃ ⌥ 48b15b9bf8
Add Lint/AmbiguousAssignment rule (#244) 2021-10-19 11:44:41 +02:00
Sijawusz Pur Rahnama 43dea0e49d Fix typos throughout the codebase 2021-07-03 14:15:23 +02:00
Caspian Baska c49c69ed9f
Early return in CountVisitor if macro node
Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
2021-06-06 04:12:56 +10:00
Caspian Baska 0ea6238dc6
Count an exhaustive `case`'s complexity as 1 2021-06-05 22:31:58 +10:00
Vitalii Elenhaupt a64f48b543
ShadowingOuterLocalVar while it is not in macro
closes #224
2021-04-18 20:55:10 +03:00
Vitalii Elenhaupt 9e2d4f1856
Disable performance rules for spec files
closes #220
2021-04-18 09:39:55 +03:00
Sijawusz Pur Rahnama 788e0a3fad Enable MapInsteadOfBlock rule again 2021-04-12 06:23:03 +02:00
Sijawusz Pur Rahnama 2694a0c865 Remove “join” from the list of trigger methods 2021-04-12 06:22:54 +02:00
Vitalii Elenhaupt 58d7775d65
Merge branch 'master' into develop 2021-04-04 21:08:02 +03:00
Sijawusz Pur Rahnama 8d21733b10 Skip macro code in Style/IsAFilter rule 2021-04-04 11:19:45 +02:00
Vitalii Elenhaupt 0881b861d7
Disable MapInsteadOfBlock by default
refs #208
2021-03-29 09:15:18 +03:00
Stephen Dolan 04ba9cd57a
Change Style/VerboseBlock - ExcludeOperators - setting default (#218) 2021-03-24 21:16:51 +01:00
Vitalii Elenhaupt 13605afe4a
Do not report IsAFilter if there is a block with multiple args 2021-03-23 20:57:50 +02:00
Vitalii Elenhaupt ad405e09b0
Merge branch 'master' into develop 2021-03-08 11:09:32 +02:00
Sijawusz Pur Rahnama 56110b3883 Default to exclude_multiple_line_blocks in Style/VerboseBlock rule 2021-03-03 00:31:53 +01:00
Sijawusz Pur Rahnama 8f308e73e5 Add ~ as the prefix operator 2021-03-02 12:40:46 +01:00
Vitalii Elenhaupt 3a1ee7fa21
Correct yml examples 2021-02-11 11:01:30 +02:00
Sijawusz Pur Rahnama 694c41650c Remove redundant check and add a few more test cases 2021-02-05 01:23:29 +01:00
Sijawusz Pur Rahnama a9d1b17deb Support named arguments in VerboseBlock#node_to_s 2021-02-05 01:23:29 +01:00
Sijawusz Pur Rahnama 16743a756c Add ExcludePrefixOperators option to Style/VerboseBlock rule 2021-02-04 21:59:23 +01:00
Sijawusz Pur Rahnama eed094b928 Fix couple of edge-cases in VerboseBlock rule 2021-02-04 21:59:23 +01:00
Sijawusz Pur Rahnama 5faf8da81c Split VerboseBlock#test method into a smaller pieces 2021-02-04 21:59:23 +01:00
Sijawusz Pur Rahnama 4b7f3ba6ee Add MaxLineLength option to Style/VerboseBlock rule 2021-02-04 21:59:22 +01:00
Sijawusz Pur Rahnama a53d44617d Fix newly found issues 2021-02-04 21:59:22 +01:00
Sijawusz Pur Rahnama 0739fad670 Add Style/VerboseBlock rule 2021-02-04 21:59:22 +01:00
Sijawusz Pur Rahnama 99da6b6916 Merge remote-tracking branch 'origin/master' into master-into-develop 2021-02-03 22:45:35 +01:00
Vitalii Elenhaupt f8c22a6e77
Utilize Source#spec? 2021-02-03 17:25:46 +02:00
Vitalii Elenhaupt ecad80a96b
NewRule: SpecFocus
closes #172
2021-02-03 17:10:07 +02:00
Vitalii Elenhaupt 51b0a07e81
Avoid exponential recursion while finding variable references in scopes (#203)
* Avoid exponential recursion while finding variable references in scopes

* Adjust source example in test
2021-01-31 16:40:44 +02:00
Sijawusz Pur Rahnama fac8072ec1
Merge pull request #197 from crystal-ameba/feature/any-instead-of-empty
Add Performance/AnyInsteadOfEmpty rule
2021-01-28 10:28:30 +01:00
Sijawusz Pur Rahnama 7b3c814914 Fix newly found issues 2021-01-28 01:03:48 +01:00
Sijawusz Pur Rahnama d71091a40c Add Performance/AnyInsteadOfEmpty rule 2021-01-28 01:03:48 +01:00
Sijawusz Pur Rahnama 95d340c3ad Add Style/IsAFilter rule 2021-01-28 00:58:06 +01:00
Sijawusz Pur Rahnama ea98554191
Add support for showing end location marker (#200)
* Add support for showing end location marker

* Cleanup Reportable method definitions

There’s no need for double splats, since they mess up method resolution, and obscure the actual - single (!) - argument - `status`, so… be gone

Also, all of the helpers return the constructed `Issue` like a behaving good methods.

* Refactor Util#affected_code

* Increase max length of trimmed lines to 120 characters

* Refactor Issue to use enum instead of a symbol for #status

* Optimize Reportable#valid?

* Add spec coverage for newly added Util methods

* Refactor DotFormatter a bit

Make text format moar in line with Crystal spec runner.

* Update README.md
2021-01-26 08:38:19 +02:00
Sijawusz Pur Rahnama 6acb8ad2eb ChainedCallsWithNoBang -> ChainedCallWithNoBang 2021-01-22 17:24:45 +01:00
Sijawusz Pur Rahnama 8babeea80f Add `repeated_combinations` and `repeated_permutations` 2021-01-22 12:21:14 +01:00
Sijawusz Pur Rahnama a219a73258 Remove rotate from the list of call_names
In some cases it returns `self` and not a copy.
2021-01-22 12:20:50 +01:00
Sijawusz Pur Rahnama d3b952f58a Add Performance/ChainedCallsWithNoBang rule 2021-01-21 12:47:10 +01:00
Vitalii Elenhaupt 7aa7efd4bd Do not report if variable is assigned and referenced in MacroFor/MacroIf/MacroExpression
closes #194
2021-01-20 13:14:42 +02:00
Sijawusz Pur Rahnama ad8f570a04 Change Rule to class 2021-01-19 22:17:17 +01:00
Sijawusz Pur Rahnama ddaa58f475
Merge pull request #192 from crystal-ameba/feature/flatten-after-map-rule
Add Performance/FlattenAfterMap rule
2021-01-19 22:16:10 +01:00
Sijawusz Pur Rahnama 4958fa2315
Merge pull request #184 from mamantoha/fix-crystal-nightly
fix Crystal nightly
2021-01-19 13:18:18 +02:00
Sijawusz Pur Rahnama 23b4b4c4f0 Add Performance/FlattenAfterMap rule 2021-01-18 18:04:54 +01:00
Sijawusz Pur Rahnama b7286dc673 Add Performance/CompactAfterMap rule 2021-01-18 18:04:12 +01:00
Sijawusz Pur Rahnama d2fa75280f
Extend JoinAfterMap to check also calls to `sum/product` and rename it to MapInsteadOfBlock (#190) 2021-01-18 17:42:50 +02:00
Vitalii Elenhaupt e9ec91654c New Rule: Lint/DuplicatedRequire
closes https://github.com/crystal-ameba/ameba/issues/176
2021-01-17 22:32:24 +02:00
Sijawusz Pur Rahnama 6898aa8976
Fix issue #187 (#189)
* Avoid using `tap` with structs

* Remove extraneous blank lines

* Readability
2021-01-17 22:31:53 +02:00
Sijawusz Pur Rahnama 928a260d51 Remove extraneous blank lines 2021-01-17 18:45:14 +01:00
Sijawusz Pur Rahnama af5d825015 Followup to #185 2021-01-17 18:45:14 +01:00
Sijawusz Pur Rahnama fd4b2f309c Don’t allocate the array on every call 2021-01-17 18:05:08 +01:00
Sijawusz Pur Rahnama 5e58a60ade Move constant definitions after `properties` call 2021-01-17 17:39:32 +01:00
Sijawusz Pur Rahnama a892cd43b0 Add Performance/JoinAfterMap rule 2021-01-17 16:57:15 +01:00
Sijawusz Pur Rahnama 06852c490b Followup to #185 2021-01-17 13:25:50 +01:00
Sijawusz Pur Rahnama 1a091c1f1a
Optimize rules (#185)
* Replace pointless interpolations with actual values

* Rules optimizations

* Stylistic refactors

* Remove extraneous blank lines

* Remove some instances of .not_nil! usage
2021-01-17 14:16:04 +02:00
Sijawusz Pur Rahnama 270a003df6
Merge pull request #184 from mamantoha/fix-crystal-nightly
fix Crystal nightly
2021-01-16 19:53:48 +01:00
Anton Maminov 6f0f8352f9 fix Crystal nightly 2021-01-16 20:42:27 +02:00
Sijawusz Pur Rahnama c4d34d74d8
Add support for showing code context lines (#181)
* Add support for showing code context lines

* Show context lines only in ExplainFormatter

* Add spec coverage for context_lines option
2021-01-12 17:20:43 +02:00
Sijawusz Pur Rahnama 19c370aee0
Misc refactors (#180)
* Optimize Severity#symbol

* Remove empty else branches

* Optimize map+compact/flatten calls

* Misc stylistic refactors
2021-01-11 20:13:58 +02:00
Sijawusz Pur Rahnama 2eff832669 Add --rules switch to the CLI 2021-01-09 21:01:04 +01:00
Vitalii Elenhaupt de3f16a9dc
Disable Lint/EmptyExpression rule
closes #169
2020-10-23 19:21:39 +03:00
Vitalii Elenhaupt 44290a6a5d
Handle case when compiler reports incorrect node location
fixes #168
2020-10-23 10:41:17 +03:00
Vitalii Elenhaupt f8d57345d4
Merge branch 'develop' 2020-08-26 22:46:03 +03:00
Vitalii Elenhaupt b5bd76dfa8
Useless Assign: ignore variables with '_' prefix
closes #164
2020-08-20 21:15:58 +03:00
Vitalii Elenhaupt d650ca5477
Incorrectly reporting shadowingOuterLocalVar within macro included
closes #161
2020-07-15 10:18:12 +03:00
Vitalii Elenhaupt 7f501a1df5
RedundantStringCoercion: do not report to_s with named args
closes #160
2020-06-24 09:26:03 +03:00
Vitalii Elenhaupt 3448de30da
Enable rules which were disabled during bugfix release 2020-06-19 21:41:02 +03:00
Vitalii Elenhaupt c3260c1740
Move to YAML::Serializable 2020-06-15 14:29:49 +03:00
Vitalii Elenhaupt 25fd493145
Fix compatiblity with crystal nightly 2020-05-14 11:43:13 +03:00
Vladislav Trotsenko bdeb6e3391
Feature/Layout trailing lines, final newline checkup (#152) 2020-05-05 16:52:24 +03:00
Matheus Richard f1adf14527
Handle duplicated files on GlobUtils (#151)
* Handle duplicated files on GlobUtils

* Update src/ameba/glob_utils.cr

Co-Authored-By: George Dietrich <yomoejoe@gmail.com>

Co-authored-by: George Dietrich <yomoejoe@gmail.com>
2020-04-19 11:52:15 +03:00
Vitalii Elenhaupt b215b34060
Disable new rules before the coming bugfix release 2020-04-13 10:11:15 +03:00
Vitalii Elenhaupt 478da94c20
Allow constants to be in PascalCase (i.e. Log, SuperConstant)
closes #148
2020-04-13 09:38:05 +03:00
Sijawusz Pur Rahnama 1a25583036
Make InlineComments::COMMENT_DIRECTIVE_REGEX more strict (#146) 2020-04-11 09:55:41 +03:00
Vitalii Elenhaupt 458c492730
Do not report shadowing outer local var is var is declared below the
shadowed var

closes #144
2020-04-10 10:44:42 +03:00
Vitalii Elenhaupt 99c65b5a28
New rule: Lint/BadDirective (#143)
* New rule: Lint/BadDirective

* Address PR feedback
2020-04-06 15:10:34 +03:00
Vitalii Elenhaupt db6b54e63c
New rule: Style/IsANil 2020-03-29 19:45:13 +03:00
Vitalii Elenhaupt 02f4afaa64
Correct doc typo 2020-03-27 23:17:36 +02:00
Vitalii Elenhaupt 04497feeed
Lint/LiteralInInterpolation: properly report node position 2020-03-27 19:44:04 +02:00
Brian J. Cardiff 6259e26457 Comply exhaustive case check 2020-03-27 09:25:07 -03:00
Vitalii Elenhaupt 9c6bc2a376
Merge pull request #137 from crystal-ameba/feat/redundant-string-coercion
New rule: Lint/RedundantStringCoercion
2020-03-26 23:55:23 +02:00
Vitalii Elenhaupt 59bc021e57
Do not report if Object#to_s is called without receiver 2020-03-26 23:51:54 +02:00
Vitalii Elenhaupt ff1669ebe8
New rule: Lint/RedundantStringCoercion 2020-03-26 16:26:27 +02:00
Vitalii Elenhaupt 98bc6bb76a
Improve Lint/SharedVarInFiber rule description 2020-03-26 15:18:44 +02:00
Vitalii Elenhaupt f27842e111
Correct doc typos 2020-03-26 10:35:27 +02:00
Vitalii Elenhaupt a6958ab455
New rule: EmptyLoop 2020-03-26 10:27:00 +02:00
Vitalii Elenhaupt 1a0468c653
Use NodeVisitor by default and remove the boilerplace code 2020-03-25 18:21:07 +02:00
Vitalii Elenhaupt 4f185db0a2
New rule: SharedVarInSpawn
closes #132
2020-03-25 17:52:20 +02:00
Vitalii Elenhaupt 0002c36fae
RedundantNext params 2020-03-24 18:27:49 +02:00
Vitalii Elenhaupt a5dd07e9e4
New rule: RedundantNext
closes #131
2020-03-24 18:06:01 +02:00
Vitalii Elenhaupt 946ec67fae
Include binary op node to redundant return 2020-03-22 20:12:24 +02:00
Vitalii Elenhaupt 9a6c4e52f4
Document Globs/Excluded 2020-03-22 15:08:04 +02:00
Vitalii Elenhaupt 2303bd82ae
Ability to excluded globally 2020-03-22 15:05:47 +02:00
Vitalii Elenhaupt bffc46c545
Ability to configure globs 2020-03-22 15:05:47 +02:00
Vitalii Elenhaupt aff723b682
Incorrectly reporting shadowingOuterLocalVar within macro included
closes #129
2020-02-15 20:49:47 +02:00
Vitalii Elenhaupt 43b566a852
Crystal 0.33 formatting 2020-02-15 17:33:20 +02:00
Vitalii Elenhaupt cc3200f3cf
Reformat sources 2020-01-11 23:58:06 +02:00
Vitalii Elenhaupt 74dfa0b934
Lint/UselessAssign: ignore transformed assignemnts by the compiler
closes #127
2020-01-11 23:51:28 +02:00
Vitalii Elenhaupt 6b56c87e78
Shadowing via short instance variable syntax
closes #122
2019-11-11 15:51:09 +02:00
Vitalii Elenhaupt fde321f7e6
New rule: RedundantWithObject (#121) 2019-11-10 09:47:30 +02:00
Vitalii Elenhaupt b6cc454039
New rule: RedundantWithIndex (#120) 2019-11-10 09:29:17 +02:00
Vitalii Elenhaupt 07e72b7bf9
Lint in parallel (#118)
* Lint in parallel

* Synced output for dot/flycheck formatters

* Re-raise exceptions raised in fibers

* Add readme instructions
2019-11-09 19:31:41 +02:00
Vitalii Elenhaupt 8d00d54012
Fix typos 2019-10-28 00:02:31 +02:00
Vitalii Elenhaupt 4ae0195628
Avoid duplicated sections in a generated TODO file (additional fix) 2019-10-27 22:56:53 +02:00
Vitalii Elenhaupt 111596541b
Avoid duplicated sections in a generated TODO file 2019-10-27 22:15:04 +02:00
Vitalii Elenhaupt 19d9223ec1
Properly detect if scope references a variable 2019-10-27 21:53:07 +02:00
Vitalii Elenhaupt 904b5beec2
Lint/UnusedArgument: fails to recognized used argument inside macro
closes #117
2019-10-27 21:32:55 +02:00
Vitalii Elenhaupt 677c75716f
Typeof scope 2019-10-27 21:22:33 +02:00
Vitalii Elenhaupt 2704a0d8b1
Do not generate todo file there are no issues 2019-10-27 17:49:30 +02:00
Vitalii Elenhaupt 504f537208
Parse docs 2019-07-22 16:23:59 +03:00
Vitalii Elenhaupt 9065a5f414
Remove unneeded code to support crystal 0.24.2 2019-07-19 23:51:30 +03:00
Vitalii Elenhaupt b868d88a85
CyclomaticCompexity: report onle def name 2019-07-12 23:33:08 +03:00
Vitalii Elenhaupt 54706192d2
Default cmd args 2019-07-06 22:42:50 +03:00
Vitalii Elenhaupt ffa5dc9b4c
Crystal 0.29 fixes (#109)
* Fixes vs crystal head

* Use crystal nightly

* Remove trailing ? from local variable

* Do not use ? in the lhs

ref https://github.com/crystal-lang/crystal/issues/6685#issuecomment-419758587

* Upgrade to crystal 0.29.0 (warnings free) (#108)

* Remove trailing ? from local variable (take 2)

* Fix Time.now deprecation warnings

* Remove Crystal nightly
2019-06-06 19:10:26 +03:00
Vitalii Elenhaupt 037d1dde74
Performance/FirstLastAfterFilter: ignore .first/.last with args
closes #104
2019-06-03 18:25:48 +03:00
Vitalii Elenhaupt de587f500a
Rename Severity::Refactoring -> Severity::Convention
it preserves clang format
2019-05-11 21:17:49 +03:00
Vitalii Elenhaupt 94e1d4567a
Properly report performance rules in macros
closes #102
2019-05-05 18:05:08 +03:00
Vitalii Elenhaupt 2ddf26b8c3
Correct doc example 2019-04-29 16:27:12 +03:00
Vitalii Elenhaupt ca5e894e0b
Rename Severity.from_name to Severity.parse 2019-04-26 18:15:36 +03:00
Vitalii Elenhaupt af395a3c13
Do not report if disabled rules exist
closes #101
2019-04-25 08:47:37 +03:00
Vitalii Elenhaupt f1fe34f8b9
Use Enum.parse 2019-04-14 19:31:50 +03:00
Vitalii Elenhaupt 117e100855
Add severity to formatters 2019-04-14 16:45:31 +03:00
Vitalii Elenhaupt 575fe07879
Change the level of failure in the runner 2019-04-14 15:57:48 +03:00
Vitalii Elenhaupt f6a57f9272
Set default severities 2019-04-14 12:15:38 +03:00
Vitalii Elenhaupt 0be42f94db
Convertable severity 2019-04-13 21:16:59 +03:00
Vitalii Elenhaupt c95ea297bd
Stop calculating cyclomatic complexity for methods which have Macro conditions (#99) 2019-03-31 20:27:20 +03:00
Vitalii Elenhaupt a059ade305
Remove one-line methods
Unnecessary level of abstraction
2019-03-23 19:25:16 +02:00
Vitalii Elenhaupt 3a71b86193
Properly report literals (#96) 2019-03-23 19:20:32 +02:00
Vitalii Elenhaupt d2b36047ef
Correct variable name rule doc 2019-02-24 20:04:35 +02:00
Vitalii Elenhaupt 3dabfb8dec
Correct json formatter output example 2019-02-24 20:04:04 +02:00
Sijawusz Pur Rahnama e8a68a80d5 Fix several misspellings (#94) 2019-02-23 07:06:28 +02:00
Hannes Käufler e850bff60f Hk cyclomatic complexity (#92)
* Proof of concept for cyclomatic complexity

* Enable configurability of rule

* Use the same nodes to increment the complexity as rubocop

* Fix typo in test description

* Properly indent code and simplify macro

* Move metric into metrics

* Cover a violation supressed by increased threshold

* Extract visitor into its own file

* Document cyclomatic complexity rule and visitor

* Refactor specs to use a macro

* Indent code inside macro

* Replace array with tuple for string formatting.

`Tuple` is stack based, whereas `Array` is allocated on the heap increasing GC pressure.

* Fix formatting

* Enable cyclomatic complexity rule by default
2019-02-16 21:03:44 +02:00
Vitalii Elenhaupt f294bb6a68
Improve explain output 2019-01-13 22:14:25 +02:00
Vitalii Elenhaupt 3c5e3cdef4
Exclude globs as arguments
Examples:

  $ ameba path/to/shard/*.cr !path/to/shard/lib
  $ ameba . !lib
2019-01-13 10:48:46 +02:00
Vitalii Elenhaupt 866af184f1
Redundant return (#87) 2018-12-30 09:04:59 +02:00
Vitalii Elenhaupt c91da1aa08
Let ameba explain the issue at the specified location (#86) 2018-12-27 23:34:10 +02:00
Vitalii Elenhaupt 4e19571fb3
Correct VariableNames doc example 2018-12-26 10:57:06 +02:00
Vitalii Elenhaupt 32ac199162
Correct trailing blank line position 2018-12-24 00:44:15 +02:00
Vitalii Elenhaupt 1d96319506
Remove unneded argument 2018-12-15 22:16:40 +02:00
Vitalii Elenhaupt 60ce034f1b
UnusedArgument: fix crystal upgrade regression 2018-12-12 22:21:33 +02:00
Vitalii Elenhaupt f671d6f857
Show affected code while using a default formatter 2018-12-12 21:45:00 +02:00
Vitalii Elenhaupt 148044f479
Add description to syntax special rule 2018-12-09 00:12:14 +02:00
Vitalii Elenhaupt 20938da89a
Dynamically load rule documentation 2018-12-08 22:52:32 +02:00
Vitalii Elenhaupt f8dab3bc34
MethodNames: correct reported location/end_location 2018-11-25 00:56:21 +02:00
Vitalii Elenhaupt e951c0772a
ConstantNames: correct reported end_location 2018-11-25 00:37:46 +02:00
Vitalii Elenhaupt 9885457227
Track issue.end_location properly 2018-11-24 19:38:13 +02:00
Vitalii Elenhaupt ad2c6bad0e
Use utility method to check if node is a loop 2018-11-22 11:52:00 +02:00
V. Elenhaupt 0fd5890738
Extend UnreachableCode rule: handle control flow (#83) 2018-11-22 10:38:32 +02:00
Vitalii Elenhaupt eca0f3f350
Handle raise, exit, abort in unreachable code 2018-11-11 20:33:48 +02:00
Vitalii Elenhaupt 67d76116f7
Basic implementation of UnreachableCode rule 2018-11-05 21:39:27 +02:00
Vitalii Elenhaupt 12aa48c98f
Fix Style/RedundantBegin: begin-end in a proc literal
closes #80
2018-09-22 21:58:38 +03:00
V. Elenhaupt cb5f802012
Correctly process record declaration at a top level (#78) 2018-09-07 00:47:02 +03:00
Vitalii Elenhaupt 18ac04d992
Generate UTC time in todo 2018-09-06 18:48:36 +03:00
V. Elenhaupt fd78d17c40
New rule: Performance/FirstLastAfterFilter (#76) 2018-09-06 17:59:11 +03:00
Vitalii Elenhaupt a1b34eb7be
New rule: Performance/AnyAfterFilter 2018-09-03 22:55:10 +03:00
Vitalii Elenhaupt 068733a9d3
Correct yaml configuration examples in docs 2018-09-03 22:53:11 +03:00
Vitalii Elenhaupt 790b519653
Performance/Count -> Performance/SizeAfterFilter 2018-09-03 22:44:30 +03:00
Vitalii Elenhaupt 799c0fd5e1
Correct location name of reported issue 2018-09-03 13:26:19 +03:00
Vitalii Elenhaupt 9fa13848bf
Correct doc example for Count rule 2018-09-03 12:00:23 +03:00
Vitalii Elenhaupt 446f557c23
New rule: Performance/Count 2018-09-03 01:07:34 +03:00
Vitalii Elenhaupt f4680a75f4
Apply default formatting 2018-09-03 00:17:56 +03:00
Vitalii Elenhaupt d60aea102f
Add --no-color cli flag
closes #72
2018-08-13 00:05:11 +03:00
Vitalii Elenhaupt 248c5a656b
Add `--all` cli flag that enables all available rules 2018-07-04 15:20:35 +03:00
Vitalii Elenhaupt 970ca4be1b
Disable PredicateName and LargeNumbers rules by default 2018-07-04 14:11:24 +03:00
Vitalii Elenhaupt dbac46b68a
Ignore outer shadowing of throwaway variables
closes #67
2018-06-25 17:02:46 +03:00
Vitalii Elenhaupt 98f0aa71e9
Allow to disable group of rules using inline directives 2018-06-23 16:52:48 +03:00
Vitalii Elenhaupt 04c7300964
Handle type declarations in scopes
closes #66
2018-06-23 08:48:13 +03:00
V. Elenhaupt fafc5f4bdc
Allow filtering by group name (#65) 2018-06-18 10:25:06 +03:00
V. Elenhaupt 4cb5328513
Add rule namespaces: style, lint, layout (#63) 2018-06-16 14:50:59 +03:00
Vitalii Elenhaupt 23245d0e52 Add end_location to json formatter 2018-06-12 12:55:56 +03:00
Vitalii Elenhaupt f8d14d4222 Rename Error to Issue 2018-06-12 12:55:56 +03:00
Vitalii Elenhaupt e1b51f62a5
Exclude file pattern match
closes #61
2018-05-29 13:19:00 +03:00
Vitalii Elenhaupt c12b4f1aa5 Shadowed argument 2018-05-29 09:47:32 +03:00
Vitalii Elenhaupt 15bb8f5331 Detect shadowing outer local vars 2018-05-29 09:47:20 +03:00
Vitalii Elenhaupt 3887da1438 Redundant begin: do not report if there is an inner handler
fixes #56
2018-05-25 11:23:11 +03:00
Brian J. Cardiff 3e099e9afc Support upcoming Crystal 0.25.0
The changes are compatible with crystal 0.24.2
2018-05-23 13:29:27 +03:00
Vitalii Elenhaupt 1cea21b147
Do not report float numbers as large if fraction has less than 3 digits 2018-05-13 19:04:15 +03:00
Vitalii Elenhaupt 7a4fcec5ce
Prefer Tuple over Array to format a message to reduce GC 2018-05-13 14:59:30 +03:00
Vitalii Elenhaupt 402a0c0dab
Unused argument name suggession 2018-05-13 14:13:57 +03:00
Vitalii Elenhaupt bf907ee98b
Rework variable references detection in macro 2018-05-12 20:08:24 +03:00
Vitalii Elenhaupt efe67212b0
Support of Crystal::UnitializedVar 2018-05-12 18:29:31 +03:00
Vitalii Elenhaupt 415432713a
Prevent false positiveness cause by macro literals
https://github.com/crystal-lang/crystal/pull/6055#issuecomment-386376227
2018-05-12 17:37:54 +03:00
Vitalii Elenhaupt 6579c8f573
Ignore config if todo formatter is used
Fixes #53
2018-05-11 21:39:09 +03:00
Vitalii Elenhaupt 4546b90b54 Add JSON formatter 2018-05-11 21:28:30 +03:00
Vitalii Elenhaupt fa7f5c5b28
Support Crystal <= 0.24.2 2018-05-09 12:53:01 +03:00
Vitalii Elenhaupt 1fc0c525bd
Do not report unneeded disable directive if directive is used one line above 2018-05-09 00:14:46 +03:00
Vitalii Elenhaupt c7fc905413
Mark the internal visitor class as private 2018-05-08 22:23:01 +03:00
Vitalii Elenhaupt eab5499f8e
Add a workaround for https://github.com/crystal-lang/crystal/pull/6032 2018-05-08 22:18:15 +03:00
V. Elenhaupt c2aa526e21
Unused argument rule (#52)
* Unused argument rule

* IgnoreDefs, IgnoreBlocks, IgnoreProcs parameters

* Implicit reference by super keyworkd

* Handle macro arguments
2018-05-08 22:00:17 +03:00
Vitalii Elenhaupt cc71511080
Use Var#special_var? to check if var is special 2018-05-04 16:25:44 +03:00
V. Elenhaupt 6475c2bb25
Variable scope & useless assignments (#41)
* AST::Visitor -> AST::NodeVisitor

* Scope & ScopeVisitor

* Useless assignment rule

* Instance vars and useless assignments

* Multiple assigns one by one

* Support outer scope

* Variable used in the useless assignment

* Support OpAssign & MultiAssign

* Captured by block

* Variable, Assignment, Reference & Refactoring

* Variable has references, Assignment can be referenced

* Branch entity

* Handle useless assignments in branches

* Handle assignments in a loop

* Handle branch equality

* Handle special var `$?` assignment

* Improve captured by block stuff

* Avoid assignments in property definitions

(UselessAssign rule reports an warning)

* Support MacroIf and MacroFor branches

* Handle assignments with shadowed vars in inner scopes

* Add method arguments as scope variables

* Handle case if branch is blank

* Top level scope

* Handle case when branch is nop?
2018-05-03 18:57:47 +03:00
V. Elenhaupt 60c1b86890
Constantize string error messages (#50) 2018-04-17 07:29:43 +03:00
Vitalii Elenhaupt d307f01bfa
Add a space delimiter to duplicated hash keys 2018-04-13 20:10:21 +03:00
Hugo Abonizio 21a3850a65 Ignore alternative names starting with `_` 2018-04-12 19:20:41 +03:00
Hugo Abonizio d6c6af883d Ignores PredicateName if alternative isn't valid (e.g. is_404?) 2018-04-12 19:20:41 +03:00
Vitalii Elenhaupt 9e2ab9c002
Show hash duplicated keys in error message
closes #45
2018-04-12 19:18:33 +03:00
Vitalii Elenhaupt 2f837375ec New rule: rand zero 2018-03-08 18:59:20 +02:00
Vitalii Elenhaupt eda5960b0f Check for unneeded directives when all other rules are done 2018-02-02 22:17:04 +02:00
Vitalii Elenhaupt 6fb483a2dd Prevent disabling of UnneededDisableDirective rule 2018-02-02 22:17:04 +02:00
Vitalii Elenhaupt 8075c39aa9 Unneeded disable directive 2018-02-02 22:17:04 +02:00
Vitalii Elenhaupt 2382657e15
Add rule's name to flycheck formatter 2018-01-31 13:30:59 +02:00
Vitalii Elenhaupt 69cff77970 Add DisabledFormatter to trace disabled lines 2018-01-30 16:09:00 +02:00
Vitalii Elenhaupt 9f85b16e09 Add inline directives parsing and disabling 2018-01-30 16:09:00 +02:00
Vitalii Elenhaupt 55b66e7975 Use more natural way to define error with custom loc 2018-01-30 16:09:00 +02:00
Vitalii Elenhaupt 1d436fbb94
Allow to configure formatter via configuration file
closes #20
2018-01-25 16:53:08 +02:00
Vitalii Elenhaupt 4c85ad7c75 Syntax rule running priorities 2018-01-25 12:37:25 +02:00
Vitalii Elenhaupt c9db63bf34 Syntax rule 2018-01-25 12:37:25 +02:00
Vitalii Elenhaupt ca502754b6
Allow to inspect a directory 2018-01-24 14:02:18 +02:00
Vitalii Elenhaupt 51fa9f024b
Much simpler way to build todo yaml
https://stackoverflow.com/a/39906916/1586762

thx @asterite 🎉
2017-12-29 12:11:38 +02:00
Vitalii Elenhaupt 7e8703dda0 Crystal 0.24.1 support 2017-12-26 18:21:21 +02:00
Vitalii Elenhaupt eca0d28692
Excluded relative path path 2017-12-18 13:06:19 +02:00
Vitalii Elenhaupt b515faff87 Add cmd specs 2017-12-11 11:19:56 +02:00
Vitalii Elenhaupt e1fa8677b0 Add flycheck formatter
refs #26
2017-12-11 11:19:56 +02:00
V. Elenhaupt f12a224dad
New rule: shadowed exception (#25) 2017-12-06 16:59:10 +02:00
Vitalii Elenhaupt 96c1af4e35
New rule: useless condition in when
thanks to @hugoabonizio for suggesstion
2017-12-02 21:55:50 +02:00
Vitalii Elenhaupt 8bf5066d6a Add Excluded property to the rule 2017-12-01 19:01:25 +02:00
Vitalii Elenhaupt a1854c0aa3 TODO formatter 2017-12-01 19:01:25 +02:00
Vitalii Elenhaupt bc552d0730 Generate config
closes #17
2017-12-01 19:01:25 +02:00
Vitalii Elenhaupt db815a2e30
Fix error message 2017-12-01 00:03:05 +02:00
Luis Lavena 27384ed889 Recognize individual files to process from CLI (#23)
Recent refactor of code introduced a regression: provide individual
files to CLI resulted in all *.cr files being processed instead, so
given file was ignored.

This change restores the original behavior that allows more fine
grained execution.
2017-11-29 10:52:40 +02:00
Hugo Abonizio b023ae0baa Disallows `while true` (#22)
* Disallows `while true`

* Add syntax highlighting in documentation

* Replace `while true` occurrencies

* Add WhileTrue rule to config sample
2017-11-27 15:35:15 +02:00
Vitalii Elenhaupt 21abce63bd
Report only wrong predicate names 2017-11-23 19:58:59 +02:00
Vitalii Elenhaupt dceafd26e5
Except & only cli flags 2017-11-23 19:49:45 +02:00
Vitalii Elenhaupt 34707903b8
Fix nodoc 2017-11-23 10:54:56 +02:00
Vitalii Elenhaupt f4f401d56f
Make config loading more flexible 2017-11-23 10:41:22 +02:00
Vitalii Elenhaupt b5c9f4dff6
Fix mistakes/typos 2017-11-19 13:31:20 +02:00
Vitalii Elenhaupt 0520774930
New rule: duplicated when 2017-11-18 18:39:45 +02:00
Vitalii Elenhaupt 1839ef2ab5
New rule: hash duplicated key 2017-11-18 00:51:16 +02:00
Vitalii Elenhaupt 791bfdabb8
New rule: percent arrays 2017-11-17 23:56:52 +02:00
Vitalii Elenhaupt 0f25b50a57
Add missing YAML sample 2017-11-17 19:34:01 +02:00
Vitalii Elenhaupt 3c9df13beb
New option: LargeNumbers#int_min_digits (default: 5) 2017-11-17 19:07:39 +02:00
Vitalii Elenhaupt b3a9ff2fa0
Mark `begin; end` as empty expression 2017-11-17 18:32:40 +02:00
Vitalii Elenhaupt fb398b5056
New rule: redundant begin 2017-11-17 18:15:11 +02:00
Vitalii Elenhaupt e5081fa970
New rule: empty ensure 2017-11-16 16:31:32 +02:00
Vitalii Elenhaupt 57b1095c5f
Document entities 2017-11-15 23:37:16 +02:00
Vitalii Elenhaupt 198d024782
v0.2.0 2017-11-14 19:40:42 +02:00
Vitalii Elenhaupt 8f4def5407
Load default config if no cli args specified 2017-11-14 11:48:06 +02:00
Vitalii Elenhaupt 06855816d7
Document configuration properties & specs 2017-11-14 10:28:26 +02:00
Vitalii Elenhaupt 822a69b81c
Base YAML config loader & Ameba runner 2017-11-14 09:00:15 +02:00
Vitalii Elenhaupt 80e2ab4f55
Ameba::Rule -> Ameba::Rule::Base 2017-11-08 00:02:32 +02:00
Vitalii Elenhaupt b6c0d3e8ad
Refactor comparison to boolean rule 2017-11-07 23:40:06 +02:00
Vitalii Elenhaupt e718c90f16
Source#content -> Source#code, Source::Error#pos -> Source::Error#location 2017-11-07 23:02:38 +02:00
Vitalii Elenhaupt 9036a7ca71
New rule: empty assignment 2017-11-07 20:54:28 +02:00
Vitalii Elenhaupt a9421ee79b
AST node source code 2017-11-07 13:28:33 +02:00
V. Elenhaupt adfe654733
Performance improvements (#15)
* Performance improvements

Two main changes:

1. Cache parsed AST in a Source. So Parser will parse content only once.
2. Use one unified visitor with multiple callbacks instead of multiple
visitors to traverse AST.

This improves performance significantly, for example running it on
Crystal repository takes ~1 second, which 6 times faster than before.

* Change readme example
2017-11-06 20:54:58 +02:00
Vitalii Elenhaupt f878ac430f
Refactor formatters 2017-11-06 10:41:03 +02:00
Vitalii Elenhaupt 1a3bb3629e
Line lenght: 80 symbols 2017-11-06 08:54:59 +02:00
V. Elenhaupt 374956f3dd
Fix travis build & new rule: constant names (#14) 2017-11-05 22:08:01 +02:00
Vitalii Elenhaupt 8440747353
New rule: variable names 2017-11-04 23:13:38 +02:00
Vitalii Elenhaupt 3d4c44c333
New rule: method names 2017-11-04 22:54:27 +02:00
Vitalii Elenhaupt 20fd53682f
New rule: type names 2017-11-04 18:57:35 +02:00
Vitalii Elenhaupt e383ec17c2
Refactor tokenizer 2017-11-04 17:38:04 +02:00
Vitalii Elenhaupt fedc29ceb6
Remove crystal syntax highliting 2017-11-04 16:49:50 +02:00
V. Elenhaupt 2f9ba27811
Large numbers rule + tokenizer (#10) 2017-11-04 16:43:40 +02:00
Vitalii Elenhaupt 75ec695a62
Colorize dot formatter
closes #1
2017-11-01 22:37:21 +02:00
Vitalii Elenhaupt 67506fc643
New rule: negated conditions in unless 2017-11-01 21:30:30 +02:00
Vitalii Elenhaupt 996dc962db
Style improvements 2017-11-01 19:30:08 +02:00
Vitalii Elenhaupt 0ca990dd5c
New rule: predicate name 2017-11-01 15:20:04 +02:00