improve_your_code 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +139 -0
- data/improve_your_code.gemspec +2 -0
- data/lib/improve_your_code/ast/node.rb +1 -5
- data/lib/improve_your_code/context_builder.rb +9 -10
- data/lib/improve_your_code/examiner.rb +1 -1
- data/lib/improve_your_code/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 310145a7aeff673ad9a5f87923798188595f745f
|
4
|
+
data.tar.gz: c8c74b13fdf446388cfb92fda52653288c3aa76e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99ac7c7d43928b479665369d2c0acddd0dc7e85f2636792a5acf655be891a36212c4db91be73bc75d2ae26acdf44d21e22858e4ef286798d06080b794e5662b6
|
7
|
+
data.tar.gz: f8011006e1980fb6ccc570ab1000ac1a558a6585ec84db5ab9ab67cd0ef5e3107c2ae398b9e54639675246264723d126531c18396442ab792fa164da4d4dfd9d
|
data/README.md
CHANGED
@@ -0,0 +1,139 @@
|
|
1
|
+
# Improve Your Code
|
2
|
+
|
3
|
+
## Code smell detector for Ruby
|
4
|
+
|
5
|
+
**Table of Contents**
|
6
|
+
|
7
|
+
- [Quickstart](#quickstart)
|
8
|
+
- [Example](#example)
|
9
|
+
- [Fixing Smell Warnings](#fixing-smell-warnings)
|
10
|
+
|
11
|
+
## Quickstart
|
12
|
+
|
13
|
+
ImproveYourCode is a tool that examines Ruby classes, modules and methods and reports any.
|
14
|
+
|
15
|
+
Install it via rubygems:
|
16
|
+
|
17
|
+
```Bash
|
18
|
+
gem install improve_your_code
|
19
|
+
```
|
20
|
+
|
21
|
+
and run it like this:
|
22
|
+
|
23
|
+
```Bash
|
24
|
+
improve_your_code
|
25
|
+
```
|
26
|
+
|
27
|
+
## Example
|
28
|
+
|
29
|
+
Imagine a source file `main.rb` containing:
|
30
|
+
|
31
|
+
```Ruby
|
32
|
+
module A
|
33
|
+
# UncommunicativeModuleName: A has the name 'A'
|
34
|
+
|
35
|
+
class Main
|
36
|
+
|
37
|
+
# TooManyConstants: Main has 4 constants
|
38
|
+
# TooManyMethods: Main Your class has 8 methods. We propose to use
|
39
|
+
# ExtractClass Pattern
|
40
|
+
|
41
|
+
# TooManyInstanceVariables: Main has at least 4 instance variables.
|
42
|
+
# We propose to use Facade Pattern
|
43
|
+
|
44
|
+
FIRST = 1
|
45
|
+
SECOND = 2
|
46
|
+
THIRD = 3
|
47
|
+
FOURTH = 4
|
48
|
+
|
49
|
+
# LongParameterList: initialize has 4 parameters.
|
50
|
+
# We propose to use Builder Pattern
|
51
|
+
|
52
|
+
def initialize(first, second, third, fourth)
|
53
|
+
@first = first
|
54
|
+
@second = second
|
55
|
+
@third = third
|
56
|
+
@fourth = fourth
|
57
|
+
end
|
58
|
+
|
59
|
+
def first
|
60
|
+
# TooManyStatements: first Your method has 6 statements.
|
61
|
+
# We propose to use ExtractMethod Pattern
|
62
|
+
|
63
|
+
# UncommunicativeVariableName: first has the variable name 'a'
|
64
|
+
|
65
|
+
a = 1
|
66
|
+
b = 2
|
67
|
+
c = 3
|
68
|
+
d = 4
|
69
|
+
e = 5
|
70
|
+
f = 6
|
71
|
+
end
|
72
|
+
|
73
|
+
def second
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def third
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
def fourth
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def fifth
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
def a(a)
|
90
|
+
# UnusedParameters: a has unused parameter 'a'
|
91
|
+
|
92
|
+
b = 1
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def b
|
98
|
+
# UnusedPrivateMethod: Main has the unused private instance
|
99
|
+
# method 'b'
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
ImproveYourCode will report the following code smells in this file:
|
107
|
+
|
108
|
+
```
|
109
|
+
$ improve_your_code
|
110
|
+
|
111
|
+
W
|
112
|
+
|
113
|
+
main.rb -- 17 warnings:
|
114
|
+
[8]:LongParameterList: initialize has 4 parameters. We propose to use Builder Pattern.
|
115
|
+
[2]:TooManyConstants: Main has 4 constants
|
116
|
+
[2]:TooManyInstanceVariables: Main has at least 4 instance variables. We propose to use Facade Pattern
|
117
|
+
[2]:TooManyMethods: Main Your class has 8 methods. We propose to use ExtractClass Pattern
|
118
|
+
[15]:TooManyStatements: first Your method has 6 statements. We propose to use ExtractMethod Pattern
|
119
|
+
[40]:UncommunicativeMethodName: a has the name 'a'
|
120
|
+
[46]:UncommunicativeMethodName: b has the name 'b'
|
121
|
+
[1]:UncommunicativeModuleName: A has the name 'A'
|
122
|
+
[41]:UncommunicativeVariableName: a has the variable name 'b'
|
123
|
+
[16]:UncommunicativeVariableName: first has the variable name 'a'
|
124
|
+
[17]:UncommunicativeVariableName: first has the variable name 'b'
|
125
|
+
[18]:UncommunicativeVariableName: first has the variable name 'c'
|
126
|
+
[19]:UncommunicativeVariableName: first has the variable name 'd'
|
127
|
+
[20]:UncommunicativeVariableName: first has the variable name 'e'
|
128
|
+
[21]:UncommunicativeVariableName: first has the variable name 'f'
|
129
|
+
[40]:UnusedParameters: a has unused parameter 'a'
|
130
|
+
[46]:UnusedPrivateMethod: Main has the unused private instance method 'b'
|
131
|
+
17 total warnings
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
## Fixing Smell Warnings
|
136
|
+
|
137
|
+
ImproveYourCode focuses on high-level code smells, so we can't tell you how to fix warnings in
|
138
|
+
a generic fashion; this is and will always be completely dependent on your domain
|
139
|
+
language and business logic.
|
data/improve_your_code.gemspec
CHANGED
@@ -7,6 +7,8 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = ImproveYourCode::Version::STRING
|
8
8
|
|
9
9
|
s.authors = ['Ilya Umanets']
|
10
|
+
s.email = 'ilya.umanets.web@gmail.com'
|
11
|
+
s.homepage = 'https://github.com/IlyaUmanets/improve_your_code'
|
10
12
|
s.default_executable = 'improve_your_code'
|
11
13
|
s.description =
|
12
14
|
'ImproveYourCode is a tool that examines Ruby classes, modules and methods and reports ' \
|
@@ -54,11 +54,7 @@ module ImproveYourCode
|
|
54
54
|
def format_to_ruby
|
55
55
|
if location
|
56
56
|
lines = location.expression.source.split("\n").map(&:strip)
|
57
|
-
|
58
|
-
when 1 then lines.first
|
59
|
-
when 2 then lines.join('; ')
|
60
|
-
else [lines.first, lines.last].join(' ... ')
|
61
|
-
end
|
57
|
+
lines.first
|
62
58
|
else
|
63
59
|
to_s
|
64
60
|
end
|
@@ -11,20 +11,14 @@ require_relative 'ast/node'
|
|
11
11
|
|
12
12
|
module ImproveYourCode
|
13
13
|
class ContextBuilder
|
14
|
-
attr_reader :
|
14
|
+
attr_reader :syntax_tree
|
15
15
|
|
16
16
|
def initialize(syntax_tree)
|
17
|
-
@
|
18
|
-
@current_context = Context::RootContext.new(
|
19
|
-
@context_tree = build(exp)
|
17
|
+
@syntax_tree = syntax_tree
|
18
|
+
@current_context = Context::RootContext.new(syntax_tree)
|
20
19
|
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
attr_accessor :current_context
|
25
|
-
attr_reader :exp
|
26
|
-
|
27
|
-
def build(exp, parent_exp = nil)
|
21
|
+
def build(exp = syntax_tree, parent_exp = nil)
|
28
22
|
context_processor = "process_#{exp.type}"
|
29
23
|
|
30
24
|
if context_processor_exists?(context_processor)
|
@@ -32,9 +26,14 @@ module ImproveYourCode
|
|
32
26
|
else
|
33
27
|
process exp
|
34
28
|
end
|
29
|
+
|
35
30
|
current_context
|
36
31
|
end
|
37
32
|
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_accessor :current_context
|
36
|
+
|
38
37
|
def process(exp)
|
39
38
|
exp.children.grep(AST::Node).each { |child| build(child, exp) }
|
40
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: improve_your_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Umanets
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
version: '2.0'
|
47
47
|
description: ImproveYourCode is a tool that examines Ruby classes, modules and methods
|
48
48
|
and reports any code smells it finds.
|
49
|
-
email:
|
49
|
+
email: ilya.umanets.web@gmail.com
|
50
50
|
executables:
|
51
51
|
- improve_your_code
|
52
52
|
extensions: []
|
@@ -115,7 +115,7 @@ files:
|
|
115
115
|
- lib/improve_your_code/source/source_locator.rb
|
116
116
|
- lib/improve_your_code/tree_dresser.rb
|
117
117
|
- lib/improve_your_code/version.rb
|
118
|
-
homepage:
|
118
|
+
homepage: https://github.com/IlyaUmanets/improve_your_code
|
119
119
|
licenses: []
|
120
120
|
metadata: {}
|
121
121
|
post_install_message:
|