Skip to content

Commit 6a8639b

Browse files
abrissegkellogg
authored andcommitted
Add rubocop gems
1 parent 466be87 commit 6a8639b

File tree

3 files changed

+149
-96
lines changed

3 files changed

+149
-96
lines changed

.rubocop.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
require:
3+
- rubocop-performance
4+
5+
AllCops:
6+
DisplayCopNames: true
7+
NewCops: enable
8+
TargetRubyVersion: 2.6
9+
10+
Layout/ArgumentAlignment:
11+
# https://www.rubydoc.info/github/bbatsov/RuboCop/RuboCop/Cop/Layout/ArgumentAlignment
12+
EnforcedStyle: with_fixed_indentation
13+
Layout/CaseIndentation:
14+
EnforcedStyle: end
15+
Layout/EndAlignment:
16+
# https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/EndAlignment
17+
EnforcedStyleAlignWith: variable
18+
Layout/FirstArgumentIndentation:
19+
# https://www.rubydoc.info/github/bbatsov/RuboCop/RuboCop/Cop/Layout/FirstArgumentIndentation
20+
Enabled: false
21+
Layout/HashAlignment:
22+
EnforcedLastArgumentHashStyle: ignore_implicit
23+
Layout/LineLength:
24+
Max: 120
25+
Layout/MultilineMethodCallIndentation:
26+
# https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/MultilineMethodCallIndentation
27+
EnforcedStyle: indented
28+
Lint/AmbiguousBlockAssociation:
29+
AllowedMethods: ['change']
30+
31+
Metrics/MethodLength:
32+
CountComments: false # count full line comments?
33+
Max: 20
34+
35+
Style/Documentation:
36+
Enabled: false
37+
Style/DoubleNegation:
38+
Enabled: false
39+
Style/FormatStringToken:
40+
Enabled: false
41+
Style/HashSyntax:
42+
Enabled: false
43+
Style/MutableConstant:
44+
Enabled: false
45+
Style/StringLiterals:
46+
Enabled: false
47+
Style/StringConcatenation:
48+
Enabled: false
49+

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ group :development, :test do
4343
gem 'psych', platforms: [:mri, :rbx]
4444
gem 'benchmark-ips'
4545
gem 'rake'
46+
gem 'rubocop'
47+
gem 'rubocop-performance'
4648
end
4749

4850
group :debug do

lib/json/ld.rb

Lines changed: 98 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# -*- encoding: utf-8 -*-
21
# frozen_string_literal: true
3-
$:.unshift(File.expand_path("../ld", __FILE__))
2+
3+
$LOAD_PATH.unshift(File.expand_path('ld', __dir__))
44
require 'rdf' # @see https://rubygems.org/gems/rdf
55
require 'multi_json'
66
require 'set'
@@ -40,47 +40,47 @@ module LD
4040
autoload :Writer, 'json/ld/writer'
4141

4242
# JSON-LD profiles
43-
JSON_LD_NS = "http://www.w3.org/ns/json-ld#"
44-
PROFILES = %w(expanded compacted flattened framed).map {|p| JSON_LD_NS + p}.freeze
43+
JSON_LD_NS = 'http://www.w3.org/ns/json-ld#'
44+
PROFILES = %w[expanded compacted flattened framed].map { |p| JSON_LD_NS + p }.freeze
4545

4646
# Default context when compacting without one being specified
47-
DEFAULT_CONTEXT = "http://schema.org"
47+
DEFAULT_CONTEXT = 'http://schema.org'
4848

4949
# Acceptable MultiJson adapters
50-
MUTLI_JSON_ADAPTERS = %i(oj json_gem json_pure ok_json yajl nsjsonseerialization)
50+
MUTLI_JSON_ADAPTERS = %i[oj json_gem json_pure ok_json yajl nsjsonseerialization]
5151

