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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11a58c121a44379f5c4cf6117db6ae5034eb1ba3ce86ab5c60236ae572808136
4
- data.tar.gz: 43282861b0fb49e9dac054cb014e406d9ce164d0860229209b0ace26d7c1c0ed
3
+ metadata.gz: ef2c93999ac0dec33666d5f5cb59a61c9ca9943212a6aba06a52aaafcccb3078
4
+ data.tar.gz: e2f2addb2e82e2f8d1d141f35898de484bf2356636a4cf603bce84797fa7a0e7
5
5
  SHA512:
6
- metadata.gz: 7296b4d12c6d2796cdb566e322c2bcee6bad26d3e5f0abd6d0ff6191744c56ed5800a47ba0a13b34ee2c59f5410332317acb081c49c0d7aa3fd2e3f12edc8759
7
- data.tar.gz: 777abcca2f151e8bbb955d241447763cc37ce9a1c0987cc7e863f8ab81b82886b6b8c51a975044dca235c27e4c55a34e82d8d227ae696bd5ec2396212bdaa3a2
6
+ metadata.gz: 0df7a44e87f2d82c994bcf3cfa5f21eafdcc8160413615b886d01934c27d03fff0bd427ccf1969b7ee48d15a08f87ddeb54c6a4cb3024fd774e0a083d6517e70
7
+ data.tar.gz: 815f17057bdf68f33c3f7b15a814d73bb249418ad419532f54bdddbc3689110b565d331a9afd373e5dc4e4d2e5922536ad00fd5de65139849507caf50a5c7e24
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
 
data/.stickler.yml CHANGED
@@ -6,9 +6,9 @@ linters:
6
6
  files:
7
7
  ignore:
8
8
  - "Guardfile"
9
+ - "lib/jscop/spacing_checker.rb"
9
10
  - "Rakefile"
10
11
  - "node_modules/**/*"
11
12
  - "spec/spec_helper.rb"
12
- - "rof_work.rb"
13
13
  - "vendor/**/*"
14
14
  - "jscop.gemspec"
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
5
  # Specify your gem's dependencies in jscop.gemspec
6
6
  gemspec
7
7
  gem 'colorize', '~> 0.8.1'
8
+ gem 'rake', '~> 12.3.3'
8
9
  gem 'rspec'
9
10
  gem 'rubocop'
10
11
  gem 'tty-font', '~> 0.5.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jscop (0.1.4)
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.2)
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
- [![Gem Version](https://badge.fury.io/rb/jscop.svg)](https://badge.fury.io/rb/jscop) [![Run on Repl.it](https://repl.it/badge/github/codecell/js-companion)](https://repl.it/github/codecell/js-companion)
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/js-companion)](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
- spaces_before = /[\s]+(const|let|var|function|class|[\}$])[\s]+[\w]*/
19
- spaces_after = /(const|let|var|function|class)[\s]{2,}[\w]+[\s]*[\=]/
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
- a = spaces_before.match?(cont)
26
- b = spaces_after.match?(cont)
27
- c = spaced_console.match?(cont)
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
- !commented_line && (a || b || c || closing_line.match?(cont))
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
- check_line = lambda { |line|
35
- lines_with_spaces << line.number if found_spaces(line.content) && !lines_with_spaces.nil?
36
- }
59
+
60
+ opening_tracker = 0
61
+ closing_tracker = 0
62
+
63
+ arr = file.lines
37
64
  err_type = 'SPACING_ERR'
38
- file.lines.each(&check_line)
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 !escapables.include?(wanted)
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
- detected_variable = match_variable(line.content.to_s) if !commented_line
81
- lines_variables_hash[line.number] = detected_variable if detected_variable
82
- variable_instances << detected_variable if detected_variable
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
@@ -1,3 +1,3 @@
1
1
  module Jscop
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
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
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-27 00:00:00.000000000 Z
11
+ date: 2020-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize