codeclimate 0.6.4 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/config/engines.yml +25 -2
- data/lib/cc/cli/config.rb +38 -0
- data/lib/cc/cli/config_generator.rb +60 -0
- data/lib/cc/cli/init.rb +26 -35
- data/lib/cc/cli/upgrade_config_generator.rb +34 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8c9b1ea7e082d3aebf1ec60122ce302cc362105
|
4
|
+
data.tar.gz: 8145118b8fc245b9ef21e53d951b40a52ebc58bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f57d7240b23377320fefd642a71db3fee4f1a88a4cbff30661623a90bb622d20505dc857e4e820fe10ec16ee4bb33749fae2a99286745592f8c2d770b719c70b
|
7
|
+
data.tar.gz: eb6c644256a56ebe17f1b44fa8785247e7b3b354cc634bc86618677c1f30fbbf37a40c86a70897f229f3fc7739b0a77f053e52f4f60abed88e5561deddd811ba
|
data/config/engines.yml
CHANGED
@@ -13,6 +13,21 @@ rubocop:
|
|
13
13
|
image: codeclimate/codeclimate-rubocop
|
14
14
|
description: A Ruby static code analyzer, based on the community Ruby style guide.
|
15
15
|
community: false
|
16
|
+
upgrade_languages:
|
17
|
+
- Ruby
|
18
|
+
enable_regexps:
|
19
|
+
- \.rb$
|
20
|
+
default_ratings_paths:
|
21
|
+
- "**.rb"
|
22
|
+
duplication:
|
23
|
+
image: codeclimate/codeclimate-duplication
|
24
|
+
description: Find similar structures in your code
|
25
|
+
community: false
|
26
|
+
default_config:
|
27
|
+
languages:
|
28
|
+
- ruby
|
29
|
+
upgrade_languages:
|
30
|
+
- Ruby
|
16
31
|
enable_regexps:
|
17
32
|
- \.rb$
|
18
33
|
default_ratings_paths:
|
@@ -53,6 +68,8 @@ eslint:
|
|
53
68
|
image: codeclimate/codeclimate-eslint
|
54
69
|
description: A JavaScript/JSX linting utility
|
55
70
|
community: false
|
71
|
+
upgrade_languages:
|
72
|
+
- JavaScript
|
56
73
|
enable_regexps:
|
57
74
|
- \.js$
|
58
75
|
- \.jsx$
|
@@ -85,14 +102,18 @@ bundler-audit:
|
|
85
102
|
image: codeclimate/codeclimate-bundler-audit
|
86
103
|
description: Patch-level verification for Bundler
|
87
104
|
community: false
|
88
|
-
|
89
|
-
-
|
105
|
+
upgrade_languages:
|
106
|
+
- Ruby
|
107
|
+
enable_regexps:
|
108
|
+
- Gemfile\.lock
|
90
109
|
default_ratings_paths:
|
91
110
|
- Gemfile.lock
|
92
111
|
phpcodesniffer:
|
93
112
|
image: codeclimate/codeclimate-phpcodesniffer
|
94
113
|
description: PHP Code Sniffer
|
95
114
|
community: false
|
115
|
+
upgrade_languages:
|
116
|
+
- PHP
|
96
117
|
enable_regexps:
|
97
118
|
- \.php$
|
98
119
|
- \.module$
|
@@ -105,6 +126,8 @@ phpmd:
|
|
105
126
|
image: codeclimate/codeclimate-phpmd
|
106
127
|
description: PHP Mess Detector
|
107
128
|
community: false
|
129
|
+
upgrade_languages:
|
130
|
+
- PHP
|
108
131
|
enable_regexps:
|
109
132
|
- \.php$
|
110
133
|
- \.module$
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module CC
|
2
|
+
module CLI
|
3
|
+
class Config
|
4
|
+
delegate :to_yaml, to: :config
|
5
|
+
def initialize
|
6
|
+
@config = {
|
7
|
+
"engines" => {},
|
8
|
+
"ratings" => { "paths" => [] }
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_engine(engine_name, engine_config)
|
13
|
+
config["engines"][engine_name] = { "enabled" => true }
|
14
|
+
|
15
|
+
if engine_config["default_config"].present?
|
16
|
+
config["engines"][engine_name]["config"] = engine_config["default_config"]
|
17
|
+
end
|
18
|
+
|
19
|
+
config["ratings"]["paths"] |= engine_config["default_ratings_paths"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_exclude_paths(paths)
|
23
|
+
config["exclude_paths"] ||= []
|
24
|
+
config["exclude_paths"] += paths.map do |path|
|
25
|
+
if path.ends_with?("/")
|
26
|
+
"#{path}**/*"
|
27
|
+
else
|
28
|
+
path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
attr_reader :config
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module CC
|
2
|
+
module CLI
|
3
|
+
class ConfigGenerator
|
4
|
+
CODECLIMATE_YAML = Command::CODECLIMATE_YAML
|
5
|
+
AUTO_EXCLUDE_PATHS = %w(config/ db/ features/ node_modules/ script/ spec/ test/ vendor/).freeze
|
6
|
+
|
7
|
+
def self.for(filesystem, engine_registry, upgrade_requested)
|
8
|
+
if upgrade_requested && upgrade_needed?(filesystem)
|
9
|
+
UpgradeConfigGenerator.new(filesystem, engine_registry)
|
10
|
+
else
|
11
|
+
ConfigGenerator.new(filesystem, engine_registry)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(filesystem, engine_registry)
|
16
|
+
@filesystem = filesystem
|
17
|
+
@engine_registry = engine_registry
|
18
|
+
end
|
19
|
+
|
20
|
+
def eligible_engines
|
21
|
+
return @eligible_engines if @eligible_engines
|
22
|
+
|
23
|
+
engines = engine_registry.list
|
24
|
+
@eligible_engines = engines.each_with_object({}) do |(name, config), result|
|
25
|
+
if engine_eligible?(config)
|
26
|
+
result[name] = config
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def exclude_paths
|
32
|
+
AUTO_EXCLUDE_PATHS.select { |path| filesystem.exist?(path) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def post_generation_verb
|
36
|
+
"generated"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_reader :engine_registry, :filesystem
|
42
|
+
|
43
|
+
def self.upgrade_needed?(filesystem)
|
44
|
+
if filesystem.exist?(CODECLIMATE_YAML)
|
45
|
+
YAML.safe_load(File.read(CODECLIMATE_YAML))["languages"].present?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def engine_eligible?(engine)
|
50
|
+
!engine["community"] && engine["enable_regexps"].present? && files_exist?(engine)
|
51
|
+
end
|
52
|
+
|
53
|
+
def files_exist?(engine)
|
54
|
+
filesystem.any? do |path|
|
55
|
+
engine["enable_regexps"].any? { |re| Regexp.new(re).match(path) }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/cc/cli/init.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
|
+
require 'cc/cli/config'
|
2
|
+
require 'cc/cli/config_generator'
|
3
|
+
require 'cc/cli/upgrade_config_generator'
|
4
|
+
|
1
5
|
module CC
|
2
6
|
module CLI
|
3
7
|
class Init < Command
|
4
8
|
include CC::Analyzer
|
5
9
|
|
6
|
-
AUTO_EXCLUDE_PATHS = %w[config db features node_modules script spec test vendor].freeze
|
7
|
-
|
8
10
|
def run
|
9
|
-
if filesystem.exist?(CODECLIMATE_YAML)
|
11
|
+
if !upgrade? && filesystem.exist?(CODECLIMATE_YAML)
|
10
12
|
say "Config file .codeclimate.yml already present.\nTry running 'validate-config' to check configuration."
|
13
|
+
elsif upgrade? && engines_enabled?
|
14
|
+
say "--upgrade should not be used on a .codeclimate.yml configured for the Platform.\nTry running 'validate-config' to check configuration."
|
11
15
|
else
|
12
16
|
create_codeclimate_yaml
|
13
|
-
say "Config file .codeclimate.yml successfully
|
17
|
+
say "Config file .codeclimate.yml successfully #{config_generator.post_generation_verb}.\nEdit and then try running 'validate-config' to check configuration."
|
14
18
|
create_default_configs
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
18
22
|
private
|
19
23
|
|
24
|
+
def upgrade?
|
25
|
+
@args.include?("--upgrade")
|
26
|
+
end
|
27
|
+
|
20
28
|
def create_codeclimate_yaml
|
21
|
-
config =
|
22
|
-
eligible_engines.each do |engine_name, engine_config|
|
23
|
-
config["engines"][engine_name] = {
|
24
|
-
"enabled" => true
|
25
|
-
}
|
26
|
-
config["ratings"] ||= {}
|
27
|
-
config["ratings"]["paths"] ||= []
|
29
|
+
config = CC::CLI::Config.new
|
28
30
|
|
29
|
-
|
31
|
+
config_generator.eligible_engines.each do |(engine_name, engine_config)|
|
32
|
+
config.add_engine(engine_name, engine_config)
|
30
33
|
end
|
31
34
|
|
32
|
-
config
|
33
|
-
|
35
|
+
config.add_exclude_paths(config_generator.exclude_paths)
|
34
36
|
filesystem.write_path(CODECLIMATE_YAML, config.to_yaml)
|
35
37
|
end
|
36
38
|
|
@@ -47,7 +49,7 @@ module CC
|
|
47
49
|
end
|
48
50
|
|
49
51
|
def available_configs
|
50
|
-
all_paths = eligible_engines.flat_map do |engine_name, _|
|
52
|
+
all_paths = config_generator.eligible_engines.flat_map do |engine_name, _|
|
51
53
|
engine_directory = File.expand_path("../../../../config/#{engine_name}", __FILE__)
|
52
54
|
Dir.glob("#{engine_directory}/*", File::FNM_DOTMATCH)
|
53
55
|
end
|
@@ -55,30 +57,19 @@ module CC
|
|
55
57
|
all_paths.reject { |path| ['.', '..'].include?(File.basename(path)) }
|
56
58
|
end
|
57
59
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
if filesystem.exist?(dir)
|
62
|
-
expanded_paths << "#{dir}/**/*"
|
63
|
-
end
|
60
|
+
def engines_enabled?
|
61
|
+
unless @engines_enabled.nil?
|
62
|
+
return @engines_enabled
|
64
63
|
end
|
65
|
-
expanded_paths
|
66
|
-
end
|
67
64
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
engine["enable_regexps"].any? { |re| Regexp.new(re).match(path) }
|
73
|
-
end
|
65
|
+
if filesystem.exist?(CODECLIMATE_YAML)
|
66
|
+
config = CC::Analyzer::Config.new(File.read(CODECLIMATE_YAML))
|
67
|
+
@engines_enabled ||= config.engine_names.any?
|
68
|
+
end
|
74
69
|
end
|
75
70
|
|
76
|
-
def
|
77
|
-
@
|
78
|
-
if engine_eligible?(config)
|
79
|
-
result[engine_name] = config
|
80
|
-
end
|
81
|
-
end
|
71
|
+
def config_generator
|
72
|
+
@config_generator ||= ConfigGenerator.for(filesystem, engine_registry, upgrade?)
|
82
73
|
end
|
83
74
|
end
|
84
75
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "cc/cli/config_generator"
|
2
|
+
|
3
|
+
module CC
|
4
|
+
module CLI
|
5
|
+
class UpgradeConfigGenerator < ConfigGenerator
|
6
|
+
def exclude_paths
|
7
|
+
existing_yaml["exclude_paths"] || []
|
8
|
+
end
|
9
|
+
|
10
|
+
def post_generation_verb
|
11
|
+
"upgraded"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def engine_eligible?(engine)
|
17
|
+
base_eligble = super
|
18
|
+
if engine["upgrade_languages"].present?
|
19
|
+
base_eligble && (engine["upgrade_languages"] & classic_languages).any?
|
20
|
+
else
|
21
|
+
base_eligble
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def classic_languages
|
26
|
+
@classic_languages ||= existing_yaml["languages"].reject { |_, v| !v }.map(&:first)
|
27
|
+
end
|
28
|
+
|
29
|
+
def existing_yaml
|
30
|
+
@existing_yml ||= YAML.safe_load(File.read(CODECLIMATE_YAML))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codeclimate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code Climate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -218,6 +218,8 @@ files:
|
|
218
218
|
- lib/cc/cli.rb
|
219
219
|
- lib/cc/cli/analyze.rb
|
220
220
|
- lib/cc/cli/command.rb
|
221
|
+
- lib/cc/cli/config.rb
|
222
|
+
- lib/cc/cli/config_generator.rb
|
221
223
|
- lib/cc/cli/console.rb
|
222
224
|
- lib/cc/cli/engines.rb
|
223
225
|
- lib/cc/cli/engines/disable.rb
|
@@ -229,6 +231,7 @@ files:
|
|
229
231
|
- lib/cc/cli/help.rb
|
230
232
|
- lib/cc/cli/init.rb
|
231
233
|
- lib/cc/cli/runner.rb
|
234
|
+
- lib/cc/cli/upgrade_config_generator.rb
|
232
235
|
- lib/cc/cli/validate_config.rb
|
233
236
|
- lib/cc/cli/version.rb
|
234
237
|
- lib/file_utils_ext.rb
|
@@ -252,7 +255,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
252
255
|
version: '0'
|
253
256
|
requirements: []
|
254
257
|
rubyforge_project:
|
255
|
-
rubygems_version: 2.4.
|
258
|
+
rubygems_version: 2.4.5
|
256
259
|
signing_key:
|
257
260
|
specification_version: 4
|
258
261
|
summary: Code Climate CLI
|