52-
KEYWORDS = Set.new(%w(
53-
@annotation
54-
@base
55-
@container
56-
@context
57-
@default
58-
@direction
59-
@embed
60-
@explicit
61-
@first
62-
@graph
63-
@id
64-
@import
65-
@included
66-
@index
67-
@json
68-
@language
69-
@list
70-
@nest
71-
@none
72-
@omitDefault
73-
@propagate
74-
@protected
75-
@preserve
76-
@requireAll
77-
@reverse
78-
@set
79-
@type
80-
@value
81-
@version
82-
@vocab
83-
)).freeze
52+
KEYWORDS = Set.new(%w[
53+
@annotation
54+
@base
55+
@container
56+
@context
57+
@default
58+
@direction
59+
@embed
60+
@explicit
61+
@first
62+
@graph
63+
@id
64+
@import
65+
@included
66+
@index
67+
@json
68+
@language
69+
@list
70+
@nest
71+
@none
72+
@omitDefault
73+
@propagate
74+
@protected
75+
@preserve
76+
@requireAll
77+
@reverse
78+
@set
79+
@type
80+
@value
81+
@version
82+
@vocab
83+
]).freeze
8484

8585
# Regexp matching an NCName.
8686
NC_REGEXP = Regexp.new(
@@ -90,19 +90,20 @@ module LD
9090
( [a-zA-Z_]
9191
| \\\\u[0-9a-fA-F]
9292
)
93-
( [0-9a-zA-Z_\.-]
93+
( [0-9a-zA-Z_.-]
9494
| \\\\u([0-9a-fA-F]{4})
9595
)*
9696
$},
97-
Regexp::EXTENDED)
97+
Regexp::EXTENDED
98+
)
9899

99100
# Datatypes that are expressed in a native form and don't expand or compact
100101
NATIVE_DATATYPES = [RDF::XSD.integer.to_s, RDF::XSD.boolean.to_s, RDF::XSD.double.to_s]
101102

102103
JSON_STATE = JSON::State.new(
103-
indent: " ",
104-
space: " ",
105-
space_before: "",
104+
indent: ' ',
105+
space: ' ',
106+
space_before: '',
106107
object_nl: "\n",
107108
array_nl: "\n"
108109
)
@@ -113,64 +114,65 @@ class JsonLdError < StandardError
113114
def to_s
114115
"#{self.class.instance_variable_get :@code}: #{super}"
115116
end
117+
116118
def code
117119
self.class.instance_variable_get :@code
118120
end
119121

