Commit graph

127 commits

Author SHA1 Message Date
fn ⌃ ⌥
01dfcbe76a Add tests for AST::Util#control_exp_code 2021-11-09 11:52:31 -08:00
fn ⌃ ⌥
e7cfe387d6 Autocorrect Stye/RedundantNext and Style/RedundantReturn 2021-11-08 14:07:35 -08: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
Sijawusz Pur Rahnama
a53d44617d Fix newly found issues 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
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
7b3c814914 Fix newly found issues 2021-01-28 01:03:48 +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
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
06852c490b Followup to #185 2021-01-17 13:25:50 +01: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
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
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
db6b54e63c
New rule: Style/IsANil 2020-03-29 19:45:13 +03:00
Brian J. Cardiff
6259e26457 Comply exhaustive case check 2020-03-27 09:25:07 -03: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
4f185db0a2
New rule: SharedVarInSpawn
closes #132
2020-03-25 17:52:20 +02:00
Vitalii Elenhaupt
a5dd07e9e4
New rule: RedundantNext
closes #131
2020-03-24 18:06:01 +02:00
Vitalii Elenhaupt
aff723b682
Incorrectly reporting shadowingOuterLocalVar within macro included
closes #129
2020-02-15 20:49:47 +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
19d9223ec1
Properly detect if scope references a variable 2019-10-27 21:53:07 +02:00
Vitalii Elenhaupt
677c75716f
Typeof scope 2019-10-27 21:22:33 +02: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
94e1d4567a
Properly report performance rules in macros
closes #102
2019-05-05 18:05:08 +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
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
866af184f1
Redundant return (#87) 2018-12-30 09:04:59 +02:00
Vitalii Elenhaupt
60ce034f1b
UnusedArgument: fix crystal upgrade regression 2018-12-12 22:21:33 +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
V. Elenhaupt
cb5f802012
Correctly process record declaration at a top level (#78) 2018-09-07 00:47:02 +03:00
Vitalii Elenhaupt
04c7300964
Handle type declarations in scopes
closes #66
2018-06-23 08:48:13 +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
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
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
Vitalii Elenhaupt
96c1af4e35
New rule: useless condition in when
thanks to @hugoabonizio for suggesstion
2017-12-02 21:55:50 +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
1839ef2ab5
New rule: hash duplicated key 2017-11-18 00:51:16 +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
80e2ab4f55
Ameba::Rule -> Ameba::Rule::Base 2017-11-08 00:02:32 +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
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
20fd53682f
New rule: type names 2017-11-04 18:57:35 +02:00
V. Elenhaupt
2f9ba27811
Large numbers rule + tokenizer (#10) 2017-11-04 16:43:40 +02:00
Vitalii Elenhaupt
0ca990dd5c
New rule: predicate name 2017-11-01 15:20:04 +02:00
Vitalii Elenhaupt
64ccc7448c
New rule: literal in the interpolation 2017-11-01 14:18:28 +02:00
Vitalii Elenhaupt
6a81a648e3
AST Util 2017-11-01 13:13:44 +02:00