Skip to content

Commit c2340fe

Browse files
committed
Add rubocop
1 parent cfdf6ca commit c2340fe

20 files changed

+260
-32
lines changed

.rubocop.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
# does not work well with RubyMotion named parameters
4+
Lint/UnusedMethodArgument:
5+
Enabled: false
6+
7+
Gemspec/DateAssignment: # (new in 1.10)
8+
Enabled: true
9+
Layout/SpaceBeforeBrackets: # (new in 1.7)
10+
Enabled: true
11+
Lint/AmbiguousAssignment: # (new in 1.7)
12+
Enabled: true
13+
Lint/DeprecatedConstants: # (new in 1.8)
14+
Enabled: true
15+
Lint/DuplicateBranch: # (new in 1.3)
16+
Enabled: true
17+
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
18+
Enabled: true
19+
Lint/EmptyBlock: # (new in 1.1)
20+
Enabled: true
21+
Lint/EmptyClass: # (new in 1.3)
22+
Enabled: true
23+
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
24+
Enabled: true
25+
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
26+
Enabled: true
27+
Lint/NumberedParameterAssignment: # (new in 1.9)
28+
Enabled: true
29+
Lint/OrAssignmentToConstant: # (new in 1.9)
30+
Enabled: true
31+
Lint/RedundantDirGlobSort: # (new in 1.8)
32+
Enabled: true
33+
Lint/SymbolConversion: # (new in 1.9)
34+
Enabled: true
35+
Lint/ToEnumArguments: # (new in 1.1)
36+
Enabled: true
37+
Lint/TripleQuotes: # (new in 1.9)
38+
Enabled: true
39+
Lint/UnexpectedBlockArity: # (new in 1.5)
40+
Enabled: true
41+
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
42+
Enabled: true
43+
Style/ArgumentsForwarding: # (new in 1.1)
44+
Enabled: true
45+
Style/CollectionCompact: # (new in 1.2)
46+
Enabled: true
47+
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
48+
Enabled: true
49+
Style/EndlessMethod: # (new in 1.8)
50+
Enabled: true
51+
Style/HashConversion: # (new in 1.10)
52+
Enabled: true
53+
Style/HashExcept: # (new in 1.7)
54+
Enabled: true
55+
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
56+
Enabled: true
57+
Style/NegatedIfElseCondition: # (new in 1.2)
58+
Enabled: true
59+
Style/NilLambda: # (new in 1.3)
60+
Enabled: true
61+
Style/RedundantArgument: # (new in 1.4)
62+
Enabled: true
63+
Style/StringChars: # (new in 1.12)
64+
Enabled: true
65+
Style/SwapValues: # (new in 1.1)
66+
Enabled: true

