linty 0.0.3
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 +7 -0
- data/bin/linty +15 -0
- data/lib/linty/analyzer.rb +22 -0
- data/lib/linty/data/common_misspellings.txt +4268 -0
- data/lib/linty/jshint_analyzer.rb +43 -0
- data/lib/linty/offense.rb +14 -0
- data/lib/linty/rubocop_analyzer.rb +41 -0
- data/lib/linty/spelling_analyzer.rb +52 -0
- data/lib/linty.rb +14 -0
- metadata +154 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'jshintrb'
|
2
|
+
|
3
|
+
class JshintAnalyzer
|
4
|
+
NAME = 'JSHint'.freeze
|
5
|
+
SEVERITY = 'error'.freeze
|
6
|
+
TOO_MANY_ERRORS_CODE = 'E043'.freeze
|
7
|
+
|
8
|
+
def analyze(path)
|
9
|
+
find_js_files(path).each do |file|
|
10
|
+
analyze_file(file, path) do |offense|
|
11
|
+
yield offense
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def analyze_file(file, path)
|
17
|
+
normalized_file = File.expand_path(file).sub(path, '')
|
18
|
+
messages = Jshintrb.lint(File.read(file))
|
19
|
+
messages.each do |message|
|
20
|
+
unless message.nil? || message['code'] == TOO_MANY_ERRORS_CODE
|
21
|
+
yield new_offense(normalized_file, message)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def new_offense(file, message)
|
27
|
+
Offense.new(
|
28
|
+
analyzer: NAME,
|
29
|
+
file: file,
|
30
|
+
line: message['line'],
|
31
|
+
column: message['column'],
|
32
|
+
rule: message['reason'],
|
33
|
+
severity: SEVERITY,
|
34
|
+
message: message['evidence'].strip
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def find_js_files(path)
|
39
|
+
files = Dir.glob(path + '/**/*.js')
|
40
|
+
files.reject { |file| file.end_with? '.min.js' }
|
41
|
+
files.reject { |file| file.include? '/vendor/' }
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'virtus'
|
2
|
+
|
3
|
+
class Offense
|
4
|
+
include Virtus.model
|
5
|
+
|
6
|
+
attribute :analyzer, String
|
7
|
+
attribute :file, String
|
8
|
+
attribute :line, Integer
|
9
|
+
attribute :column, Integer
|
10
|
+
attribute :length, Integer
|
11
|
+
attribute :rule, String
|
12
|
+
attribute :severity, String
|
13
|
+
attribute :message, String
|
14
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubocop'
|
2
|
+
|
3
|
+
class RubocopAnalyzer
|
4
|
+
NAME = 'Rubocop'.freeze
|
5
|
+
|
6
|
+
def analyze(path)
|
7
|
+
file_results = run_rubocop(path)
|
8
|
+
file_results['files'].each do |file_result|
|
9
|
+
normalized_file = File.expand_path(file_result['path']).sub(path, '')
|
10
|
+
file_result['offenses'].each do |message|
|
11
|
+
yield new_offense(normalized_file, message)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def new_offense(file, message)
|
17
|
+
Offense.new(
|
18
|
+
analyzer: NAME,
|
19
|
+
file: file,
|
20
|
+
line: message['location']['line'],
|
21
|
+
column: message['location']['column'],
|
22
|
+
length: message['location']['length'],
|
23
|
+
rule: message['cop_name'],
|
24
|
+
severity: message['severity'],
|
25
|
+
message: message['message']
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def run_rubocop(path)
|
30
|
+
options, paths = RuboCop::Options.new.parse ['--format', 'json', path]
|
31
|
+
runner = RuboCop::Runner.new(options, RuboCop::ConfigStore.new)
|
32
|
+
begin
|
33
|
+
stdout = $stdout
|
34
|
+
$stdout = StringIO.new('', 'w')
|
35
|
+
runner.run(paths)
|
36
|
+
return JSON.parse($stdout.string)
|
37
|
+
ensure
|
38
|
+
$stdout = stdout
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class SpellingAnalyzer
|
2
|
+
NAME = 'Spellcheck'.freeze
|
3
|
+
RULE = 'Common misspelling'.freeze
|
4
|
+
SEVERITY = 'warning'.freeze
|
5
|
+
EXTENSIONS = ['.md', '.markdown', '.textile', '.rdoc'].freeze
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
path = File.dirname(__FILE__) + '/data/common_misspellings.txt'
|
9
|
+
@common_misspellings = File.read(path).lines.map(&:downcase).map!(&:strip)
|
10
|
+
end
|
11
|
+
|
12
|
+
def analyze(path)
|
13
|
+
find_text_files(path).each do |file|
|
14
|
+
analyze_file(file, path) do |offense|
|
15
|
+
yield offense
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def analyze_file(file, path)
|
21
|
+
normalized_file = File.expand_path(file).sub(path, '')
|
22
|
+
File.read(file).lines.each_with_index do |line, line_num|
|
23
|
+
words = find_words(line)
|
24
|
+
misspellings = words & @common_misspellings
|
25
|
+
misspellings.each do |misspelling|
|
26
|
+
yield new_offense(normalized_file, misspelling, line_num)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def new_offense(file, misspelling, line_num)
|
32
|
+
Offense.new(
|
33
|
+
analyzer: NAME,
|
34
|
+
file: file,
|
35
|
+
line: line_num,
|
36
|
+
rule: RULE,
|
37
|
+
severity: SEVERITY,
|
38
|
+
message: misspelling
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_text_files(path)
|
43
|
+
files = Dir.glob(path + '/**/*.*')
|
44
|
+
files.select { |file| EXTENSIONS.include? File.extname(file) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def find_words(content)
|
48
|
+
words = content.downcase.split(/\W+/).uniq
|
49
|
+
words.reject!(&:empty?)
|
50
|
+
return words
|
51
|
+
end
|
52
|
+
end
|
data/lib/linty.rb
ADDED
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linty
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Carey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: require_all
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.3.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.3
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: virtus
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.0.5
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.0'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.0.5
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rubocop
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0.37'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.37.2
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.37'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 0.37.2
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: jshintrb
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0.3'
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.0
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.3'
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 0.3.0
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: oj
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '2.14'
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 2.14.5
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '2.14'
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: 2.14.5
|
113
|
+
description: |-
|
114
|
+
Run static code analysis across many languages, \
|
115
|
+
powered by popular open source libraries.
|
116
|
+
email: careykevin@gmail.com
|
117
|
+
executables:
|
118
|
+
- linty
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files: []
|
121
|
+
files:
|
122
|
+
- bin/linty
|
123
|
+
- lib/linty.rb
|
124
|
+
- lib/linty/analyzer.rb
|
125
|
+
- lib/linty/data/common_misspellings.txt
|
126
|
+
- lib/linty/jshint_analyzer.rb
|
127
|
+
- lib/linty/offense.rb
|
128
|
+
- lib/linty/rubocop_analyzer.rb
|
129
|
+
- lib/linty/spelling_analyzer.rb
|
130
|
+
homepage: http://github.com/careykevin/linty
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.5.1
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Linty
|
154
|
+
test_files: []
|