jscop 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +30 -31
- data/lib/jscop/spacing_checker.rb +11 -1
- data/lib/jscop/unused_var_checker.rb +31 -29
- 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: ce8faa818424c673cf2f4c792fe4f8fcb410fe887e55ffd3f0e2290fd3f8025c
|
4
|
+
data.tar.gz: 5ec46eea194d8b6b54f5f4a620aa02f43f2153d1274c560fca7f14c13f9002e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f3d7672d02395f92b52e255232630e547792cdeeda6bc14c8e26029beaaa73688c9c639a2d2227cf5e63c6c3317c643a514748c68cdb43c3065bb266dfa4ad5
|
7
|
+
data.tar.gz: 98529ecc526de9d2591ec195afaec712e47de303531a15d51474f2a122f655c08e4da4e592fe4c042a04fd3456ae330899bb39f2f1d159aec234294b87858669
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Gem Version](https://badge.fury.io/rb/jscop.svg)](https://badge.fury.io/rb/jscop) [![Build Status](https://travis-ci.org/codecell/jscop.svg?branch=development)](https://travis-ci.org/codecell/jscop) [![Run on Repl.it](https://repl.it/badge/github/codecell/
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/jscop.svg)](https://badge.fury.io/rb/jscop) [![Build Status](https://travis-ci.org/codecell/jscop.svg?branch=development)](https://travis-ci.org/codecell/jscop) [![Run on Repl.it](https://repl.it/badge/github/codecell/jscop)](https://repl.it/github/codecell/jscop)
|
2
2
|
|
3
3
|
# Jscop
|
4
4
|
|
@@ -24,23 +24,22 @@ Or install it yourself as:
|
|
24
24
|
- once in desired path in the terminal/console, RUN
|
25
25
|
|
26
26
|
```ruby
|
27
|
-
a. jscop # To lint all *.js files in the current Path.
|
27
|
+
a. jscop # To lint all *.js files in the current $Path.
|
28
28
|
b. jscop ./**/path_to_file.js # To lint JUST a specific file.
|
29
29
|
c. jscop foldername # To lint all *.js files in a specific folder.
|
30
30
|
```
|
31
31
|
|
32
32
|
## Outline
|
33
|
-
- Title, Description, Installation, Usage
|
33
|
+
- Title, Description, Installation, Usage above
|
34
34
|
- Errors currently detectable by jscop
|
35
|
-
-
|
36
|
-
-
|
35
|
+
- Variable naming errors
|
36
|
+
- Class naming errors
|
37
37
|
- Extra or redundant spacing errors
|
38
38
|
- Multiple declaration of classes in a file (class count) errors
|
39
39
|
- Unused variables are detected
|
40
40
|
- Arguments supported to initiate linting
|
41
|
-
- Testing
|
42
|
-
|
43
|
-
- Unit Tests
|
41
|
+
- Testing this repo
|
42
|
+
- Unit tests
|
44
43
|
- Tools used
|
45
44
|
- Code of conduct
|
46
45
|
- Contributing
|
@@ -48,52 +47,52 @@ c. jscop foldername # To lint all *.js files in a specific folder.
|
|
48
47
|
## ERRORS that can currently be detected include
|
49
48
|
|
50
49
|
### VARIABLE NAMING ERRORS
|
51
|
-
- if capital letters or numbers
|
50
|
+
- if capital letters or numbers are used to start a variable name, e.g
|
52
51
|
- `*Bad practice* let 8owngoal = 4 or const Capvar = 9`
|
53
|
-
- `*Good
|
52
|
+
- `*Good practice* let owngoal = 4 or const capVar = 9`
|
54
53
|
|
55
54
|
### CLASS NAME ERRORS
|
56
|
-
- if class names begin
|
57
|
-
- if class names
|
55
|
+
- if class names begin with small letters and/or
|
56
|
+
- if class names are snake-cased or both e.g
|
58
57
|
- `*Bad practice* class badclass {} or class Bad-class {}`
|
59
|
-
- `*Good
|
58
|
+
- `*Good practice* class GoodClass {} or class Good_Class {}`
|
60
59
|
- Or if underscores and hyphen are mixed
|
61
60
|
`*Bad practice* class Bad_class-Name {}`
|
62
61
|
|
63
62
|
### SPACING ERRORS
|
64
|
-
- if
|
63
|
+
- if spaces are found at beginning of lines
|
65
64
|
- if extra spaces are found around variables e.g
|
66
|
-
- `*Bad practice* let| |
|
67
|
-
- `*Good
|
65
|
+
- `*Bad practice* let| | vacuum = 4 or var hollow| | = 9`
|
66
|
+
- `*Good practice* let vacuum = 4 or const hollow = 9`
|
68
67
|
|
69
68
|
### CLASS COUNT ERROR
|
70
|
-
- if more than one class is defined in a
|
69
|
+
- if more than one class is defined in a module,
|
71
70
|
|
72
71
|
### UNUSED VARIABLE ERROR
|
73
72
|
- if a variable (var, let, const) is defined and never used.
|
74
|
-
- A lot of edge cases
|
73
|
+
- A lot of edge cases are covered here.
|
75
74
|
|
76
|
-
## Arguments Supported By
|
75
|
+
## Arguments Supported By jscop to Check Javascript Code
|
77
76
|
- 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
|
77
|
+
- `You can pass in a specific file $Path to test just the file`
|
78
|
+
- `You can pass in a folder and all javascript files in it will be checked and finally`
|
79
|
+
- `Everything Js can be linted all at once (both files and folders)`
|
81
80
|
|
82
81
|
## Testing This Repo
|
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
|
82
|
+
- Once in the $Path you intend to keep this project in the terminal of your machine
|
83
|
+
- Clone with this command `git clone [repo](https://github.com/codecell/jscop.git)`
|
84
|
+
- Change directory into the folder `cd jscop`
|
85
|
+
- Install project dependencies with the command `bundle install`
|
86
|
+
- You can make the `exe/jscop` file executable with the command `chmod a+x exe/jscop` if permission is not granted
|
88
87
|
|
89
88
|
## Unit Tests
|
90
|
-
- Ensure you have `rspec` installed, or ensure
|
91
|
-
-
|
89
|
+
- Ensure you have `rspec` installed, or ensure that `gem rspec` is listed among the gems in the `Gemfile` => then run `bundle install`
|
90
|
+
- In the console, run `rspec` or `rake` to run all the unit tests written for this project
|
92
91
|
|
93
92
|
## Built With
|
94
93
|
- Ruby
|
95
|
-
- [Rubular](https://rubular.com/)
|
96
|
-
- Rubocop
|
94
|
+
- [Rubular](https://rubular.com/) was used to craft and test the regular expressions
|
95
|
+
- Rubocop linter
|
97
96
|
- Stickler CI
|
98
97
|
|
99
98
|
## Contributing
|
@@ -31,6 +31,15 @@ module SpacingChecker
|
|
31
31
|
!commented_line && (vsf || beq || aeq || spc)
|
32
32
|
end
|
33
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
|
+
|
34
43
|
def self.closing_curly_spacing(cont)
|
35
44
|
spaced_closing_curly = /[\s]+[\}][\s]*/
|
36
45
|
c = spaced_closing_curly.match(cont)
|
@@ -69,7 +78,7 @@ module SpacingChecker
|
|
69
78
|
seen_open = true if open_curly(line.content)
|
70
79
|
|
71
80
|
opening_tracker += 1 if line.content.match?(/{/)
|
72
|
-
closing_tracker += 1 if line.content.match?(/}/)
|
81
|
+
closing_tracker += 1 if line.content.match?(/}/) && !line.content.match?(/[\}][\s]*[\)]/)
|
73
82
|
|
74
83
|
lines_with_spaces << line.number if line_beginining_spaces(line.content) unless seen_open
|
75
84
|
opt = (opening_tracker == closing_tracker)
|
@@ -77,6 +86,7 @@ module SpacingChecker
|
|
77
86
|
|
78
87
|
lines_with_spaces << line.number if closing_curly_spacing(line.content) && opt
|
79
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)
|
80
90
|
|
81
91
|
counter += 1
|
82
92
|
end
|
@@ -17,29 +17,38 @@ module UnusedVarChecker
|
|
17
17
|
def self.check_escapable(elem)
|
18
18
|
escapables = [
|
19
19
|
'', 'var', 'let', 'const', 'constructor', 'class', 'super', 'function', 'static', 'console',
|
20
|
+
'prototype', 'get', 'set', 'this', 'alert', 'prompt',
|
20
21
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
21
22
|
]
|
22
23
|
|
23
24
|
escapables.include?(elem)
|
24
25
|
end
|
25
26
|
|
26
|
-
def self.
|
27
|
-
/([\(][\w
|
28
|
-
|
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
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
vars_match_data_str_arr.collect { |var|
|
33
|
+
each_var = vars_match_data.collect { |var|
|
33
34
|
/([\w\-]+)/ =~ var
|
34
|
-
wanted = Regexp.last_match
|
35
|
+
wanted = Regexp.last_match(0)
|
35
36
|
wanted = wanted.to_s
|
36
|
-
|
37
|
-
all_params << wanted.to_s if !wanted.empty?
|
37
|
+
wanted
|
38
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
|
39
50
|
end
|
40
|
-
# /(?<lhs>\w+)\s*=\s*(?<rhs>\w+)/ =~ " x = y " <= From: https://ruby-doc.org/core-2.6.4/Regexp.html
|
41
51
|
|
42
|
-
# rubocop:disable Lint/UselessAssignment
|
43
52
|
def self.match_variable(contents)
|
44
53
|
/(?<lhs>\w+)\s*=\s*(?<rhs>\w*\W*)/ =~ contents
|
45
54
|
equals_var = Regexp.last_match(:lhs)
|
@@ -50,9 +59,8 @@ module UnusedVarChecker
|
|
50
59
|
/(?<lhs>\w+)\s*(?<rhs>[\(\w+\)]*)/ =~ contents
|
51
60
|
func_call_var = Regexp.last_match(:lhs)
|
52
61
|
|
53
|
-
|
62
|
+
lazy_init_var || func_call_var || equals_var
|
54
63
|
end
|
55
|
-
# rubocop:enable Lint/UselessAssignment
|
56
64
|
|
57
65
|
def self.create_variables_check_info(count_vs_var, lines_vs_var, filename)
|
58
66
|
err_type = 'UNUSED_VAR_ERR'
|
@@ -75,29 +83,23 @@ module UnusedVarChecker
|
|
75
83
|
lines_variables_hash = {}
|
76
84
|
|
77
85
|
line_check = lambda { |line|
|
78
|
-
/([\(][\w\W]+[\)])/ =~ line.content.to_s
|
79
|
-
vars_match_data = Regexp.last_match
|
80
|
-
|
81
|
-
vars_match_data = vars_match_data if !vars_match_data.nil?
|
82
|
-
vars_match_data_str_arr = vars_match_data.to_s.split
|
83
|
-
|
84
|
-
vars_match_data_str_arr.collect { |var|
|
85
|
-
/([\w\-]+)/ =~ var
|
86
|
-
wanted = Regexp.last_match
|
87
|
-
wanted = wanted.to_s
|
88
|
-
lines_variables_hash[line.number] = wanted if wanted
|
89
|
-
variable_instances << wanted if !check_escapable(wanted)
|
90
|
-
}
|
91
|
-
|
92
86
|
commented_line = line.content.to_s.match?(%r{^\W+[\/\/]})
|
93
87
|
|
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?
|
91
|
+
|
94
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
|
94
|
+
|
95
95
|
lines_variables_hash[line.number] = detected_var if detected_var
|
96
|
-
|
96
|
+
lines_variables_hash[line.number] = detected_accessd_var if detected_accessd_var
|
97
|
+
|
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?
|
97
100
|
}
|
98
101
|
|
99
102
|
file.lines.each(&line_check)
|
100
|
-
|
101
103
|
variable_instances.map { |el|
|
102
104
|
var_instances_count_hash[el] = var_instances_count_hash[el] ? var_instances_count_hash[el] += 1 : 1
|
103
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.6
|
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-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|