.rubocop_todo.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2021-05-04 22:10:55 UTC using RuboCop version 1.13.0.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 1
10+
# Configuration parameters: Include.
11+
# Include: **/*.gemspec
12+
Gemspec/RequiredRubyVersion:
13+
Exclude:
14+
- 'motion-html-pipeline.gemspec'
15+
16+
# Offense count: 1
17+
# Configuration parameters: AllowSafeAssignment.
18+
Lint/AssignmentInCondition:
19+
Exclude:
20+
- 'lib/motion-html-pipeline/pipeline/filter.rb'
21+
22+
# Offense count: 6
23+
# Configuration parameters: AllowedMethods.
24+
# AllowedMethods: enums
25+
Lint/ConstantDefinitionInBlock:
26+
Exclude:
27+
- 'spec/motion-html-pipeline/pipeline/absolute_source_filter_spec.rb'
28+
- 'spec/motion-html-pipeline/pipeline/https_filter_spec.rb'
29+
- 'spec/motion-html-pipeline/pipeline/image_filter_spec.rb'
30+
- 'spec/motion-html-pipeline/pipeline_spec.rb'
31+
- 'spec/spec_helper.rb'
32+
33+
# Offense count: 1
34+
Lint/DuplicateMethods:
35+
Exclude:
36+
- 'lib/motion-html-pipeline/pipeline/body_content.rb'
37+
38+
# Offense count: 1
39+
# Configuration parameters: IgnoreImplicitReferences.
40+
Lint/ShadowedArgument:
41+
Exclude:
42+
- 'lib/motion-html-pipeline/pipeline.rb'
43+
44+
# Offense count: 1
45+
Lint/ShadowingOuterLocalVariable:
46+
Exclude:
47+
- 'lib/motion-html-pipeline/pipeline.rb'
48+
49+
# Offense count: 1
50+
# Configuration parameters: AllowComments, AllowNil.
51+
Lint/SuppressedException:
52+
Exclude:
53+
- 'Rakefile'
54+
55+
# Offense count: 4
56+
Lint/UselessAssignment:
57+
Exclude:
58+
- 'lib/motion-html-pipeline/pipeline.rb'
59+
- 'spec/motion-html-pipeline/pipeline_spec.rb'
60+
61+
# Offense count: 1
62+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
63+
Metrics/AbcSize:
64+
Max: 20
65+
66+
# Offense count: 5
67+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
68+
# IgnoredMethods: refine
69+
Metrics/BlockLength:
70+
Max: 61
71+
72+
# Offense count: 2
73+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
74+
Metrics/MethodLength:
75+
Max: 13
76+
77+
# Offense count: 1
78+
Naming/ConstantName:
79+
Exclude:
80+
- 'spec/spec_helper.rb'
81+
82+
# Offense count: 3
83+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms.
84+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
85+
Naming/FileName:
86+
Exclude:
87+
- 'lib/motion-html-pipeline.rb'
88+
- 'lib/motion-html-pipeline/pipeline/disabled/@mention_filter.rb'
89+
- 'lib/motion-html-pipeline/pipeline/disabled/@team_mention_filter.rb'
90+
91+
# Offense count: 1
92+
# Configuration parameters: EnforcedStyle, IgnoredPatterns.
93+
# SupportedStyles: snake_case, camelCase
94+
Naming/MethodName:
95+
Exclude:
96+
- 'app/app_delegate.rb'
97+
98+
# Offense count: 1
99+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
100+
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
101+
Naming/MethodParameterName:
102+
Exclude:
103+
- 'app/app_delegate.rb'
104+
105+
# Offense count: 1
106+
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
107+
# NamePrefix: is_, has_, have_
108+
# ForbiddenPrefixes: is_, has_, have_
109+
# AllowedMethods: is_a?
110+
# MethodDefinitionMacros: define_method, define_singleton_method
111+
Naming/PredicateName:
112+
Exclude:
113+
- 'spec/**/*'
114+
- 'lib/motion-html-pipeline/pipeline/filter.rb'
115+
116+
# Offense count: 1
117+
# Configuration parameters: EnforcedStyle, AllowedIdentifiers.
118+
# SupportedStyles: snake_case, camelCase
119+
Naming/VariableName:
120+
Exclude:
121+
- 'app/app_delegate.rb'
122+
123+
# Offense count: 8
124+
# Configuration parameters: AllowedChars.
125+
# AllowedChars: ©
126+
Style/AsciiComments:
127+
Exclude:
128+
- 'spec/motion-html-pipeline/pipeline/disabled/email_reply_filter_spec.rb'
129+
- 'spec/motion-html-pipeline/pipeline/disabled/toc_filter_spec.rb'
130+
131+
# Offense count: 5
132+
# Configuration parameters: AllowedConstants.
133+
Style/Documentation:
134+
Exclude:
135+
- 'spec/**/*'
136+
- 'test/**/*'
137+
- 'app/app_delegate.rb'
138+
- 'lib/motion-html-pipeline/document_fragment.rb'
139+
- 'lib/motion-html-pipeline/pipeline/absolute_source_filter.rb'
140+
- 'lib/motion-html-pipeline/pipeline/image_filter.rb'
141+
- 'lib/motion-html-pipeline/pipeline/text_filter.rb'
142+
143+
# Offense count: 1
144+
# Configuration parameters: MinBodyLength.
145+
Style/GuardClause:
146+
Exclude:
147+
- 'lib/motion-html-pipeline/pipeline/filter.rb'
148+
149+
# Offense count: 35
150+
# Cop supports --auto-correct.
151+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
152+
# URISchemes: http, https
153+
Layout/LineLength:
154+
Max: 600

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.7.2

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# -*- coding: utf-8 -*-
21
# frozen_string_literal: true
3-
$:.unshift("/Library/RubyMotion/lib")
4-
$:.unshift("~/.rubymotion/rubymotion-templates")
2+
3+
$LOAD_PATH.unshift('/Library/RubyMotion/lib')
4+
$LOAD_PATH.unshift('~/.rubymotion/rubymotion-templates')
55

66
platform = ENV.fetch('platform', 'osx')
77
testing = true if ARGV.join(' ') =~ /spec/

app/app_delegate.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
class AppDelegate
44
# OS X entry point
55
#------------------------------------------------------------------------------
6-
def applicationDidFinishLaunching(notification)
7-
end
6+
def applicationDidFinishLaunching(notification); end
87

98
# iOS entry point
109
#------------------------------------------------------------------------------
11-
def application(application, didFinishLaunchingWithOptions:launchOptions)
10+
def application(application, didFinishLaunchingWithOptions: launchOptions)
1211
true
1312
end
1413
end

lib/motion-html-pipeline.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# frozen_string_literal: true
22

3-
unless defined?(Motion::Project::Config)
4-
raise "This file must be required within a RubyMotion project Rakefile."
5-
end
3+
raise 'This file must be required within a RubyMotion project Rakefile.' unless defined?(Motion::Project::Config)
64

75
require 'motion-cocoapods'
86

97
lib_dir_path = File.dirname(File.expand_path(__FILE__))
108
Motion::Project::App.setup do |app|
11-
app.files.unshift(Dir.glob(File.join(lib_dir_path, "motion-html-pipeline/**/*.rb")))
9+
app.files.unshift(Dir.glob(File.join(lib_dir_path, 'motion-html-pipeline/**/*.rb')))
1210

