codeclimate-yaml 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64b83201137eff338b53df17bcd0c40dc6c4080d
4
- data.tar.gz: 765030581dbb359be2b1a64cbfb3c8afb32b7f1a
3
+ metadata.gz: 09ba5979113592bfe69c17ea1ea515883bf8b236
4
+ data.tar.gz: b8d0034a571105f3e3f29807fc9edce39e459c8e
5
5
  SHA512:
6
- metadata.gz: bdcc647a18fdd90f1641ba26e9f495f8d9f1d21a2fddafb88a372e616615e9d0e749fe0dc0093e2d33886403e1abdc61a7b1df2c0c8a319a33f7cb18652774c7
7
- data.tar.gz: b255602577aeffcf93a4f642b21e5b69c60143203655fedd2e9aa4d1eb8a6b16f547ed478edf90b6406a4a26087a6813ff942079d0b941ce94b4250209d18b71
6
+ metadata.gz: b1aad8e2a33fa800765cd2f1997524dbb4604911b454695410ae0b02e3fad04a3f24046301fc568bcb982e029b231cb074d6d7f2ad28092c22286ebc889e7cdd
7
+ data.tar.gz: ebb9b13db51c9ed988e66c009dd31ee4d08cff6d18c56bb7b4936e66ab5bba2d2305e97479cdbcecab53b257ccaebb6f798eca7bc8b8520a6cfccd527adf633c
@@ -0,0 +1,32 @@
1
+ module CC
2
+ module Yaml
3
+ module Nodes
4
+ class Language < Scalar
5
+ LANGUAGES = %w[Ruby JavaScript Python PHP].freeze
6
+
7
+ def valid?
8
+ LANGUAGES.include?(name)
9
+ end
10
+
11
+ def name
12
+ to_s
13
+ end
14
+
15
+ def appears_to_be_mispelled_version_of?
16
+ if !valid? && downcased_language_map.has_key?(name.downcase)
17
+ downcased_language_map[self]
18
+ else
19
+ false
20
+ end
21
+ end
22
+
23
+ def downcased_language_map
24
+ @downcased_language_map ||=
25
+ LANGUAGES.each_with_object({}) do |language, obj|
26
+ obj[language.downcase] = language
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module CC
2
+ module Yaml
3
+ module Nodes
4
+ class LanguageList < Sequence
5
+ type Language
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,8 @@
1
1
  module CC::Yaml
2
2
  module Nodes
3
3
  class Mapping < Node
4
+ INCOMPATIBLE_KEYS_WARNING = "Analysis settings for Languages and Engines are both valid but mutually exclusive. Note: command line analysis requires an Engines configuration.".freeze
5
+
4
6
  def self.mapping
5
7
  @mapping ||= superclass.respond_to?(:mapping) ? superclass.mapping.dup : {}
6
8
  end
@@ -65,17 +67,12 @@ module CC::Yaml
65
67
  def set_warnings(key)
66
68
  if subnode_for(key)
67
69
  check_duplicates(key)
68
- elsif key == "languages"
69
- warning("analysis by language not available via CLI. Use engines configuration instead.")
70
+ check_incompatibility(key)
70
71
  else
71
72
  warning("unexpected key %p, dropping", key)
72
73
  end
73
74
  end
74
75
 
75
- def check_duplicates(key)
76
- warning("has multiple %p entries, keeping last entry", key) if self[key]
77
- end
78
-
79
76
  def []=(key, value)
80
77
  if mapped_key = mapped_key(key)
81
78
  unless value.is_a? Node
@@ -178,11 +175,37 @@ module CC::Yaml
178
175
 
179
176
  protected
180
177
 
181
- def dup_values
182
- duped_mapping = @mapping.map { |key, value| [key.dup, value.dup] }
183
- @mapping = Hash[duped_mapping]
184
- self
178
+ def dup_values
179
+ duped_mapping = @mapping.map { |key, value| [key.dup, value.dup] }
180
+ @mapping = Hash[duped_mapping]
181
+ self
182
+ end
183
+
184
+ def check_duplicates(key)
185
+ warning("has multiple %p entries, keeping last entry", key) if self[key]
186
+ end
187
+
188
+ def check_incompatibility(key)
189
+ if creates_incompatibility?(key)
190
+ warning(incompatibility_message(key), key)
185
191
  end
192
+ end
193
+
194
+ def incompatibility_message(key)
195
+ "#{extant_engines_or_languages_key} key already found, dropping key: #{key}. #{INCOMPATIBLE_KEYS_WARNING}"
196
+ end
197
+
198
+ def extant_engines_or_languages_key
199
+ if self["engines"]
200
+ "engines"
201
+ elsif self["languages"]
202
+ "languages"
203
+ end
204
+ end
205
+
206
+ def creates_incompatibility?(key)
207
+ (key == "engines" && self["languages"]) || (key == "languages" && self["engines"])
208
+ end
186
209
  end
187
210
  end
188
211
  end
@@ -7,6 +7,7 @@ module CC
7
7
  class Root < Mapping
8
8
  map :engines, to: EngineList
9
9
  map :exclude_paths, to: GlobList
10
+ map :languages, to: LanguageList
10
11
  map :ratings, to: Ratings
11
12
 
12
13
  def initialize
data/lib/cc/yaml/nodes.rb CHANGED
@@ -5,6 +5,8 @@ module CC
5
5
  autoload :EngineList, "cc/yaml/nodes/engine_list"
6
6
  autoload :Glob, "cc/yaml/nodes/glob"
7
7
  autoload :GlobList, "cc/yaml/nodes/glob_list"
8
+ autoload :Language, "cc/yaml/nodes/language"
9
+ autoload :LanguageList, "cc/yaml/nodes/language_list"
8
10
  autoload :Mapping, "cc/yaml/nodes/mapping"
9
11
  autoload :Node, "cc/yaml/nodes/node"
10
12
  autoload :OpenMapping, "cc/yaml/nodes/open_mapping"
@@ -1,5 +1,5 @@
1
1
  module CC
2
2
  module Yaml
3
- VERSION = "0.0.5".freeze
3
+ VERSION = "0.0.6".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codeclimate-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
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-06-30 00:00:00.000000000 Z
11
+ date: 2015-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: secure_string
@@ -50,6 +50,8 @@ files:
50
50
  - lib/cc/yaml/nodes/engine_list.rb
51
51
  - lib/cc/yaml/nodes/glob.rb
52
52
  - lib/cc/yaml/nodes/glob_list.rb
53
+ - lib/cc/yaml/nodes/language.rb
54
+ - lib/cc/yaml/nodes/language_list.rb
53
55
  - lib/cc/yaml/nodes/mapping.rb
54
56
  - lib/cc/yaml/nodes/node.rb
55
57
  - lib/cc/yaml/nodes/open_mapping.rb