jscop 0.1.3 → 0.1.8
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 +3 -1
- data/.stickler.yml +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +59 -0
- data/README.md +47 -46
- data/exe/jscop +3 -2
- data/lib/classes/js_parser.rb +3 -1
- data/lib/jscop/class_count.rb +5 -1
- data/lib/jscop/class_name.rb +3 -1
- data/lib/jscop/naming_checker.rb +3 -1
- data/lib/jscop/spacing_checker.rb +68 -12
- data/lib/jscop/unused_var_checker.rb +46 -30
- data/lib/jscop/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b64419ab3765a43ca858c74dc7e95b2518520c68c3c57d8a24b85e147b2963e
|
4
|
+
data.tar.gz: dc8bb2e1329895ac6a7dbfce27027c5cc6011627dd2d684ef2df9d29943e68bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 345026f8b2c53c1debc6e0ad81230f40fac8a04b098c9383281014724b8212437542ec1d3dbf859898974071c77e3e0f8a9421037ee1356f02723ba55cd1940f
|
7
|
+
data.tar.gz: 5cb920394d53327036d0d378efba2fe4bd5b6d5d12f83ed652df76a6acb11dec4e3df8460efebcb9823f0262d197810e26edb646d7edbe5d7b2908632a5fb5e3
|
data/.rubocop.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
3
|
- "spec/spec_helper.rb"
|
4
|
+
- "lib/jscop/spacing_checker.rb"
|
4
5
|
- "README.md"
|
5
6
|
- "Guardfile"
|
6
7
|
- "Rakefile"
|
7
|
-
- "rof_work.rb"
|
8
8
|
- "vendor/**/*"
|
9
9
|
- "jscop.gemspec"
|
10
10
|
|
@@ -14,6 +14,8 @@ Lint/RaiseException:
|
|
14
14
|
Enabled: false
|
15
15
|
Lint/StructNewOverride:
|
16
16
|
Enabled: false
|
17
|
+
Lint/UselessAssignment:
|
18
|
+
Enabled: false
|
17
19
|
|
18
20
|
Layout/LineLength:
|
19
21
|
Max: 120
|
data/.stickler.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
jscop (0.1.7)
|
5
|
+
colorize (~> 0.8)
|
6
|
+
tty-font (~> 0.5)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.0)
|
12
|
+
colorize (0.8.1)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
jaro_winkler (1.5.4)
|
15
|
+
parallel (1.19.1)
|
16
|
+
parser (2.7.1.2)
|
17
|
+
ast (~> 2.4.0)
|
18
|
+
rainbow (3.0.0)
|
19
|
+
rake (12.3.3)
|
20
|
+
rexml (3.2.4)
|
21
|
+
rspec (3.9.0)
|
22
|
+
rspec-core (~> 3.9.0)
|
23
|
+
rspec-expectations (~> 3.9.0)
|
24
|
+
rspec-mocks (~> 3.9.0)
|
25
|
+
rspec-core (3.9.1)
|
26
|
+
rspec-support (~> 3.9.1)
|
27
|
+
rspec-expectations (3.9.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.9.0)
|
30
|
+
rspec-mocks (3.9.1)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-support (3.9.2)
|
34
|
+
rubocop (0.82.0)
|
35
|
+
jaro_winkler (~> 1.5.1)
|
36
|
+
parallel (~> 1.10)
|
37
|
+
parser (>= 2.7.0.1)
|
38
|
+
rainbow (>= 2.2.2, < 4.0)
|
39
|
+
rexml
|
40
|
+
ruby-progressbar (~> 1.7)
|
41
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
42
|
+
ruby-progressbar (1.10.1)
|
43
|
+
tty-font (0.5.0)
|
44
|
+
unicode-display_width (1.7.0)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler (~> 1.17)
|
51
|
+
colorize (~> 0.8.1)
|
52
|
+
jscop!
|
53
|
+
rake (~> 12.3.3)
|
54
|
+
rspec
|
55
|
+
rubocop
|
56
|
+
tty-font (~> 0.5.0)
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.17.2
|
data/README.md
CHANGED
@@ -1,9 +1,25 @@
|
|
1
|
-
[](https://badge.fury.io/rb/jscop)
|
1
|
+
[](https://badge.fury.io/rb/jscop) [](https://travis-ci.org/codecell/jscop)
|
2
2
|
|
3
3
|
# Jscop
|
4
4
|
|
5
5
|
This is a Linter for checking errors in Javascript code, built with Ruby.
|
6
6
|
|
7
|
+
## Outline
|
8
|
+
- [Installation](#Installation)
|
9
|
+
- [Usage](#Usage)
|
10
|
+
- [Errors currently detectable by jscop](#ERRORS)
|
11
|
+
- Variable naming errors
|
12
|
+
- Class naming errors
|
13
|
+
- Extra or redundant spacing errors
|
14
|
+
- Multiple declaration of classes in a file (class count) errors
|
15
|
+
- Unused variables are detected
|
16
|
+
- [More about usage](#More-About-Usage)
|
17
|
+
- [Testing this repo](#Testing-This-Repo)
|
18
|
+
- [Built With](#Built-With)
|
19
|
+
- [Contributing](#contributing)
|
20
|
+
- [Code of conduct](#Code-of-Conduct)
|
21
|
+
- [Licence](#License)
|
22
|
+
|
7
23
|
## Installation
|
8
24
|
|
9
25
|
Add this line to your application's Gemfile:
|
@@ -24,76 +40,60 @@ Or install it yourself as:
|
|
24
40
|
- once in desired path in the terminal/console, RUN
|
25
41
|
|
26
42
|
```ruby
|
27
|
-
a. jscop # To lint all *.js files in the current Path.
|
43
|
+
a. jscop # To lint all *.js files in the current $Path.
|
28
44
|
b. jscop ./**/path_to_file.js # To lint JUST a specific file.
|
29
45
|
c. jscop foldername # To lint all *.js files in a specific folder.
|
30
46
|
```
|
31
47
|
|
32
|
-
##
|
33
|
-
|
34
|
-
- Errors currently detectable by jscop
|
35
|
-
- variable naming errors
|
36
|
-
- class naming errors
|
37
|
-
- Extra or redundant spacing errors
|
38
|
-
- Multiple declaration of classes in a file (class count) errors
|
39
|
-
- Unused variables are detected
|
40
|
-
- Arguments supported to initiate linting
|
41
|
-
- Testing Javascript files with Js-Companion
|
42
|
-
- cloning Locally to local machine
|
43
|
-
- Unit Tests
|
44
|
-
- Tools used
|
45
|
-
- Code of conduct
|
46
|
-
- Contributing
|
47
|
-
|
48
|
-
## ERRORS that can currently be detected include
|
48
|
+
## ERRORS
|
49
|
+
The following erros are currently detectable by Jscop:
|
49
50
|
|
50
51
|
### VARIABLE NAMING ERRORS
|
51
|
-
- if capital letters or numbers
|
52
|
+
- if capital letters or numbers are used to start a variable name, e.g
|
52
53
|
- `*Bad practice* let 8owngoal = 4 or const Capvar = 9`
|
53
|
-
- `*Good
|
54
|
+
- `*Good practice* let owngoal = 4 or const capVar = 9`
|
54
55
|
|
55
56
|
### CLASS NAME ERRORS
|
56
|
-
- if class names begin
|
57
|
-
- if class names
|
57
|
+
- if class names begin with small letters and/or
|
58
|
+
- if class names are snake-cased or both e.g
|
58
59
|
- `*Bad practice* class badclass {} or class Bad-class {}`
|
59
|
-
- `*Good
|
60
|
+
- `*Good practice* class GoodClass {} or class Good_Class {}`
|
60
61
|
- Or if underscores and hyphen are mixed
|
61
62
|
`*Bad practice* class Bad_class-Name {}`
|
62
63
|
|
63
64
|
### SPACING ERRORS
|
64
|
-
- if
|
65
|
+
- if spaces are found at beginning of lines
|
65
66
|
- if extra spaces are found around variables e.g
|
66
|
-
- `*Bad practice* let| |
|
67
|
-
- `*Good
|
67
|
+
- `*Bad practice* let| | vacuum = 4 or var hollow| | = 9`
|
68
|
+
- `*Good practice* let vacuum = 4 or const hollow = 9`
|
68
69
|
|
69
70
|
### CLASS COUNT ERROR
|
70
|
-
- if more than one class is defined in a
|
71
|
+
- if more than one class is defined in a module,
|
71
72
|
|
72
73
|
### UNUSED VARIABLE ERROR
|
73
74
|
- if a variable (var, let, const) is defined and never used.
|
74
|
-
- A lot of edge cases
|
75
|
+
- A lot of edge cases are covered here.
|
75
76
|
|
76
|
-
##
|
77
|
+
## More About Usage
|
78
|
+
Arguments Supported By jscop to Check Javascript Code
|
77
79
|
- You can pass in file(s) or a folder in any of the following cases in your terminal
|
78
|
-
- `
|
79
|
-
- `You can pass in a
|
80
|
-
- `Everything Js can be linted all at once (both files and
|
81
|
-
|
82
|
-
## Testing
|
83
|
-
- Once in the Path you intend to keep this project in the terminal of your machine
|
84
|
-
- Clone with this command git clone [repo](https://github.com/codecell/jscop.git)
|
85
|
-
-
|
86
|
-
- Install project dependencies with the command bundle install
|
87
|
-
- You can make the exe/jscop executable with the command chmod a+x exe/jscop if permission is not granted
|
88
|
-
|
89
|
-
|
90
|
-
- Ensure you have `rspec` installed, or ensure the `gem 'rspec` is listed among the gems in the `Gemfile` => then run `bundle install`
|
91
|
-
- in your console, run `rspec` or `rake` to run all the unit tests written for this project
|
80
|
+
- `You can pass in a specific file $Path to test just the file`
|
81
|
+
- `You can pass in a folder and all javascript files in it will be checked and finally`
|
82
|
+
- `Everything Js can be linted all at once (both files and folders)`
|
83
|
+
|
84
|
+
## Testing this Repo
|
85
|
+
- Once in the $Path you intend to keep this project in the terminal of your machine
|
86
|
+
- Clone with this command `git clone [repo](https://github.com/codecell/jscop.git)`
|
87
|
+
- Change directory into the folder `cd jscop`
|
88
|
+
- Install project dependencies with the command `bundle install`
|
89
|
+
- You can make the `exe/jscop` file executable with the command `chmod a+x exe/jscop` if permission is not granted
|
90
|
+
- Ensure you have `rspec` installed, or ensure that `gem rspec` is listed among the gems in the `Gemfile` => then run `bundle install`
|
91
|
+
- In the console, run `rspec` or `rake` to run all the unit tests written for this project
|
92
92
|
|
93
93
|
## Built With
|
94
94
|
- Ruby
|
95
|
-
- [Rubular](https://rubular.com/)
|
96
|
-
- Rubocop
|
95
|
+
- [Rubular](https://rubular.com/) was used to craft and test the regular expressions
|
96
|
+
- Rubocop linter
|
97
97
|
- Stickler CI
|
98
98
|
|
99
99
|
## Contributing
|
@@ -111,6 +111,7 @@ Everyone interacting in the Jscop project’s codebases, issue trackers, chat ro
|
|
111
111
|
- Github: [@codecell](https://github.com/codecell)
|
112
112
|
- Twitter: [@the_codecell](https://twitter.com/the_codecell)
|
113
113
|
- Linkedin: [ezaka alfred](https://www.linkedin.com/in/alfrednoble/)
|
114
|
+
|
114
115
|
## License
|
115
116
|
|
116
117
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
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)
|
data/lib/classes/js_parser.rb
CHANGED
@@ -11,10 +11,12 @@ class JsParser
|
|
11
11
|
|
12
12
|
def set_lines
|
13
13
|
file = File.open(@filename)
|
14
|
-
|
15
14
|
all_lines = file.readlines.map(&:chomp)
|
16
15
|
init_lines = lambda { |val, index|
|
17
16
|
line = Line.new(index + 1, val, @filename)
|
17
|
+
config_folders = line.filename.match?(/(node_modules|config|babel)/)
|
18
|
+
next if config_folders
|
19
|
+
|
18
20
|
@lines << line
|
19
21
|
}
|
20
22
|
|
data/lib/jscop/class_count.rb
CHANGED
@@ -16,11 +16,15 @@ module ClassCount
|
|
16
16
|
|
17
17
|
def self.class_count(file)
|
18
18
|
pat = /(class)/
|
19
|
+
commented_line = %r{^\W+[\/\/]}
|
19
20
|
|
20
21
|
lines_with_class = []
|
21
22
|
err_type = 'CLASS_COUNT_ERR'
|
22
23
|
|
23
|
-
file.lines.each { |line|
|
24
|
+
file.lines.each { |line|
|
25
|
+
needed_lines_with_class = pat.match?(line.content) && !line.content.match?(commented_line)
|
26
|
+
lines_with_class << line.number if needed_lines_with_class
|
27
|
+
}
|
24
28
|
raise_err(lines_with_class, err_type, file.filename) if lines_with_class.length > 1
|
25
29
|
|
26
30
|
lines_with_class
|
data/lib/jscop/class_name.rb
CHANGED
@@ -18,7 +18,9 @@ module ClassName
|
|
18
18
|
fes_pat = /[\s]*(class)[\s]*[\d]*[\-]*[a-z]+[\-]*[\w\W]*/
|
19
19
|
sec_pat = /[\s]*(class)[\s]*[\p{Alpha}]+[\-]+[\p{Alpha}]+/
|
20
20
|
|
21
|
-
|
21
|
+
commented_line = crime.match?(%r{^\W+[\/\/]})
|
22
|
+
|
23
|
+
!commented_line && (fes_pat.match?(crime) || sec_pat.match?(crime))
|
22
24
|
end
|
23
25
|
|
24
26
|
def self.check_class_name(file)
|
data/lib/jscop/naming_checker.rb
CHANGED
@@ -16,7 +16,9 @@ module NamingChecker
|
|
16
16
|
|
17
17
|
def self.bad_var_case(bad_case)
|
18
18
|
bad_var_start = /(var|let|const|[\s])[\s]*([[:upper:]]{1,}|\d)+(([\w]+[\s][\w]+)|[\w]+)[\s]*[\=][\s]*[\w]*/
|
19
|
-
|
19
|
+
commented_line = bad_case.match?(%r{^\W+[\/\/]})
|
20
|
+
|
21
|
+
bad_var_start.match?(bad_case) && !commented_line
|
20
22
|
end
|
21
23
|
|
22
24
|
def self.check_naming(fpath)
|
@@ -15,25 +15,81 @@ 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
|
|
23
|
-
|
24
|
-
|
25
|
-
c = spaced_console.match?(cont)
|
21
|
+
/(?<lhs>\w+\W*)\s{2,}=\s*(?<rhs>\w+\W*)/ =~ cont
|
22
|
+
beq = !Regexp.last_match.nil?
|
26
23
|
|
27
|
-
|
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)
|
29
|
+
commented_line = cont.match?(%r{^\W+[\/\/]})
|
30
|
+
|
31
|
+
!commented_line && (vsf || beq || aeq || spc)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.spc_around_fn(cont)
|
35
|
+
around_funcs = /[\)][\s]{2,}[\{]/.match?(cont)
|
36
|
+
around_classes = /[\w+\-*]*[\s]{2,}[\{]/.match?(cont)
|
37
|
+
|
38
|
+
commented_line = cont.match?(%r{^\W+[\/\/]})
|
39
|
+
|
40
|
+
!commented_line && (around_funcs || around_classes)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.closing_curly_spacing(cont)
|
44
|
+
spaced_closing_curly = /[\s]+[\}][\s]*/
|
45
|
+
c = spaced_closing_curly.match(cont)
|
46
|
+
|
47
|
+
commented_line = cont.match?(%r{^\W+[\/\/]})
|
48
|
+
|
49
|
+
c && !commented_line
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.closed_curly(cont)
|
53
|
+
cont.match?(/}/)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.open_curly(cont)
|
57
|
+
cont.match?(/{/)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.line_beginining_spaces(line)
|
61
|
+
/^[\s+][\w\W]*/.match?(line)
|
28
62
|
end
|
29
63
|
|
30
64
|
def self.check_spaces(file)
|
65
|
+
seen_open = false
|
66
|
+
counter = 0
|
31
67
|
lines_with_spaces = []
|
32
|
-
|
33
|
-
|
34
|
-
|
68
|
+
|
69
|
+
opening_tracker = 0
|
70
|
+
closing_tracker = 0
|
71
|
+
|
72
|
+
arr = file.lines
|
35
73
|
err_type = 'SPACING_ERR'
|
36
|
-
|
74
|
+
|
75
|
+
while counter < arr.length
|
76
|
+
line = arr[counter]
|
77
|
+
|
78
|
+
seen_open = true if open_curly(line.content)
|
79
|
+
|
80
|
+
opening_tracker += 1 if line.content.match?(/{/)
|
81
|
+
closing_tracker += 1 if line.content.match?(/}/) && !line.content.match?(/[\}][\s]*[\)]/)
|
82
|
+
|
83
|
+
lines_with_spaces << line.number if line_beginining_spaces(line.content) unless seen_open
|
84
|
+
opt = (opening_tracker == closing_tracker)
|
85
|
+
seen_open = false if closed_curly(line.content) && opt
|
86
|
+
|
87
|
+
lines_with_spaces << line.number if closing_curly_spacing(line.content) && opt
|
88
|
+
lines_with_spaces << line.number if found_spaces(line.content) && !lines_with_spaces.nil?
|
89
|
+
lines_with_spaces << line.number if spc_around_fn(line.content)
|
90
|
+
|
91
|
+
counter += 1
|
92
|
+
end
|
37
93
|
|
38
94
|
lines_with_spaces.each { |line| raise_err(line, err_type, file.filename) if !lines_with_spaces.empty? }
|
39
95
|
end
|
@@ -14,29 +14,53 @@ module UnusedVarChecker
|
|
14
14
|
unused_var_err
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.
|
18
|
-
|
19
|
-
|
17
|
+
def self.check_escapable(elem)
|
18
|
+
escapables = [
|
19
|
+
'', 'var', 'let', 'const', 'constructor', 'class', 'super', 'function', 'static', 'console',
|
20
|
+
'prototype', 'get', 'set', 'this', 'alert', 'prompt', 'return',
|
21
|
+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
22
|
+
]
|
23
|
+
|
24
|
+
escapables.include?(elem)
|
25
|
+
end
|
20
26
|
|
21
|
-
|
27
|
+
def self.vars_parentesis(paramz)
|
28
|
+
/(?<lhs>[\(])(?<rhs>[^\{]*[\w\-]+)/ =~ paramz
|
29
|
+
vars = Regexp.last_match(:rhs)
|
30
|
+
vars = vars.to_s.split if vars
|
31
|
+
vars_match_data = vars.to_s.split
|
22
32
|
|
23
|
-
|
33
|
+
each_var = vars_match_data.collect { |var|
|
24
34
|
/([\w\-]+)/ =~ var
|
25
|
-
wanted = Regexp.last_match
|
35
|
+
wanted = Regexp.last_match(0)
|
26
36
|
wanted = wanted.to_s
|
27
|
-
|
28
|
-
all_params << wanted.to_s if !wanted.empty?
|
37
|
+
wanted
|
29
38
|
}
|
39
|
+
each_var[0] if each_var[0] && !each_var.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.match_accessd_var(vari)
|
43
|
+
/(?<lhs>[\w+\-*]+)[\[](?<rhs>[\w+\-*]+)/ =~ vari
|
44
|
+
sqad = Regexp.last_match(:rhs)
|
45
|
+
|
46
|
+
/(?<lhs>[\w+\-*]+)\.(?<rhs>[\w+\-*]+)/ =~ vari
|
47
|
+
awda = Regexp.last_match(:rhs)
|
48
|
+
|
49
|
+
sqad || awda
|
30
50
|
end
|
31
|
-
# /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ " x = y " <= From: https://ruby-doc.org/core-2.6.4/Regexp.html
|
32
51
|
|
33
|
-
# rubocop:disable Lint/UselessAssignment
|
34
52
|
def self.match_variable(contents)
|
35
53
|
/(?<lhs>\w+)\s*=\s*(?<rhs>\w*\W*)/ =~ contents
|
54
|
+
equals_var = Regexp.last_match(:lhs)
|
55
|
+
|
56
|
+
/(?<lhs>(let|var|const))\s{1,}(?<rhs>[\w\-]*)/ =~ contents
|
57
|
+
lazy_init_var = Regexp.last_match(:rhs)
|
36
58
|
|
37
|
-
lhs
|
59
|
+
/(?<lhs>\w+)\s*(?<rhs>[\(\w+\)]*)/ =~ contents
|
60
|
+
func_call_var = Regexp.last_match(:lhs)
|
61
|
+
|
62
|
+
lazy_init_var || func_call_var || equals_var
|
38
63
|
end
|
39
|
-
# rubocop:enable Lint/UselessAssignment
|
40
64
|
|
41
65
|
def self.create_variables_check_info(count_vs_var, lines_vs_var, filename)
|
42
66
|
err_type = 'UNUSED_VAR_ERR'
|
@@ -59,31 +83,23 @@ module UnusedVarChecker
|
|
59
83
|
lines_variables_hash = {}
|
60
84
|
|
61
85
|
line_check = lambda { |line|
|
62
|
-
|
63
|
-
vars_match_data = Regexp.last_match
|
64
|
-
|
65
|
-
vars_match_data = vars_match_data if !vars_match_data.nil?
|
66
|
-
vars_match_data_str_arr = vars_match_data.to_s.split
|
86
|
+
commented_line = line.content.to_s.match?(%r{^\W+[\/\/]})
|
67
87
|
|
68
|
-
|
88
|
+
from_parentsis = vars_parentesis(line.content.to_s) if !commented_line
|
89
|
+
lines_variables_hash[line.number] = from_parentsis if from_parentsis
|
90
|
+
variable_instances << from_parentsis if !check_escapable(from_parentsis) && !from_parentsis.nil?
|
69
91
|
|
70
|
-
|
71
|
-
|
72
|
-
wanted = Regexp.last_match
|
73
|
-
wanted = wanted.to_s
|
74
|
-
lines_variables_hash[line.number] = wanted if wanted
|
75
|
-
variable_instances << wanted if !escapables.include?(wanted)
|
76
|
-
}
|
92
|
+
detected_var = match_variable(line.content.to_s) if !commented_line
|
93
|
+
detected_accessd_var = match_accessd_var(line.content.to_s) if !commented_line
|
77
94
|
|
78
|
-
|
95
|
+
lines_variables_hash[line.number] = detected_var if detected_var
|
96
|
+
lines_variables_hash[line.number] = detected_accessd_var if detected_accessd_var
|
79
97
|
|
80
|
-
|
81
|
-
|
82
|
-
variable_instances << detected_variable if detected_variable
|
98
|
+
variable_instances << detected_var if !check_escapable(detected_var) && !detected_var.nil?
|
99
|
+
variable_instances << detected_accessd_var if !check_escapable(detected_accessd_var) && !detected_accessd_var.nil?
|
83
100
|
}
|
84
101
|
|
85
102
|
file.lines.each(&line_check)
|
86
|
-
|
87
103
|
variable_instances.map { |el|
|
88
104
|
var_instances_count_hash[el] = var_instances_count_hash[el] ? var_instances_count_hash[el] += 1 : 1
|
89
105
|
}
|
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.8
|
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-
|
11
|
+
date: 2020-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- ".travis.yml"
|
97
97
|
- CODE_OF_CONDUCT.md
|
98
98
|
- Gemfile
|
99
|
+
- Gemfile.lock
|
99
100
|
- LICENSE.txt
|
100
101
|
- README.md
|
101
102
|
- Rakefile
|
@@ -135,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
136
|
- !ruby/object:Gem::Version
|
136
137
|
version: '0'
|
137
138
|
requirements: []
|
138
|
-
rubygems_version: 3.
|
139
|
+
rubygems_version: 3.1.4
|
139
140
|
signing_key:
|
140
141
|
specification_version: 4
|
141
142
|
summary: A linter for checking errors in javascript code
|