120-
class CollidingKeywords < JsonLdError; @code = "colliding keywords"; end
121-
class ConflictingIndexes < JsonLdError; @code = "conflicting indexes"; end
122-
class CyclicIRIMapping < JsonLdError; @code = "cyclic IRI mapping"; end
123-
class InvalidAnnotation < JsonLdError; @code = "invalid annotation"; end
124-
class InvalidBaseIRI < JsonLdError; @code = "invalid base IRI"; end
125-
class InvalidContainerMapping < JsonLdError; @code = "invalid container mapping"; end
126-
class InvalidContextEntry < JsonLdError; @code = "invalid context entry"; end
127-
class InvalidContextNullification < JsonLdError; @code = "invalid context nullification"; end
128-
class InvalidDefaultLanguage < JsonLdError; @code = "invalid default language"; end
129-
class InvalidIdValue < JsonLdError; @code = "invalid @id value"; end
130-
class InvalidIndexValue < JsonLdError; @code = "invalid @index value"; end
131-
class InvalidVersionValue < JsonLdError; @code = "invalid @version value"; end
132-
class InvalidImportValue < JsonLdError; @code = "invalid @import value"; end
133-
class InvalidIncludedValue < JsonLdError; @code = "invalid @included value"; end
134-
class InvalidIRIMapping < JsonLdError; @code = "invalid IRI mapping"; end
135-
class InvalidJsonLiteral < JsonLdError; @code = "invalid JSON literal"; end
136-
class InvalidKeywordAlias < JsonLdError; @code = "invalid keyword alias"; end
137-
class InvalidLanguageMapping < JsonLdError; @code = "invalid language mapping"; end
138-
class InvalidLanguageMapValue < JsonLdError; @code = "invalid language map value"; end
139-
class InvalidLanguageTaggedString < JsonLdError; @code = "invalid language-tagged string"; end
140-
class InvalidLanguageTaggedValue < JsonLdError; @code = "invalid language-tagged value"; end
141-
class InvalidLocalContext < JsonLdError; @code = "invalid local context"; end
142-
class InvalidNestValue < JsonLdError; @code = "invalid @nest value"; end
143-
class InvalidPrefixValue < JsonLdError; @code = "invalid @prefix value"; end
144-
class InvalidPropagateValue < JsonLdError; @code = "invalid @propagate value"; end
145-
class InvalidEmbeddedNode < JsonLdError; @code = "invalid embedded node"; end
146-
class InvalidRemoteContext < JsonLdError; @code = "invalid remote context"; end
147-
class InvalidReverseProperty < JsonLdError; @code = "invalid reverse property"; end
148-
class InvalidReversePropertyMap < JsonLdError; @code = "invalid reverse property map"; end
149-
class InvalidReversePropertyValue < JsonLdError; @code = "invalid reverse property value"; end
150-
class InvalidReverseValue < JsonLdError; @code = "invalid @reverse value"; end
151-
class InvalidScopedContext < JsonLdError; @code = "invalid scoped context"; end
152-
class InvalidScriptElement < JsonLdError; @code = "invalid script element"; end
153-
class InvalidSetOrListObject < JsonLdError; @code = "invalid set or list object"; end
122+
class CollidingKeywords < JsonLdError; @code = 'colliding keywords'; end
123+
class ConflictingIndexes < JsonLdError; @code = 'conflicting indexes'; end
124+
class CyclicIRIMapping < JsonLdError; @code = 'cyclic IRI mapping'; end
125+
class InvalidAnnotation < JsonLdError; @code = 'invalid annotation'; end
126+
class InvalidBaseIRI < JsonLdError; @code = 'invalid base IRI'; end
127+
class InvalidContainerMapping < JsonLdError; @code = 'invalid container mapping'; end
128+
class InvalidContextEntry < JsonLdError; @code = 'invalid context entry'; end
129+
class InvalidContextNullification < JsonLdError; @code = 'invalid context nullification'; end
130+
class InvalidDefaultLanguage < JsonLdError; @code = 'invalid default language'; end
131+
class InvalidIdValue < JsonLdError; @code = 'invalid @id value'; end
132+
class InvalidIndexValue < JsonLdError; @code = 'invalid @index value'; end
133+
class InvalidVersionValue < JsonLdError; @code = 'invalid @version value'; end
134+
class InvalidImportValue < JsonLdError; @code = 'invalid @import value'; end
135+
class InvalidIncludedValue < JsonLdError; @code = 'invalid @included value'; end
136+
class InvalidIRIMapping < JsonLdError; @code = 'invalid IRI mapping'; end
137+
class InvalidJsonLiteral < JsonLdError; @code = 'invalid JSON literal'; end
138+
class InvalidKeywordAlias < JsonLdError; @code = 'invalid keyword alias'; end
139+
class InvalidLanguageMapping < JsonLdError; @code = 'invalid language mapping'; end
140+
class InvalidLanguageMapValue < JsonLdError; @code = 'invalid language map value'; end
141+
class InvalidLanguageTaggedString < JsonLdError; @code = 'invalid language-tagged string'; end
142+
class InvalidLanguageTaggedValue < JsonLdError; @code = 'invalid language-tagged value'; end
143+
class InvalidLocalContext < JsonLdError; @code = 'invalid local context'; end
144+
class InvalidNestValue < JsonLdError; @code = 'invalid @nest value'; end
145+
class InvalidPrefixValue < JsonLdError; @code = 'invalid @prefix value'; end
146+
class InvalidPropagateValue < JsonLdError; @code = 'invalid @propagate value'; end
147+
class InvalidEmbeddedNode < JsonLdError; @code = 'invalid embedded node'; end
148+
class InvalidRemoteContext < JsonLdError; @code = 'invalid remote context'; end
149+
class InvalidReverseProperty < JsonLdError; @code = 'invalid reverse property'; end
150+
class InvalidReversePropertyMap < JsonLdError; @code = 'invalid reverse property map'; end
151+
class InvalidReversePropertyValue < JsonLdError; @code = 'invalid reverse property value'; end
152+
class InvalidReverseValue < JsonLdError; @code = 'invalid @reverse value'; end
153+
class InvalidScopedContext < JsonLdError; @code = 'invalid scoped context'; end
154+
class InvalidScriptElement < JsonLdError; @code = 'invalid script element'; end
155+
class InvalidSetOrListObject < JsonLdError; @code = 'invalid set or list object'; end
154156
class InvalidStreamingKeyOrder < JsonLdError; @code = 'invalid streaming key order' end
155-
class InvalidTermDefinition < JsonLdError; @code = "invalid term definition"; end
156-
class InvalidBaseDirection < JsonLdError; @code = "invalid base direction"; end
157-
class InvalidTypedValue < JsonLdError; @code = "invalid typed value"; end
158-
class InvalidTypeMapping < JsonLdError; @code = "invalid type mapping"; end
159-
class InvalidTypeValue < JsonLdError; @code = "invalid type value"; end
160-
class InvalidValueObject < JsonLdError; @code = "invalid value object"; end
161-
class InvalidValueObjectValue < JsonLdError; @code = "invalid value object value"; end
162-
class InvalidVocabMapping < JsonLdError; @code = "invalid vocab mapping"; end
163-
class IRIConfusedWithPrefix < JsonLdError; @code = "IRI confused with prefix"; end
164-
class KeywordRedefinition < JsonLdError; @code = "keyword redefinition"; end
165-
class LoadingDocumentFailed < JsonLdError; @code = "loading document failed"; end
166-
class LoadingRemoteContextFailed < JsonLdError; @code = "loading remote context failed"; end
167-
class ContextOverflow < JsonLdError; @code = "context overflow"; end
168-
class MissingIncludedReferent < JsonLdError; @code = "missing @included referent"; end
169-
class MultipleContextLinkHeaders < JsonLdError; @code = "multiple context link headers"; end
170-
class ProtectedTermRedefinition < JsonLdError; @code = "protected term redefinition"; end
171-
class ProcessingModeConflict < JsonLdError; @code = "processing mode conflict"; end
172-
class InvalidFrame < JsonLdError; @code = "invalid frame"; end
173-
class InvalidEmbedValue < InvalidFrame; @code = "invalid @embed value"; end
157+
class InvalidTermDefinition < JsonLdError; @code = 'invalid term definition'; end
158+
class InvalidBaseDirection < JsonLdError; @code = 'invalid base direction'; end
159+
class InvalidTypedValue < JsonLdError; @code = 'invalid typed value'; end
160+
class InvalidTypeMapping < JsonLdError; @code = 'invalid type mapping'; end
161+
class InvalidTypeValue < JsonLdError; @code = 'invalid type value'; end
162+
class InvalidValueObject < JsonLdError; @code = 'invalid value object'; end
163+
class InvalidValueObjectValue < JsonLdError; @code = 'invalid value object value'; end
164+
class InvalidVocabMapping < JsonLdError; @code = 'invalid vocab mapping'; end
165+
class IRIConfusedWithPrefix < JsonLdError; @code = 'IRI confused with prefix'; end
166+
class KeywordRedefinition < JsonLdError; @code = 'keyword redefinition'; end
167+
class LoadingDocumentFailed < JsonLdError; @code = 'loading document failed'; end
168+
class LoadingRemoteContextFailed < JsonLdError; @code = 'loading remote context failed'; end
169+
class ContextOverflow < JsonLdError; @code = 'context overflow'; end
170+
class MissingIncludedReferent < JsonLdError; @code = 'missing @included referent'; end
171+
class MultipleContextLinkHeaders < JsonLdError; @code = 'multiple context link headers'; end
172+
class ProtectedTermRedefinition < JsonLdError; @code = 'protected term redefinition'; end
173+
class ProcessingModeConflict < JsonLdError; @code = 'processing mode conflict'; end
174+
class InvalidFrame < JsonLdError; @code = 'invalid frame'; end
175+
class InvalidEmbedValue < InvalidFrame; @code = 'invalid @embed value'; end
174176
end
175177
end
176178
end

0 commit comments

Comments
 (0)