1311
app.pods do
1412
pod 'HTMLKit', '~> 4.2'

lib/motion-html-pipeline/document_fragment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ def css(query)
2424
def to_html
2525
document.body.innerHTML
2626
end
27-
alias :to_s :to_html
27+
alias to_s to_html
2828
end
2929
end

lib/motion-html-pipeline/pipeline.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ def self.parse(document_or_html)
4242

4343
# Public: String name for this Pipeline. Defaults to Class name.
4444
attr_writer :instrumentation_name
45+
4546
def instrumentation_name
4647
return @instrumentation_name if defined?(@instrumentation_name)
48+
4749
@instrumentation_name = self.class.name
4850
end
4951

@@ -54,6 +56,7 @@ class << self
5456

5557
def initialize(filters, default_context = {}, result_class = nil)
5658
raise ArgumentError, 'default_context cannot be nil' if default_context.nil?
59+
5760
@filters = filters.flatten.freeze
5861
@default_context = default_context.freeze
5962
@result_class = result_class || Hash
@@ -132,12 +135,11 @@ def setup_instrumentation(name = nil, service = nil)
132135
# block, otherwise the block is ran without instrumentation.
133136
#
134137
# Returns the result of the provided block.
135-
def instrument(event, payload = nil)
138+
def instrument(event, payload = nil, &block)
136139
payload ||= default_payload
137140
return yield(payload) unless instrumentation_service
138-
instrumentation_service.instrument event, payload do |payload|
139-
yield payload
140-
end
141+
142+
instrumentation_service.instrument event, payload, &block
141143
end
142144

143145
# Internal: Default payload for instrumentation.

lib/motion-html-pipeline/pipeline/absolute_source_filter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ class AbsoluteSourceFilter < Filter
1919
def call
2020
doc.css('img').each do |element|
2121
next if element['src'].nil? || element['src'].empty?
22+
2223
src = element['src'].strip
2324
next if src.start_with? 'http'
25+
2426
base = if src.start_with? '/'
2527
image_base_url
2628
else

lib/motion-html-pipeline/pipeline/disabled/@mention_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# TODO Requires Set (or something similar)
3+
# TODO: Requires Set (or something similar)
44
#------------------------------------------------------------------------------
55
# require 'set'
66
#

lib/motion-html-pipeline/pipeline/disabled/autolink_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
# TODO Requires Rinku gem (or something similar)
3+
# TODO: Requires Rinku gem (or something similar)
44
#------------------------------------------------------------------------------
55
# module MotionHTMLPipeline
66
# class Pipeline

lib/motion-html-pipeline/pipeline/filter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def doc
6666
# called.
6767
def html
6868
raise InvalidDocumentException if @html.nil? && @doc.nil?
69+
6970
@html || doc.to_html
7071
end
7172

lib/motion-html-pipeline/pipeline/image_filter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Pipeline
1010

1111
class ImageFilter < TextFilter
1212
def call
13-
@text.gsub(/(https|http)?:\/\/.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?/i) do |match|
13+
@text.gsub(%r{(https|http)?://.+\.(jpg|jpeg|bmp|gif|png)(\?\S+)?}i) do |match|
1414
%(<img src="#{match}" alt=""/>)
1515
end
1616
end

lib/motion-html-pipeline/pipeline/text_filter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class TextFilter < Filter
77

88
def initialize(text, context = nil, result = nil)
99
raise TypeError, 'text cannot be HTML' if text.is_a?(DocumentFragment)
10+
1011
# Ensure that this is always a string
1112
@text = text.respond_to?(:to_str) ? text.to_str : text.to_s
1213
super nil, context, result

lib/motion-html-pipeline/pipeline/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module MotionHTMLPipeline
44
class Pipeline
5-
VERSION = '0.4.2'.freeze
5+
VERSION = '0.4.2'
66
end
77
end

motion-html-pipeline.gemspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require File.expand_path('../lib/motion-html-pipeline/pipeline/version.rb', __FILE__)
3+
require File.expand_path('lib/motion-html-pipeline/pipeline/version.rb', __dir__)
44

55
Gem::Specification.new do |spec|
66
spec.name = 'motion-html-pipeline'
@@ -12,8 +12,7 @@ Gem::Specification.new do |spec|
1212
spec.homepage = 'https://github.com/digitalmoksha/motion-html-pipeline'
1313
spec.licenses = ['MIT']
1414

15-
spec.files = Dir.glob('lib/**/*.rb')
16-
spec.files << 'README.md'
15+
spec.files = Dir.glob('lib/**/*.rb') + ['README.md']
1716
spec.test_files = Dir.glob('spec/**/*.rb')
1817
spec.require_paths = ['lib']
1918

spec/motion-html-pipeline/_helpers/mock_instumentation_service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
class MockedInstrumentationService
44
attr_reader :events
5+
56
def initialize(event = nil, events = [])
67
@events = events
78
subscribe event

0 commit comments

Comments
 (0)