From ae7367c5aa4e4530ab34d8f87f153264f2aa25b6 Mon Sep 17 00:00:00 2001 From: Dmytro Shteflyuk Date: Tue, 22 Aug 2017 12:55:11 -0400 Subject: [PATCH] More strict Ruby code style --- .rubocop.yml | 213 +++++++++++++------------- lib/meta_tags.rb | 1 + lib/meta_tags/meta_tags_collection.rb | 14 +- lib/meta_tags/renderer.rb | 82 +++++----- lib/meta_tags/text_normalizer.rb | 2 +- meta-tags.gemspec | 2 +- 6 files changed, 157 insertions(+), 157 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 25ddacfc..6854ad94 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,6 @@ AllCops: DisabledByDefault: true + TargetRubyVersion: 2.2 #################### Lint ################################ @@ -19,7 +20,7 @@ Lint/AmbiguousRegexpLiteral: Lint/AssignmentInCondition: Description: "Don't use assignment in conditions." StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition' - Enabled: false + Enabled: true Lint/BlockAlignment: Description: 'Align block ends correctly.' @@ -210,8 +211,8 @@ Metrics/AbcSize: A calculated magnitude based on number of assignments, branches, and conditions. Reference: 'http://c2.com/cgi/wiki?AbcMetric' - Enabled: false - Max: 20 + Enabled: true + Max: 25 Metrics/BlockNesting: Description: 'Avoid excessive block nesting' @@ -335,7 +336,7 @@ Rails/FindBy: Rails/FindEach: Description: 'Prefer all.find_each over all.find.' - Enabled: false + Enabled: true Rails/HasAndBelongsToMany: Description: 'Prefer has_many :through to has_and_belongs_to_many.' @@ -343,7 +344,7 @@ Rails/HasAndBelongsToMany: Rails/Output: Description: 'Checks for calls to puts, print, etc.' - Enabled: false + Enabled: true Rails/ReadWriteAttribute: Description: >- @@ -386,40 +387,40 @@ Style/AlignArray: Align the elements of an array literal if they span more than one line. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#align-multiline-arrays' - Enabled: false + Enabled: true Style/AlignHash: Description: >- Align the elements of a hash literal if they span more than one line. - Enabled: false + Enabled: true Style/AlignParameters: Description: >- Align the parameters of a method call if they span more than one line. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-double-indent' - Enabled: false + Enabled: true Style/AndOr: Description: 'Use &&/|| instead of and/or.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-and-or-or' - Enabled: false + Enabled: true Style/ArrayJoin: Description: 'Use Array#join instead of Array#*.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#array-join' - Enabled: false + Enabled: true Style/AsciiComments: Description: 'Use only ascii symbols in comments.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-comments' - Enabled: false + Enabled: true Style/AsciiIdentifiers: Description: 'Use only ascii symbols in identifiers.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#english-identifiers' - Enabled: false + Enabled: true Style/Attr: Description: 'Checks for uses of Module#attr.' @@ -429,7 +430,7 @@ Style/Attr: Style/BeginBlock: Description: 'Avoid the use of BEGIN blocks.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-BEGIN-blocks' - Enabled: false + Enabled: true Style/BarePercentLiterals: Description: 'Checks if usage of %() or %Q() matches configuration.' @@ -443,7 +444,7 @@ Style/BlockComments: Style/BlockEndNewline: Description: 'Put end statement of multiline block on its own line.' - Enabled: false + Enabled: true Style/BlockDelimiters: Description: >- @@ -460,7 +461,7 @@ Style/BracesAroundHashParameters: Style/CaseEquality: Description: 'Avoid explicit use of the case equality operator(===).' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-case-equality' - Enabled: false + Enabled: true Style/CaseIndentation: Description: 'Indentation of when in a case/when/[else/]end.' @@ -470,12 +471,12 @@ Style/CaseIndentation: Style/CharacterLiteral: Description: 'Checks for uses of character literals.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-character-literals' - Enabled: false + Enabled: true Style/ClassAndModuleCamelCase: Description: 'Use CamelCase for classes and modules.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#camelcase-classes' - Enabled: false + Enabled: true Style/ClassAndModuleChildren: Description: 'Checks style of children classes and modules.' @@ -483,12 +484,13 @@ Style/ClassAndModuleChildren: Style/ClassCheck: Description: 'Enforces consistent use of `Object#is_a?` or `Object#kind_of?`.' - Enabled: false + Enabled: true + EnforcedStyle: kind_of? Style/ClassMethods: Description: 'Use self when defining module/class methods.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#def-self-class-methods' - Enabled: false + Enabled: true Style/ClassVars: Description: 'Avoid the use of class variables.' @@ -497,12 +499,12 @@ Style/ClassVars: Style/ClosingParenthesisIndentation: Description: 'Checks the indentation of hanging closing parentheses.' - Enabled: false + Enabled: true Style/ColonMethodCall: Description: 'Do not use :: for method call.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#double-colons' - Enabled: false + Enabled: true Style/CommandLiteral: Description: 'Use `` or %x around command literals.' @@ -521,17 +523,17 @@ Style/CommentIndentation: Style/ConstantName: Description: 'Constants should use SCREAMING_SNAKE_CASE.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#screaming-snake-case' - Enabled: false + Enabled: true Style/DefWithParentheses: Description: 'Use def with parentheses when there are arguments.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false + Enabled: true Style/PreferredHashMethods: Description: 'Checks for use of deprecated Hash methods.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key' - Enabled: false + Enabled: true Style/Documentation: Description: 'Document classes and non-namespace modules.' @@ -540,7 +542,8 @@ Style/Documentation: Style/DotPosition: Description: 'Checks the position of the dot in multi-line method calls.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains' - Enabled: false + EnforcedStyle: trailing + Enabled: true Style/DoubleNegation: Description: 'Checks for uses of double negation (!!).' @@ -553,28 +556,28 @@ Style/EachWithObject: Style/ElseAlignment: Description: 'Align elses and elsifs correctly.' - Enabled: false + Enabled: true Style/EmptyElse: Description: 'Avoid empty else-clauses.' - Enabled: false + Enabled: true Style/EmptyLineBetweenDefs: Description: 'Use empty lines between defs.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#empty-lines-between-methods' - Enabled: false + Enabled: true Style/EmptyLines: Description: "Don't use several empty lines in a row." - Enabled: false + Enabled: true Style/EmptyLinesAroundAccessModifier: Description: "Keep blank lines around access modifiers." - Enabled: false + Enabled: true Style/EmptyLinesAroundBlockBody: Description: "Keeps track of empty lines around block bodies." - Enabled: false + Enabled: true Style/EmptyLinesAroundClassBody: Description: "Keeps track of empty lines around class bodies." @@ -586,31 +589,31 @@ Style/EmptyLinesAroundModuleBody: Style/EmptyLinesAroundMethodBody: Description: "Keeps track of empty lines around method bodies." - Enabled: false + Enabled: true Style/EmptyLiteral: Description: 'Prefer literals to Array.new/Hash.new/String.new.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#literal-array-hash' - Enabled: false + Enabled: true Style/EndBlock: Description: 'Avoid the use of END blocks.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-END-blocks' - Enabled: false + Enabled: true Style/EndOfLine: Description: 'Use Unix-style line endings.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#crlf' - Enabled: false + Enabled: true Style/EvenOdd: Description: 'Favor the use of Fixnum#even? && Fixnum#odd?' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods' - Enabled: false + Enabled: true Style/ExtraSpacing: Description: 'Do not use unnecessary spacing.' - Enabled: false + Enabled: true Style/FileName: Description: 'Use snake_case for source file names.' @@ -620,7 +623,7 @@ Style/FileName: Style/InitialIndentation: Description: >- Checks the indentation of the first non-blank non-comment line in a file. - Enabled: false + Enabled: true Style/FirstParameterIndentation: Description: 'Checks the indentation of the first parameter in a method call.' @@ -629,35 +632,35 @@ Style/FirstParameterIndentation: Style/FlipFlop: Description: 'Checks for flip flops' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-flip-flops' - Enabled: false + Enabled: true Style/For: Description: 'Checks use of for or each in multiline loops.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-for-loops' - Enabled: false + Enabled: true Style/FormatString: Description: 'Enforce the use of Kernel#sprintf, Kernel#format or String#%.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#sprintf' - Enabled: false + Enabled: true Style/GlobalVars: Description: 'Do not introduce global variables.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#instance-vars' Reference: 'http://www.zenspider.com/Languages/Ruby/QuickRef.html' - Enabled: false + Enabled: true Style/GuardClause: Description: 'Check for conditionals that can be replaced with guard clauses' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals' - Enabled: false + Enabled: true Style/HashSyntax: Description: >- Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax { :a => 1, :b => 2 }. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-literals' - Enabled: false + Enabled: true Style/IfUnlessModifier: Description: >- @@ -669,31 +672,31 @@ Style/IfUnlessModifier: Style/IfWithSemicolon: Description: 'Do not use if x; .... Use the ternary operator instead.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon-ifs' - Enabled: false + Enabled: true Style/IndentationConsistency: Description: 'Keep indentation straight.' - Enabled: false + Enabled: true Style/IndentationWidth: Description: 'Use 2 spaces for indentation.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false + Enabled: true Style/IndentArray: Description: >- Checks the indentation of the first element in an array literal. - Enabled: false + Enabled: true Style/IndentHash: Description: 'Checks the indentation of the first key in a hash literal.' - Enabled: false + Enabled: true Style/InfiniteLoop: Description: 'Use Kernel#loop for infinite loops.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#infinite-loop' - Enabled: false + Enabled: true Style/Lambda: Description: 'Use the new lambda literal syntax for single-line blocks.' @@ -703,12 +706,12 @@ Style/Lambda: Style/LambdaCall: Description: 'Use lambda.call(...) instead of lambda.(...).' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#proc-call' - Enabled: false + Enabled: true Style/LeadingCommentSpace: Description: 'Comments should start with a space.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-space' - Enabled: false + Enabled: true Style/LineEndConcatenation: Description: >- @@ -719,19 +722,19 @@ Style/LineEndConcatenation: Style/MethodCallWithoutArgsParentheses: Description: 'Do not use parentheses for method calls with no arguments.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens' - Enabled: false + Enabled: true Style/MethodDefParentheses: Description: >- Checks if the method definitions have or don't have parentheses. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens' - Enabled: false + Enabled: true Style/MethodName: Description: 'Use the configured style when naming methods.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars' - Enabled: false + Enabled: true Style/ModuleFunction: Description: 'Checks for usage of `extend self` in modules.' @@ -745,32 +748,32 @@ Style/MultilineBlockChain: Style/MultilineBlockLayout: Description: 'Ensures newlines after multiline block do statements.' - Enabled: false + Enabled: true Style/MultilineIfThen: Description: 'Do not use then for multi-line if/unless.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-then' - Enabled: false + Enabled: true Style/MultilineOperationIndentation: Description: >- Checks indentation of binary operations that span more than one line. - Enabled: false + Enabled: true Style/MultilineTernaryOperator: Description: >- Avoid multi-line ?: (the ternary operator); use if/unless instead. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-multiline-ternary' - Enabled: false + Enabled: true Style/NegatedIf: Description: >- Favor unless over if for negative conditions (or control flow or). StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#unless-for-negatives' - Enabled: false + Enabled: true Style/NegatedWhile: Description: 'Favor until over while for negative conditions.' @@ -780,17 +783,17 @@ Style/NegatedWhile: Style/NestedTernaryOperator: Description: 'Use one expression per branch in a ternary operator.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-ternary' - Enabled: false + Enabled: true Style/Next: Description: 'Use `next` to skip iteration instead of a condition at the end.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals' - Enabled: false + Enabled: true Style/NilComparison: Description: 'Prefer x.nil? to x == nil.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#predicate-methods' - Enabled: false + Enabled: true Style/NonNilCheck: Description: 'Checks for redundant nil checks.' @@ -800,7 +803,7 @@ Style/NonNilCheck: Style/Not: Description: 'Use ! instead of not.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#bang-not-not' - Enabled: false + Enabled: true Style/NumericLiterals: Description: >- @@ -814,7 +817,7 @@ Style/OneLineConditional: Favor the ternary operator(?:) over if/then/else/end constructs. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#ternary-operator' - Enabled: false + Enabled: true Style/OpMethod: Description: 'When defining binary operators, name the argument other.' @@ -826,7 +829,7 @@ Style/OptionalArguments: Checks for optional arguments that do not appear at the end of the argument list StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#optional-arguments' - Enabled: false + Enabled: true Style/ParallelAssignment: Description: >- @@ -835,14 +838,14 @@ Style/ParallelAssignment: matches on both sides of the assignment. This also provides performance benefits StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parallel-assignment' - Enabled: false + Enabled: true Style/ParenthesesAroundCondition: Description: >- Don't use parentheses around the condition of an if/unless/while. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-parens-if' - Enabled: false + Enabled: true Style/PercentLiteralDelimiters: Description: 'Use `%`-literal delimiters consistently' @@ -871,17 +874,17 @@ Style/Proc: Style/RaiseArgs: Description: 'Checks the arguments passed to raise/fail.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#exception-class-messages' - Enabled: false + Enabled: true Style/RedundantBegin: Description: "Don't use begin blocks when they are not needed." StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#begin-implicit' - Enabled: false + Enabled: true Style/RedundantException: Description: "Checks for an obsolete RuntimeException argument in raise/fail." StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-explicit-runtimeerror' - Enabled: false + Enabled: true Style/RedundantReturn: Description: "Don't use return where it's not required." @@ -900,24 +903,24 @@ Style/RegexpLiteral: Style/RescueEnsureAlignment: Description: 'Align rescues and ensures correctly.' - Enabled: false + Enabled: true Style/RescueModifier: Description: 'Avoid using rescue in its modifier form.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-rescue-modifiers' - Enabled: false + Enabled: true Style/SelfAssignment: Description: >- Checks for places where self-assignment shorthand should have been used. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#self-assignment' - Enabled: false + Enabled: true Style/Semicolon: Description: "Don't use semicolons to terminate expressions." StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-semicolon' - Enabled: false + Enabled: true Style/SignalException: Description: 'Checks for proper usage of fail and raise.' @@ -932,7 +935,7 @@ Style/SingleLineBlockParams: Style/SingleLineMethods: Description: 'Avoid single-line methods.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-single-line-methods' - Enabled: false + Enabled: true Style/SpaceBeforeFirstArg: Description: >- @@ -943,43 +946,43 @@ Style/SpaceBeforeFirstArg: Style/SpaceAfterColon: Description: 'Use spaces after colons.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false + Enabled: true Style/SpaceAfterComma: Description: 'Use spaces after commas.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false + Enabled: true Style/SpaceAroundKeyword: Description: 'Use spaces around keywords.' - Enabled: false + Enabled: true Style/SpaceAfterMethodName: Description: >- Do not put a space between a method name and the opening parenthesis in a method definition. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#parens-no-spaces' - Enabled: false + Enabled: true Style/SpaceAfterNot: Description: Tracks redundant space after the ! operator. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-bang' - Enabled: false + Enabled: true Style/SpaceAfterSemicolon: Description: 'Use spaces after semicolons.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false + Enabled: true Style/SpaceBeforeBlockBraces: Description: >- Checks that the left block brace has or doesn't have space before it. - Enabled: false + Enabled: true Style/SpaceBeforeComma: Description: 'No spaces before commas.' - Enabled: false + Enabled: true Style/SpaceBeforeComment: Description: >- @@ -989,18 +992,18 @@ Style/SpaceBeforeComment: Style/SpaceBeforeSemicolon: Description: 'No spaces before semicolons.' - Enabled: false + Enabled: true Style/SpaceInsideBlockBraces: Description: >- Checks that block braces have or don't have surrounding space. For blocks taking parameters, checks that the left brace has or doesn't have trailing space. - Enabled: false + Enabled: true Style/SpaceAroundBlockParameters: Description: 'Checks the spacing inside and after block parameters pipes.' - Enabled: false + Enabled: true Style/SpaceAroundEqualsInParameterDefault: Description: >- @@ -1008,12 +1011,12 @@ Style/SpaceAroundEqualsInParameterDefault: have or don't have surrounding space depending on configuration. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-around-equals' - Enabled: false + Enabled: true Style/SpaceAroundOperators: Description: 'Use a single space around operators.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false + Enabled: true Style/SpaceInsideBrackets: Description: 'No spaces after [ or before ].' @@ -1023,27 +1026,27 @@ Style/SpaceInsideBrackets: Style/SpaceInsideHashLiteralBraces: Description: "Use spaces inside hash literal braces - or don't." StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-operators' - Enabled: false + Enabled: true Style/SpaceInsideParens: Description: 'No spaces after ( or before ).' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-spaces-braces' - Enabled: false + Enabled: true Style/SpaceInsideRangeLiteral: Description: 'No spaces inside range literals.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-space-inside-range-literals' - Enabled: false + Enabled: true Style/SpaceInsideStringInterpolation: Description: 'Checks for padding/surrounding spaces inside string interpolation.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#string-interpolation' - Enabled: false + Enabled: true Style/SpecialGlobalVars: Description: 'Avoid Perl-style global variables.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms' - Enabled: false + Enabled: true Style/StringLiterals: Description: 'Checks if uses of quotes match the configured preference.' @@ -1059,25 +1062,25 @@ Style/StringLiteralsInInterpolation: Style/StructInheritance: Description: 'Checks for inheritance from Struct.new.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-extend-struct-new' - Enabled: false + Enabled: true Style/SymbolLiteral: Description: 'Use plain symbols instead of string symbols when possible.' - Enabled: false + Enabled: true Style/SymbolProc: Description: 'Use symbols as procs instead of blocks when possible.' - Enabled: false + Enabled: true Style/Tab: Description: 'No hard tabs.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#spaces-indentation' - Enabled: false + Enabled: true Style/TrailingBlankLines: Description: 'Checks trailing blank lines and final newline.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#newline-eof' - Enabled: false + Enabled: true Style/TrailingCommaInArguments: Description: 'Checks for trailing comma in parameter lists.' @@ -1092,19 +1095,19 @@ Style/TrailingCommaInLiteral: Style/TrailingWhitespace: Description: 'Avoid trailing whitespace.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-whitespace' - Enabled: false + Enabled: true Style/TrivialAccessors: Description: 'Prefer attr_* methods to trivial readers/writers.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#attr_family' - Enabled: false + Enabled: true Style/UnlessElse: Description: >- Do not use unless with else. Rewrite these with the positive case first. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-else-with-unless' - Enabled: false + Enabled: true Style/UnneededCapitalW: Description: 'Checks for %W when interpolation is not needed.' @@ -1119,19 +1122,19 @@ Style/TrailingUnderscoreVariable: Description: >- Checks for the usage of unneeded trailing underscores at the end of parallel variable assignment. - Enabled: false + Enabled: true Style/VariableInterpolation: Description: >- Don't interpolate global, instance and class variables directly in strings. StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#curlies-interpolate' - Enabled: false + Enabled: true Style/VariableName: Description: 'Use the configured style when naming variables.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#snake-case-symbols-methods-vars' - Enabled: false + Enabled: true Style/WhenThen: Description: 'Use when x then ... for one-line cases.' diff --git a/lib/meta_tags.rb b/lib/meta_tags.rb index 69307f90..7d11fc3e 100644 --- a/lib/meta_tags.rb +++ b/lib/meta_tags.rb @@ -1,3 +1,4 @@ +require 'English' require 'action_controller' require 'action_view' diff --git a/lib/meta_tags/meta_tags_collection.rb b/lib/meta_tags/meta_tags_collection.rb index d7a48ded..ef23718f 100644 --- a/lib/meta_tags/meta_tags_collection.rb +++ b/lib/meta_tags/meta_tags_collection.rb @@ -57,7 +57,7 @@ def with_defaults(defaults = {}) # @return [String] page title. # def full_title(defaults = {}) - with_defaults(defaults) { extract_full_title } + with_defaults(defaults) { extract_full_title } end # Deletes and returns a meta tag value by name. @@ -85,7 +85,7 @@ def extract_full_title site_title = extract(:site) || '' title = extract_title || [] separator = extract_separator - reverse = extract(:reverse) === true + reverse = extract(:reverse) == true TextNormalizer.normalize_title(site_title, title, separator, reverse) end @@ -99,7 +99,7 @@ def extract_title return unless title title = Array(title) - title.each(&:downcase!) if extract(:lowercase) === true + title.each(&:downcase!) if extract(:lowercase) == true title end @@ -108,7 +108,7 @@ def extract_title # @return [String] page title separator. # def extract_separator - if meta_tags[:separator] === false + if meta_tags[:separator] == false # Special case: if separator is hidden, do not display suffix/prefix prefix = separator = suffix = '' else @@ -147,7 +147,7 @@ def extract_noindex # @return [HashWithIndifferentAccess] normalized meta tags list. # def normalize_open_graph(meta_tags) - meta_tags = meta_tags.is_a?(HashWithIndifferentAccess) ? meta_tags.dup : meta_tags.with_indifferent_access + meta_tags = meta_tags.kind_of?(HashWithIndifferentAccess) ? meta_tags.dup : meta_tags.with_indifferent_access meta_tags[:og] = meta_tags.delete(:open_graph) if meta_tags.key?(:open_graph) meta_tags end @@ -160,7 +160,7 @@ def normalize_open_graph(meta_tags) # @return [String] separator segment value. # def extract_separator_section(name, default) - meta_tags[name] === false ? '' : (meta_tags[name] || default) + meta_tags[name] == false ? '' : (meta_tags[name] || default) end # Extracts noindex attribute name and value without deleting it from meta tags list. @@ -170,7 +170,7 @@ def extract_separator_section(name, default) # def extract_noindex_attribute(name) noindex = extract(name) - noindex_name = String === noindex ? noindex : 'robots' + noindex_name = noindex.kind_of?(String) ? noindex : 'robots' noindex_value = noindex ? name.to_s : nil [ noindex_name, noindex_value ] diff --git a/lib/meta_tags/renderer.rb b/lib/meta_tags/renderer.rb index 7859bb6b..6a86d4fd 100644 --- a/lib/meta_tags/renderer.rb +++ b/lib/meta_tags/renderer.rb @@ -42,15 +42,13 @@ def render(view) protected - # Renders charset tag. # # @param [Array] tags a buffer object to store tag in. # def render_charset(tags) - if charset = meta_tags.extract(:charset) - tags << Tag.new(:meta, charset: charset) if charset.present? - end + charset = meta_tags.extract(:charset) + tags << Tag.new(:meta, charset: charset) if charset.present? end # Renders title tag. @@ -68,15 +66,16 @@ def render_title(tags) # @param [Array] tags a buffer object to store tag in. # def render_icon(tags) - if icon = meta_tags.extract(:icon) - if String === icon - tags << Tag.new(:link, rel: 'icon', href: icon, type: 'image/x-icon') - else - icon = [icon] if Hash === icon - icon.each do |icon_params| - icon_params = { rel: 'icon', type: 'image/x-icon' }.with_indifferent_access.merge(icon_params) - tags << Tag.new(:link, icon_params) - end + icon = meta_tags.extract(:icon) + return unless icon + + if icon.kind_of?(String) + tags << Tag.new(:link, rel: 'icon', href: icon, type: 'image/x-icon') + else + icon = [icon] if icon.kind_of?(Hash) + icon.each do |icon_params| + icon_params = { rel: 'icon', type: 'image/x-icon' }.with_indifferent_access.merge(icon_params) + tags << Tag.new(:link, icon_params) end end end @@ -108,9 +107,8 @@ def render_noindex(tags) # @param [Array] tags a buffer object to store tag in. # def render_refresh(tags) - if refresh = meta_tags.extract(:refresh) - tags << Tag.new(:meta, 'http-equiv' => 'refresh', content: refresh.to_s) if refresh.present? - end + refresh = meta_tags.extract(:refresh) + tags << Tag.new(:meta, 'http-equiv' => 'refresh', content: refresh.to_s) if refresh.present? end # Renders alternate link tags. @@ -118,15 +116,16 @@ def render_refresh(tags) # @param [Array] tags a buffer object to store tag in. # def render_alternate(tags) - if alternate = meta_tags.extract(:alternate) - if Hash === alternate - alternate.each do |hreflang, href| - tags << Tag.new(:link, rel: 'alternate', href: href, hreflang: hreflang) if href.present? - end - elsif Array === alternate - alternate.each do |link_params| - tags << Tag.new(:link, { rel: 'alternate' }.with_indifferent_access.merge(link_params)) - end + alternate = meta_tags.extract(:alternate) + return unless alternate + + if alternate.kind_of?(Hash) + alternate.each do |hreflang, href| + tags << Tag.new(:link, rel: 'alternate', href: href, hreflang: hreflang) if href.present? + end + elsif alternate.kind_of?(Array) + alternate.each do |link_params| + tags << Tag.new(:link, { rel: 'alternate' }.with_indifferent_access.merge(link_params)) end end end @@ -136,14 +135,14 @@ def render_alternate(tags) # @param [Array] tags a buffer object to store tag in. # def render_open_search(tags) - if open_search = meta_tags.extract(:open_search) - href = open_search[:href] - title = open_search[:title] - if href.present? - type = "application/opensearchdescription+xml" - tags << Tag.new(:link, rel: 'search', type: type, href: href, title: title) - end - end + open_search = meta_tags.extract(:open_search) + return unless open_search + + href = open_search[:href] + title = open_search[:title] + + type = "application/opensearchdescription+xml" + tags << Tag.new(:link, rel: 'search', type: type, href: href, title: title) if href.present? end # Renders links. @@ -165,11 +164,8 @@ def render_links(tags) # @param [Array] tags a buffer object to store tag in. # def render_hashes(tags, options = {}) - meta_tags.meta_tags.each do |property, data| - if data.is_a?(Hash) - process_hash(tags, property, data, options) - meta_tags.extract(property) - end + meta_tags.meta_tags.keys.each do |property| + render_hash(tags, property, options) end end @@ -179,10 +175,10 @@ def render_hashes(tags, options = {}) # def render_hash(tags, key, options = {}) data = meta_tags.meta_tags[key] - if data.is_a?(Hash) - process_hash(tags, key, data, options) - meta_tags.extract(key) - end + return unless data.kind_of?(Hash) + + process_hash(tags, key, data, options) + meta_tags.extract(key) end # Renders custom meta tags. @@ -226,7 +222,7 @@ def process_tree(tags, property, content, options = {}) def process_hash(tags, property, content, options = {}) content.each do |key, value| key = key.to_s == '_' ? property : "#{property}:#{key}" - value = normalized_meta_tags[value] if value.is_a?(Symbol) + value = normalized_meta_tags[value] if value.kind_of?(Symbol) process_tree(tags, key, value, options) end end diff --git a/lib/meta_tags/text_normalizer.rb b/lib/meta_tags/text_normalizer.rb index 0e4cdeca..c4638372 100644 --- a/lib/meta_tags/text_normalizer.rb +++ b/lib/meta_tags/text_normalizer.rb @@ -89,7 +89,7 @@ def self.strip_tags(string) # @param [String] sep separator to join strings with. # @return [String] input strings joined together using a given separator. # - def self.safe_join(array, sep = $,) + def self.safe_join(array, sep = $OFS) helpers.safe_join(array, sep) end diff --git a/meta-tags.gemspec b/meta-tags.gemspec index ba985f53..ce91b727 100644 --- a/meta-tags.gemspec +++ b/meta-tags.gemspec @@ -27,5 +27,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rspec-html-matchers", "~> 0.8.0" spec.cert_chain = ["certs/kpumuk.pem"] - spec.signing_key = File.expand_path("~/.ssh/gem-kpumuk.pem") if $0 =~ /gem\z/ + spec.signing_key = File.expand_path("~/.ssh/gem-kpumuk.pem") if $PROGRAM_NAME =~ /gem\z/ end