jscop 0.1.4 → 0.1.5
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/.rubocop.yml +1 -1
- data/.stickler.yml +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -3
- data/README.md +1 -1
- data/exe/jscop +3 -2
- data/lib/jscop/spacing_checker.rb +56 -12
- data/lib/jscop/unused_var_checker.rb +21 -7
- data/lib/jscop/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef2c93999ac0dec33666d5f5cb59a61c9ca9943212a6aba06a52aaafcccb3078
|
4
|
+
data.tar.gz: e2f2addb2e82e2f8d1d141f35898de484bf2356636a4cf603bce84797fa7a0e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0df7a44e87f2d82c994bcf3cfa5f21eafdcc8160413615b886d01934c27d03fff0bd427ccf1969b7ee48d15a08f87ddeb54c6a4cb3024fd774e0a083d6517e70
|
7
|
+
data.tar.gz: 815f17057bdf68f33c3f7b15a814d73bb249418ad419532f54bdddbc3689110b565d331a9afd373e5dc4e4d2e5922536ad00fd5de65139849507caf50a5c7e24
|
data/.rubocop.yml
CHANGED
data/.stickler.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
jscop (0.1.
|
4
|
+
jscop (0.1.5)
|
5
5
|
colorize (~> 0.8)
|
6
6
|
tty-font (~> 0.5)
|
7
7
|
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
parser (2.7.1.1)
|
17
17
|
ast (~> 2.4.0)
|
18
18
|
rainbow (3.0.0)
|
19
|
-
rake (12.3.
|
19
|
+
rake (12.3.3)
|
20
20
|
rexml (3.2.4)
|
21
21
|
rspec (3.9.0)
|
22
22
|
rspec-core (~> 3.9.0)
|
@@ -50,7 +50,7 @@ DEPENDENCIES
|
|
50
50
|
bundler (~> 1.17)
|
51
51
|
colorize (~> 0.8.1)
|
52
52
|
jscop!
|
53
|
-
rake (~> 12.3)
|
53
|
+
rake (~> 12.3.3)
|
54
54
|
rspec
|
55
55
|
rubocop
|
56
56
|
tty-font (~> 0.5.0)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[](https://badge.fury.io/rb/jscop) [](https://repl.it/github/codecell/js-companion)
|
1
|
+
[](https://badge.fury.io/rb/jscop) [](https://travis-ci.org/codecell/jscop) [](https://repl.it/github/codecell/js-companion)
|
2
2
|
|
3
3
|
# Jscop
|
4
4
|
|
data/exe/jscop
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require 'jscop/version'
|
3
|
-
require_relative '../lib/helpers/lint_ware'
|
4
2
|
require 'tty-font'
|
5
3
|
require 'colorize'
|
6
4
|
|
5
|
+
require 'jscop/version'
|
6
|
+
require_relative '../lib/helpers/lint_ware'
|
7
|
+
|
7
8
|
def show_title
|
8
9
|
font = TTY::Font.new
|
9
10
|
font_messge = font.write('Jscop', letter_spacing: 1)
|
@@ -15,27 +15,71 @@ module SpacingChecker
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.found_spaces(cont)
|
18
|
-
|
19
|
-
|
20
|
-
spaced_console = /[\s]+(function|(console.log)[\(][\w]*[\)])[\s]*/
|
21
|
-
closing_line = /[\s]+[\}][\s]*/
|
18
|
+
/(?<lhs>\w+[\W]*)\s{2,}(?<rhs>\w+[\W]*)/ =~ cont
|
19
|
+
vsf = !Regexp.last_match.nil?
|
22
20
|
|
21
|
+
/(?<lhs>\w+\W*)\s{2,}=\s*(?<rhs>\w+\W*)/ =~ cont
|
22
|
+
beq = !Regexp.last_match.nil?
|
23
|
+
|
24
|
+
/(?<lhs>\w+\W*)\s*=\s{2,}(?<rhs>\w+\W*)/ =~ cont
|
25
|
+
aeq = !Regexp.last_match.nil?
|
26
|
+
|
27
|
+
spaced_console = /(console.log)[\s+][\(][\w\W]+[\)]/
|
28
|
+
spc = spaced_console.match?(cont)
|
23
29
|
commented_line = cont.match?(%r{^\W+[\/\/]})
|
24
30
|
|
25
|
-
|
26
|
-
|
27
|
-
|
31
|
+
!commented_line && (vsf || beq || aeq || spc)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.closing_curly_spacing(cont)
|
35
|
+
spaced_closing_curly = /[\s]+[\}][\s]*/
|
36
|
+
c = spaced_closing_curly.match(cont)
|
37
|
+
|
38
|
+
commented_line = cont.match?(%r{^\W+[\/\/]})
|
39
|
+
|
40
|
+
c && !commented_line
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.closed_curly(cont)
|
44
|
+
cont.match?(/}/)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.open_curly(cont)
|
48
|
+
cont.match?(/{/)
|
49
|
+
end
|
28
50
|
|
29
|
-
|
51
|
+
def self.line_beginining_spaces(line)
|
52
|
+
/^[\s+][\w\W]*/.match?(line)
|
30
53
|
end
|
31
54
|
|
32
55
|
def self.check_spaces(file)
|
56
|
+
seen_open = false
|
57
|
+
counter = 0
|
33
58
|
lines_with_spaces = []
|
34
|
-
|
35
|
-
|
36
|
-
|
59
|
+
|
60
|
+
opening_tracker = 0
|
61
|
+
closing_tracker = 0
|
62
|
+
|
63
|
+
arr = file.lines
|
37
64
|
err_type = 'SPACING_ERR'
|
38
|
-
|
65
|
+
|
66
|
+
while counter < arr.length
|
67
|
+
line = arr[counter]
|
68
|
+
|
69
|
+
seen_open = true if open_curly(line.content)
|
70
|
+
|
71
|
+
opening_tracker += 1 if line.content.match?(/{/)
|
72
|
+
closing_tracker += 1 if line.content.match?(/}/)
|
73
|
+
|
74
|
+
lines_with_spaces << line.number if line_beginining_spaces(line.content) unless seen_open
|
75
|
+
opt = (opening_tracker == closing_tracker)
|
76
|
+
seen_open = false if closed_curly(line.content) && opt
|
77
|
+
|
78
|
+
lines_with_spaces << line.number if closing_curly_spacing(line.content) && opt
|
79
|
+
lines_with_spaces << line.number if found_spaces(line.content) && !lines_with_spaces.nil?
|
80
|
+
|
81
|
+
counter += 1
|
82
|
+
end
|
39
83
|
|
40
84
|
lines_with_spaces.each { |line| raise_err(line, err_type, file.filename) if !lines_with_spaces.empty? }
|
41
85
|
end
|
@@ -14,6 +14,15 @@ module UnusedVarChecker
|
|
14
14
|
unused_var_err
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.check_escapable(elem)
|
18
|
+
escapables = [
|
19
|
+
'', 'var', 'let', 'const', 'constructor', 'class', 'super', 'function', 'static', 'console',
|
20
|
+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
21
|
+
]
|
22
|
+
|
23
|
+
escapables.include?(elem)
|
24
|
+
end
|
25
|
+
|
17
26
|
def self.extract_from_parentesis(expresn)
|
18
27
|
/([\(][\w\W]+[\)])/ =~ expresn
|
19
28
|
vars_match_data = Regexp.last_match
|
@@ -33,8 +42,15 @@ module UnusedVarChecker
|
|
33
42
|
# rubocop:disable Lint/UselessAssignment
|
34
43
|
def self.match_variable(contents)
|
35
44
|
/(?<lhs>\w+)\s*=\s*(?<rhs>\w*\W*)/ =~ contents
|
45
|
+
equals_var = Regexp.last_match(:lhs)
|
36
46
|
|
37
|
-
lhs
|
47
|
+
/(?<lhs>(let|var|const))\s{1,}(?<rhs>[\w\-]*)/ =~ contents
|
48
|
+
lazy_init_var = Regexp.last_match(:rhs)
|
49
|
+
|
50
|
+
/(?<lhs>\w+)\s*(?<rhs>[\(\w+\)]*)/ =~ contents
|
51
|
+
func_call_var = Regexp.last_match(:lhs)
|
52
|
+
|
53
|
+
equals_var || lazy_init_var || func_call_var
|
38
54
|
end
|
39
55
|
# rubocop:enable Lint/UselessAssignment
|
40
56
|
|
@@ -65,21 +81,19 @@ module UnusedVarChecker
|
|
65
81
|
vars_match_data = vars_match_data if !vars_match_data.nil?
|
66
82
|
vars_match_data_str_arr = vars_match_data.to_s.split
|
67
83
|
|
68
|
-
escapables = ['var', 'let', '', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
69
|
-
|
70
84
|
vars_match_data_str_arr.collect { |var|
|
71
85
|
/([\w\-]+)/ =~ var
|
72
86
|
wanted = Regexp.last_match
|
73
87
|
wanted = wanted.to_s
|
74
88
|
lines_variables_hash[line.number] = wanted if wanted
|
75
|
-
variable_instances << wanted if !
|
89
|
+
variable_instances << wanted if !check_escapable(wanted)
|
76
90
|
}
|
77
91
|
|
78
92
|
commented_line = line.content.to_s.match?(%r{^\W+[\/\/]})
|
79
93
|
|
80
|
-
|
81
|
-
lines_variables_hash[line.number] =
|
82
|
-
variable_instances <<
|
94
|
+
detected_var = match_variable(line.content.to_s) if !commented_line
|
95
|
+
lines_variables_hash[line.number] = detected_var if detected_var
|
96
|
+
variable_instances << detected_var if !check_escapable(detected_var)
|
83
97
|
}
|
84
98
|
|
85
99
|
file.lines.each(&line_check)
|
data/lib/jscop/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jscop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ezaka Alfred
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|