Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Woking in Progress] Standarize code #627

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

WaKeMaTTa
Copy link

@WaKeMaTTa WaKeMaTTa commented Apr 3, 2019

Why this pull request?

✔️ Readability
✔️ Maintainability
✔️ Consistent syntax
✔️ More secure (because it helps to prevent usually bad practices)

Todo

  • Install standard gem (including it to Rakefile also)
  • Configure standard.yml
  • Configure travis.yml
    • Add bundle exec rake standard in the script section
  • Run auto-fix bundle exec rake standard:fix
  • Fix manually the issues that auto-fix cannot fix.

Fix this ones manually

Rakefile:25:27: C: Security/Eval: The use of eval is a serious security risk.
gemspecs.map! { |gemspec| eval(IO.read(gemspec)) }
                          ^^^^
Rakefile:117:7: W: Lint/AmbiguousOperator: Ambiguous splat operator. Parenthesize the method arguments if it's surely a splat operator, or add a whitespace to the right of the * if it should be a multiplication.
  run *cmd
      ^
Rakefile:122:7: W: Lint/AmbiguousOperator: Ambiguous splat operator. Parenthesize the method arguments if it's surely a splat operator, or add a whitespace to the right of the * if it should be a multiplication.
  run *cmd
      ^
Rakefile:129:9: W: Lint/AmbiguousOperator: Ambiguous splat operator. Parenthesize the method arguments if it's surely a splat operator, or add a whitespace to the right of the * if it should be a multiplication.
    run *cmd
        ^
nmatrix.gemspec:9:13: C: Security/Eval: The use of eval is a serious security risk.
  gemspec = eval(File.read(gemspec_file))
            ^^^^
lib/nmatrix/fftw.rb:278:11: C: Naming/AccessorMethodName: Do not prefix writer method names with set_.
      def set_input ip
          ^^^^^^^^^
lib/nmatrix/monkeys.rb:55:37: W: Lint/ShadowingOuterLocalVariable: Shadowing outer local variable - shape.
    guess_shape = lambda { |shapey; shape|
                                    ^^^^^
lib/nmatrix/monkeys.rb:127:22: C: Style/CommentedKeyword: Do not place comments on the same line as the module keyword.
module AutoloadPatch #:nodoc
                     ^^^^^^^
lib/nmatrix/mkmf.rb:20:5: C: Style/GlobalVars: Do not introduce global variables.
    $defs.each do |line|
    ^^^^^
lib/nmatrix/mkmf.rb:68:3: C: Style/GlobalVars: Do not introduce global variables.
  $CXX_STANDARD = "c++11"
  ^^^^^^^^^^^^^
lib/nmatrix/mkmf.rb:78:3: C: Style/GlobalVars: Do not introduce global variables.
  $CXX_STANDARD = if version < "4.7.0"
  ^^^^^^^^^^^^^
lib/nmatrix/mkmf.rb:83:33: C: Style/GlobalVars: Do not introduce global variables.
  puts "using C++ standard... #{$CXX_STANDARD}"
                                ^^^^^^^^^^^^^
lib/nmatrix/mkmf.rb:88:1: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS += " -O3 "
^^^^^^^
lib/nmatrix/mkmf.rb:90:1: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS += " -O3 -std=#{$CXX_STANDARD} " #-fmax-errors=10 -save-temps
^^^^^^^^^
lib/nmatrix/mkmf.rb:90:27: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS += " -O3 -std=#{$CXX_STANDARD} " #-fmax-errors=10 -save-temps
                          ^^^^^^^^^^^^^
lib/nmatrix/cruby/math.rb:432:76: C: Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.
      warn "warning: A diagonal element of R in A = QR is close to zero ;" <<
                                                                           ^^
lib/nmatrix/shortcuts.rb:744:5: W: Lint/DuplicateMethods: Method NMatrix.linspace is defined at both lib/nmatrix/shortcuts.rb:646 and lib/nmatrix/shortcuts.rb:744.
    def linspace(base, limit, shape = [100])
    ^^^^^^^^^^^^
lib/nmatrix/shortcuts.rb:797:5: W: Lint/DuplicateMethods: Method NMatrix.logspace is defined at both lib/nmatrix/shortcuts.rb:699 and lib/nmatrix/shortcuts.rb:797.
    def logspace(base, limit, shape = [50], exponent_base: 10)
    ^^^^^^^^^^^^
lib/nmatrix/io/market.rb:214:18: W: Lint/AssignmentInCondition: Wrap assignment in parentheses if intentional
      while line = file.gets
                 ^
lib/nmatrix/io/market.rb:217:15: W: Lint/UselessAssignment: Useless assignment to variable - comment. Use _ or _comment as a variable name to indicate that it won't be used.
        line, comment = line.split("%", 2) # ignore comments
              ^^^^^^^
lib/nmatrix/io/market.rb:226:18: W: Lint/AssignmentInCondition: Wrap assignment in parentheses if intentional
      while line = file.gets
                 ^
lib/nmatrix/io/market.rb:229:15: W: Lint/UselessAssignment: Useless assignment to variable - comment. Use _ or _comment as a variable name to indicate that it won't be used.
        line, comment = line.split("%", 2) # ignore comments
              ^^^^^^^
lib/nmatrix/io/point_cloud.rb:117:18: W: Lint/AssignmentInCondition: Wrap assignment in parentheses if intentional
      while line = f.gets
                 ^
lib/nmatrix/io/point_cloud.rb:118:50: W: Lint/ShadowingOuterLocalVariable: Shadowing outer local variable - f.
        @matrix[i, :*] = line.chomp.split.map { |f| f.send(convert) }
                                                 ^
lib/nmatrix/io/point_cloud.rb:125:19: W: Lint/AmbiguousOperator: Ambiguous splat operator. Parenthesize the method arguments if it's surely a splat operator, or add a whitespace to the right of the * if it should be a multiplication.
    attr_accessor *ENTRIES
                  ^
lib/nmatrix/io/point_cloud.rb:134:18: W: Lint/AssignmentInCondition: Wrap assignment in parentheses if intentional
      while line = f.gets
                 ^
lib/nmatrix/io/point_cloud.rb:140:49: W: Lint/ShadowingOuterLocalVariable: Shadowing outer local variable - f.
          line.split.tap { |t| t.shift }.map { |f|
                                                ^
lib/nmatrix/io/harwell_boeing.rb:164:31: W: Lint/UselessAssignment: Useless assignment to variable - c. Use - instead of -=.
          @col_ptrs.map! {|c| c -= 1}
                              ^
lib/nmatrix/io/harwell_boeing.rb:176:34: W: Lint/UselessAssignment: Useless assignment to variable - r. Use - instead of -=.
          @row_indices.map! {|r| r -= 1}
                                 ^
lib/nmatrix/io/mat5_reader.rb:104:9: W: Lint/UnreachableCode: Unreachable code detected.
        packedio << [info, {bytes: padded_bytes}.merge(options)]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/io/mat5_reader.rb:278:9: W: Lint/UselessAssignment: Useless assignment to variable - from_dtype.
        from_dtype = MatReader::MDTYPE_TO_DTYPE[real_part.tag.data_type]
        ^^^^^^^^^^
lib/nmatrix/homogeneous.rb:134:9: C: Style/IdenticalConditionalBranches: Move NMatrix.eye(4, opts) out of the conditional.
        NMatrix.eye(4, opts)
        ^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/homogeneous.rb:136:9: C: Style/IdenticalConditionalBranches: Move NMatrix.eye(4, opts) out of the conditional.
        NMatrix.eye(4, opts)
        ^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/jruby/slice.rb:83:11: W: Lint/UselessAssignment: Useless assignment to variable - s.
          s = @s.toArray.to_a
          ^
lib/nmatrix/jruby/slice.rb:100:7: W: Lint/UselessAssignment: Useless assignment to variable - result.
      result = []
      ^^^^^^
lib/nmatrix/jruby/slice.rb:130:7: C: Naming/VariableName: Use snake_case for variable names.
      resultShape = Array.new(dim)
      ^^^^^^^^^^^
lib/nmatrix/jruby/slice.rb:145:7: W: Lint/UselessAssignment: Useless assignment to variable - temp.
      temp = []
      ^^^^
lib/nmatrix/jruby/slice.rb:180:70: C: Style/CommentedKeyword: Do not place comments on the same line as the def keyword.
  def dense_storage_coords(s, slice_pos, coords_out, stride, offset) # array, int, array
                                                                     ^^^^^^^^^^^^^^^^^^^
lib/nmatrix/jruby/operators.rb:68:10: C: Naming/BinaryOperatorParameterName: When defining the ** operator, name its argument other.
  def ** val
         ^^^
lib/nmatrix/jruby/nmatrix_java.rb:42:11: C: Style/IfInsideElse: Convert if nested inside else to elsif.
          if args.length > 1
          ^^
lib/nmatrix/jruby/nmatrix_java.rb:129:7: C: Naming/MethodName: Use snake_case for method names.
  def twoDMat
      ^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:133:3: W: Lint/DuplicateMethods: Method NMatrix#dtype is defined at both lib/nmatrix/jruby/nmatrix_java.rb:19 and lib/nmatrix/jruby/nmatrix_java.rb:133.
  attr_reader :dtype
  ^^^^^^^^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:140:3: W: Lint/DuplicateMethods: Method NMatrix#stype is defined at both lib/nmatrix/jruby/nmatrix_java.rb:19 and lib/nmatrix/jruby/nmatrix_java.rb:140.
  def stype
  ^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:182:5: W: Lint/Void: Variable to_return used in void context.
    to_return
    ^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:220:3: W: Lint/DuplicateMethods: Method NMatrix#shape is defined at both lib/nmatrix/jruby/nmatrix_java.rb:19 and lib/nmatrix/jruby/nmatrix_java.rb:220.
  attr_reader :shape
  ^^^^^^^^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:236:2: W: Layout/DefEndAlignment: end at 236, 1 is not aligned with def at 222, 2.
 end
 ^^^
lib/nmatrix/jruby/nmatrix_java.rb:252:7: W: Lint/UnreachableCode: Unreachable code detected.
      return nil
      ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:267:7: W: Lint/UnreachableCode: Unreachable code detected.
      return nil
      ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:342:5: W: Lint/UselessAssignment: Useless assignment to variable - shape_copy.
    shape_copy = Array.new(dim)
    ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:372:5: W: Lint/UselessAssignment: Useless assignment to variable - shape_copy.
    shape_copy = Array.new(dim)
    ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:410:5: W: Lint/UselessAssignment: Useless assignment to variable - shape_copy.
    shape_copy = Array.new(dim)
    ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:414:11: C: Style/IdenticalConditionalBranches: Move dense_storage_coords(nmatrix, k, coords, stride, offset) out of the conditional.
          dense_storage_coords(nmatrix, k, coords, stride, offset)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:418:11: C: Style/IdenticalConditionalBranches: Move dense_storage_coords(nmatrix, k, coords, stride, offset) out of the conditional.
          dense_storage_coords(nmatrix, k, coords, stride, offset)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:436:5: W: Lint/UselessAssignment: Useless assignment to variable - shape_copy.
    shape_copy = Array.new(dim)
    ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:474:10: C: Naming/BinaryOperatorParameterName: When defining the == operator, name its argument other.
  def ==(otherNmatrix)
         ^^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:474:10: C: Naming/VariableName: Use snake_case for variable names.
  def ==(otherNmatrix)
         ^^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:501:5: C: Naming/VariableName: Use snake_case for variable names.
    resultArray = Array.new(lha.length)
    ^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:506:9: W: Lint/UnreachableCode: Unreachable code detected.
        return nil
        ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:512:11: W: Lint/UnreachableCode: Unreachable code detected.
          return nil
          ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:530:5: C: Naming/VariableName: Use snake_case for variable names.
    resultArray = Array.new(lha.length)
    ^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:535:9: W: Lint/UnreachableCode: Unreachable code detected.
        return nil
        ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:541:11: W: Lint/UnreachableCode: Unreachable code detected.
          return nil
          ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:559:5: C: Naming/VariableName: Use snake_case for variable names.
    resultArray = Array.new(lha.length)
    ^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:564:9: W: Lint/UnreachableCode: Unreachable code detected.
        return nil
        ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:570:11: W: Lint/UnreachableCode: Unreachable code detected.
          return nil
          ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:588:5: C: Naming/VariableName: Use snake_case for variable names.
    resultArray = Array.new(lha.length)
    ^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:593:9: W: Lint/UnreachableCode: Unreachable code detected.
        return nil
        ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:599:11: W: Lint/UnreachableCode: Unreachable code detected.
          return nil
          ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:617:5: C: Naming/VariableName: Use snake_case for variable names.
    resultArray = Array.new(lha.length)
    ^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:622:9: W: Lint/UnreachableCode: Unreachable code detected.
        return nil
        ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:628:11: W: Lint/UnreachableCode: Unreachable code detected.
          return nil
          ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:646:5: C: Naming/VariableName: Use snake_case for variable names.
    resultArray = Array.new(lha.length)
    ^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:651:9: W: Lint/UnreachableCode: Unreachable code detected.
        return nil
        ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:657:11: W: Lint/UnreachableCode: Unreachable code detected.
          return nil
          ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:682:9: W: Lint/UnreachableCode: Unreachable code detected.
        return nil
        ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:687:9: W: Lint/UnreachableCode: Unreachable code detected.
        return nil
        ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:696:7: C: Naming/VariableName: Use snake_case for variable names.
      twoDMat = self.twoDMat.multiply(other.twoDMat)
      ^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:715:11: C: Style/IdenticalConditionalBranches: Move eps = 0 out of the conditional.
          eps = 0
          ^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:716:11: C: Style/IdenticalConditionalBranches: Move is_symmetric = MatrixUtils.isSymmetric(twoDMat, eps) out of the conditional.
          is_symmetric = MatrixUtils.isSymmetric(twoDMat, eps)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:718:11: C: Style/IdenticalConditionalBranches: Move eps = 0 out of the conditional.
          eps = 0
          ^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:719:11: C: Style/IdenticalConditionalBranches: Move is_symmetric = MatrixUtils.isSymmetric(twoDMat, eps) out of the conditional.
          is_symmetric = MatrixUtils.isSymmetric(twoDMat, eps)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:722:7: C: Style/EmptyElse: Redundant else-clause.
      else
      ^^^^
lib/nmatrix/jruby/nmatrix_java.rb:749:7: W: Lint/UnreachableCode: Unreachable code detected.
      return nil
      ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:756:7: C: Naming/VariableName: Use snake_case for variable names.
      twoDMat = MatrixUtils.inverse(matrix.twoDMat)
      ^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:771:7: W: Lint/UnreachableCode: Unreachable code detected.
      return nil
      ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:773:5: W: Lint/UselessAssignment: Useless assignment to variable - to_return.
    to_return = nil
    ^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:777:7: C: Naming/VariableName: Use snake_case for variable names.
      twoDMat = MatrixUtils.inverse(self.twoDMat)
      ^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:792:7: W: Lint/UnreachableCode: Unreachable code detected.
      return nil
      ^^^^^^^^^^
lib/nmatrix/jruby/nmatrix_java.rb:799:7: C: Naming/VariableName: Use snake_case for variable names.
      twoDMat = MatrixUtils.inverse(self.twoDMat)
      ^^^^^^^
lib/nmatrix/jruby/math.rb:182:7: C: Naming/VariableName: Use snake_case for variable names.
      twoDMat = cholesky.getLT
      ^^^^^^^
lib/nmatrix/jruby/math.rb:187:7: C: Naming/VariableName: Use snake_case for variable names.
      twoDMat = cholesky.getL
      ^^^^^^^
lib/nmatrix/jruby/math.rb:216:5: C: Naming/VariableName: Use snake_case for variable names.
    twoDMat = cholesky.getL
    ^^^^^^^
lib/nmatrix/jruby/math.rb:219:5: C: Naming/VariableName: Use snake_case for variable names.
    twoDMat = cholesky.getLT
    ^^^^^^^
lib/nmatrix/jruby/math.rb:242:5: C: Naming/VariableName: Use snake_case for variable names.
    twoDMat = LUDecomposition.new(self.twoDMat).getP
    ^^^^^^^
lib/nmatrix/jruby/math.rb:270:5: C: Naming/VariableName: Use snake_case for variable names.
    qtwoDMat = qrdecomp.getQ
    ^^^^^^^^
lib/nmatrix/jruby/math.rb:274:5: C: Naming/VariableName: Use snake_case for variable names.
    rtwoDMat = qrdecomp.getR
    ^^^^^^^^
lib/nmatrix/jruby/math.rb:331:5: W: Lint/UselessAssignment: Useless assignment to variable - x.
    x    = b.clone
    ^
lib/nmatrix/jruby/math.rb:332:5: W: Lint/UselessAssignment: Useless assignment to variable - n.
    n    = shape[0]
    ^
lib/nmatrix/jruby/math.rb:333:5: W: Lint/UselessAssignment: Useless assignment to variable - nrhs.
    nrhs = b.shape[1]
    ^^^^
lib/nmatrix/nmatrix.rb:42:3: C: Style/IfInsideElse: Convert if nested inside else to elsif.
  if File.exist?("lib/nmatrix/nmatrix.so") # || File.exist?("lib/nmatrix/nmatrix.bundle")
  ^^
lib/nmatrix/nmatrix.rb:650:7: C: Style/IfInsideElse: Convert if nested inside else to elsif.
      if jruby?
      ^^
lib/nmatrix/nmatrix.rb:653:9: C: Naming/VariableName: Use snake_case for variable names.
        twoDMat = self.twoDMat.transpose
        ^^^^^^^
lib/nmatrix/nmatrix.rb:953:3: C: Style/MethodMissingSuper: When using method_missing, fall back on super.
  def method_missing name, *args, &block #:nodoc: ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/nmatrix.rb:953:3: C: Style/MissingRespondToMissing: When using method_missing, define respond_to_missing?.
  def method_missing name, *args, &block #:nodoc: ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/nmatrix.rb:1058:81: C: Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.
        ary << "ija:#{__yale_ary__to_s(:ija)}" << "ia:#{__yale_ary__to_s(:ia)}" <<
                                                                                ^^
lib/nmatrix/nmatrix.rb:1059:103: C: Style/LineEndConcatenation: Use \ instead of + or << to concatenate those strings.
          "ja:#{__yale_ary__to_s(:ja)}" << "a:#{__yale_ary__to_s(:a)}" << "d:#{__yale_ary__to_s(:d)}" <<
                                                                                                      ^^
lib/nmatrix/nmatrix.rb:1070:136: W: Lint/UselessAssignment: Useless assignment to variable - p. Use * instead of *=.
    raise(ArgumentError, "reshape cannot resize; size of new and old matrices must match") unless size == new_shape.inject(1) { |p, i| p *= i }
                                                                                                                                       ^
lib/nmatrix/math.rb:106:7: C: Style/IdenticalConditionalBranches: Move cloned.invert! out of the conditional.
      cloned.invert!
      ^^^^^^^^^^^^^^
lib/nmatrix/math.rb:109:7: C: Style/IdenticalConditionalBranches: Move cloned.invert! out of the conditional.
      cloned.invert!
      ^^^^^^^^^^^^^^
lib/nmatrix/math.rb:157:7: C: Style/IdenticalConditionalBranches: Move cloned.exact_inverse! out of the conditional.
      cloned.exact_inverse!
      ^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/math.rb:160:7: C: Style/IdenticalConditionalBranches: Move cloned.exact_inverse! out of the conditional.
      cloned.exact_inverse!
      ^^^^^^^^^^^^^^^^^^^^^
lib/nmatrix/math.rb:328:29: W: Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.
      return two_matrix_norm (type == -2)
                            ^
lib/nmatrix/math.rb:330:29: W: Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.
      return one_matrix_norm (type == -1)
                            ^
lib/nmatrix/math.rb:334:29: W: Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.
      return inf_matrix_norm (type == :'-inf' || type == :'-infinity')
                            ^
lib/nmatrix/math.rb:438:16: W: Lint/UselessAssignment: Useless assignment to variable - getby.
      each_row(getby = :copy) do |selfr|
               ^^^^^
lib/nmatrix/math.rb:648:52: W: Lint/UselessAssignment: Useless assignment to variable - sum. Use + instead of +=.
      col_sums << col(i).inject(0) { |sum, number| sum += number.abs}
                                                   ^^^
lib/nmatrix/math.rb:661:52: W: Lint/UselessAssignment: Useless assignment to variable - sum. Use + instead of +=.
      row_sums << row(i).inject(0) { |sum, number| sum += number.abs}
                                                   ^^^
spec/blas_spec.rb:33:12: E: Lint/Syntax: unexpected token tCOMMA
(Using Ruby 2.5 parser; configure using TargetRubyVersion parameter, under AllCops)
   :object],.each do |dtype|
           ^
spec/blas_spec.rb:210:1: E: Lint/Syntax: unexpected token kEND
(Using Ruby 2.5 parser; configure using TargetRubyVersion parameter, under AllCops)
end
^^^
spec/stat_spec.rb:131:43: W: Lint/AmbiguousBlockAssociation: Parenthesize the param nm_1d.map { |e| e**2 } to make sure that the block will be associated with the nm_1d.map method call.
          expect(en.each { |e| e**2 }).to eq nm_1d.map { |e| e**2 } unless stype == :yale
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^
spec/stat_spec.rb:133:43: W: Lint/AmbiguousBlockAssociation: Parenthesize the param nm_2d.map { |e| e**2 } to make sure that the block will be associated with the nm_2d.map method call.
          expect(en.each { |e| e**2 }).to eq nm_2d.map { |e| e**2 }
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^
spec/stat_spec.rb:140:39: W: Lint/Void: Operator + used in void context.
            expect(en.each { |a, e| a + e }.to_f).to eq 12
                                      ^
spec/stat_spec.rb:143:37: W: Lint/Void: Operator + used in void context.
          expect(en.each { |a, e| a + e }).to eq NMatrix[[2.0], [6.0], stype: stype]
                                    ^
spec/math_spec.rb:154:75: W: Lint/UselessAssignment: Useless assignment to variable - e.
                    expect(@m.send(meth)).to eq N.new(@size, @a.map { |e| e = Complex(e.real.send(meth), e.imag.send(meth)) }, dtype: dtype, stype: stype)
                                                                          ^
spec/math_spec.rb:433:14: W: Lint/UselessAssignment: Useless assignment to variable - r. Use _ or _r as a variable name to indicate that it won't be used.
          q, r = a.factorize_qr
             ^
spec/math_spec.rb:524:11: C: Style/IdenticalConditionalBranches: Move begin
            expect(a.dot(a.pinv)).to be_within(err).of(b)
          rescue NotImplementedError
            pending "Suppressing a NotImplementedError when the atlas plugin is not available"
          end out of the conditional.
          begin ...
          ^^^^^
spec/math_spec.rb:534:11: C: Style/IdenticalConditionalBranches: Move begin
            expect(a.dot(a.pinv)).to be_within(err).of(b)
          rescue NotImplementedError
            pending "Suppressing a NotImplementedError when the atlas plugin is not available"
          end out of the conditional.
          begin ...
          ^^^^^
spec/math_spec.rb:549:11: C: Style/IdenticalConditionalBranches: Move begin
            b = a.pinv # pseudo inverse
            expect(a.dot(b.dot(a))).to be_within(err).of(a)
            expect(b.dot(a.dot(b))).to be_within(err).of(b)
          rescue NotImplementedError
            pending "Suppressing a NotImplementedError when the atlas plugin is not available"
          end out of the conditional.
          begin ...
          ^^^^^
spec/math_spec.rb:560:11: C: Style/IdenticalConditionalBranches: Move begin
            b = a.pinv # pseudo inverse
            expect(a.dot(b.dot(a))).to be_within(err).of(a)
            expect(b.dot(a.dot(b))).to be_within(err).of(b)
          rescue NotImplementedError
            pending "Suppressing a NotImplementedError when the atlas plugin is not available"
          end out of the conditional.
          begin ...
          ^^^^^
spec/math_spec.rb:1200:11: C: Naming/VariableName: Use snake_case for variable names.
          @matrix_norm_TOLERANCE = 1.0e-10
          ^^^^^^^^^^^^^^^^^^^^^^
spec/02_slice_spec.rb:365:15: W: Lint/UselessAssignment: Useless assignment to variable - n.
              n = stype_matrix[1..2, 0..1]
              ^
spec/elementwise_spec.rb:78:7: W: Lint/UselessAssignment: Useless assignment to variable - m.
      m = NMatrix.new(2, stype: :yale, dtype: :int64)
      ^
spec/00_nmatrix_spec.rb:129:5: W: Lint/UselessAssignment: Useless assignment to variable - m.
    m = NMatrix.new(:dense, [3, 3], [0, 0, 1, 0, 2, 0, 3, 4, 5], :int64)
    ^
spec/00_nmatrix_spec.rb:430:20: W: Lint/Void: Operator + used in void context.
    t.each { |x| x + 0 }
                   ^
spec/00_nmatrix_spec.rb:579:16: W: Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.
        context ("#{left}?#{right}") do
               ^
spec/00_nmatrix_spec.rb:610:15: C: Style/CommentedKeyword: Do not place comments on the same line as the end keyword.
          end # yale must have dimension 2
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec/shortcuts_spec.rb:150:7: W: Lint/UselessAssignment: Useless assignment to variable - m.
      m = NMatrix.random(2, dtype: :complex128)
      ^
spec/nmatrix_yale_spec.rb:56:7: W: Lint/UselessAssignment: Useless assignment to variable - x.
      x = n + m
      ^
spec/nmatrix_yale_spec.rb:129:94: C: Security/YAMLLoad: Prefer using YAML.safe_load over YAML.load.
      associations = File.open("spec/nmatrix_yale_resize_test_associations.yaml") { |y| YAML.load(y) }
                                                                                             ^^^^
spec/nmatrix_yale_spec.rb:276:22: W: Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.
          STDERR.puts (a.yale_ja_d_keys_at(ai) & b.yale_ja_d_keys_at(bi)).inspect
                     ^
ext/nmatrix_lapacke/extconf.rb:37:1: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include", $CFLAGS].join(" ")
^^^^^^^
ext/nmatrix_lapacke/extconf.rb:37:92: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include", $CFLAGS].join(" ")
                                                                                           ^^^^^^^
ext/nmatrix_lapacke/extconf.rb:38:1: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include", $CXXFLAGS].join(" ")
^^^^^^^^^
ext/nmatrix_lapacke/extconf.rb:38:94: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include", $CXXFLAGS].join(" ")
                                                                                             ^^^^^^^^^
ext/nmatrix_lapacke/extconf.rb:39:1: C: Style/GlobalVars: Do not introduce global variables.
$CPPFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include", $CPPFLAGS].join(" ")
^^^^^^^^^
ext/nmatrix_lapacke/extconf.rb:39:94: C: Style/GlobalVars: Do not introduce global variables.
$CPPFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include", $CPPFLAGS].join(" ")
                                                                                             ^^^^^^^^^
ext/nmatrix_lapacke/extconf.rb:44:1: C: Style/GlobalVars: Do not introduce global variables.
$objs = basenames.map { |b| "#{b}.o"   }
^^^^^
ext/nmatrix_lapacke/extconf.rb:45:1: C: Style/GlobalVars: Do not introduce global variables.
$srcs = basenames.map { |b| "#{b}.cpp" }
^^^^^
ext/nmatrix_lapacke/extconf.rb:61:1: C: Style/GlobalVars: Do not introduce global variables.
$libs += " -llapack "
^^^^^
ext/nmatrix_fftw/extconf.rb:31:1: W: Lint/UselessAssignment: Useless assignment to variable - fftw_srcdir. Did you mean fftw_incdir?
fftw_srcdir = RbConfig::CONFIG["srcdir"]
^^^^^^^^^^^
ext/nmatrix_fftw/extconf.rb:33:1: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include", $CFLAGS].join(" ")
^^^^^^^
ext/nmatrix_fftw/extconf.rb:33:92: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include", $CFLAGS].join(" ")
                                                                                           ^^^^^^^
ext/nmatrix_fftw/extconf.rb:34:1: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include -std=c++11", $CXXFLAGS].join(" ")
^^^^^^^^^
ext/nmatrix_fftw/extconf.rb:34:105: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include -std=c++11", $CXXFLAGS].join(" ")
                                                                                                        ^^^^^^^^^
ext/nmatrix_fftw/extconf.rb:35:1: C: Style/GlobalVars: Do not introduce global variables.
$CPPFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include -std=c++11", $CPPFLAGS].join(" ")
^^^^^^^^^
ext/nmatrix_fftw/extconf.rb:35:105: C: Style/GlobalVars: Do not introduce global variables.
$CPPFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix -I$(srcdir)/lapacke/include -std=c++11", $CPPFLAGS].join(" ")
                                                                                                        ^^^^^^^^^
ext/nmatrix_fftw/extconf.rb:37:1: W: Lint/UselessAssignment: Useless assignment to variable - flags.
flags = " --include=#{fftw_incdir} --libdir=#{fftw_libdir}"
^^^^^
ext/nmatrix_fftw/extconf.rb:40:3: C: Style/GlobalVars: Do not introduce global variables.
  $CFLAGS += [" -lfftw3 -lm #{$CFLAGS} #{$flags}"].join(" ")
  ^^^^^^^
ext/nmatrix_fftw/extconf.rb:40:31: C: Style/GlobalVars: Do not introduce global variables.
  $CFLAGS += [" -lfftw3 -lm #{$CFLAGS} #{$flags}"].join(" ")
                              ^^^^^^^
ext/nmatrix_fftw/extconf.rb:40:42: C: Style/GlobalVars: Do not introduce global variables.
  $CFLAGS += [" -lfftw3 -lm #{$CFLAGS} #{$flags}"].join(" ")
                                         ^^^^^^
ext/nmatrix/extconf.rb:30:1: C: Style/GlobalVars: Do not introduce global variables.
$INSTALLFILES = [
^^^^^^^^^^^^^
ext/nmatrix/extconf.rb:39:3: C: Style/GlobalVars: Do not introduce global variables.
  $INSTALLFILES << ["libnmatrix.a", "$(archdir)"]
  ^^^^^^^^^^^^^
ext/nmatrix/extconf.rb:43:1: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS = ["-Wall -Werror=return-type", $CFLAGS].join(" ")
^^^^^^^
ext/nmatrix/extconf.rb:43:41: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS = ["-Wall -Werror=return-type", $CFLAGS].join(" ")
                                        ^^^^^^^
ext/nmatrix/extconf.rb:44:1: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS = ["-Wall -Werror=return-type", $CXXFLAGS].join(" ")
^^^^^^^^^
ext/nmatrix/extconf.rb:44:43: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS = ["-Wall -Werror=return-type", $CXXFLAGS].join(" ")
                                          ^^^^^^^^^
ext/nmatrix/extconf.rb:45:1: C: Style/GlobalVars: Do not introduce global variables.
$CPPFLAGS = ["-Wall -Werror=return-type", $CPPFLAGS].join(" ")
^^^^^^^^^
ext/nmatrix/extconf.rb:45:43: C: Style/GlobalVars: Do not introduce global variables.
$CPPFLAGS = ["-Wall -Werror=return-type", $CPPFLAGS].join(" ")
                                          ^^^^^^^^^
ext/nmatrix/extconf.rb:49:1: C: Style/GlobalVars: Do not introduce global variables.
$objs = basenames.map { |b| "#{b}.o"   }
^^^^^
ext/nmatrix/extconf.rb:50:1: C: Style/GlobalVars: Do not introduce global variables.
$srcs = basenames.map { |b| "#{b}.cpp" }
^^^^^
ext/nmatrix_atlas/extconf.rb:37:1: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix", $CFLAGS].join(" ")
^^^^^^^
ext/nmatrix_atlas/extconf.rb:37:64: C: Style/GlobalVars: Do not introduce global variables.
$CFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix", $CFLAGS].join(" ")
                                                               ^^^^^^^
ext/nmatrix_atlas/extconf.rb:38:1: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix", $CXXFLAGS].join(" ")
^^^^^^^^^
ext/nmatrix_atlas/extconf.rb:38:66: C: Style/GlobalVars: Do not introduce global variables.
$CXXFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix", $CXXFLAGS].join(" ")
                                                                 ^^^^^^^^^
ext/nmatrix_atlas/extconf.rb:39:1: C: Style/GlobalVars: Do not introduce global variables.
$CPPFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix", $CPPFLAGS].join(" ")
^^^^^^^^^
ext/nmatrix_atlas/extconf.rb:39:66: C: Style/GlobalVars: Do not introduce global variables.
$CPPFLAGS = ["-Wall -Werror=return-type -I$(srcdir)/../nmatrix", $CPPFLAGS].join(" ")
                                                                 ^^^^^^^^^
ext/nmatrix_atlas/extconf.rb:44:1: C: Style/GlobalVars: Do not introduce global variables.
$objs = basenames.map { |b| "#{b}.o"   }
^^^^^
ext/nmatrix_atlas/extconf.rb:45:1: C: Style/GlobalVars: Do not introduce global variables.
$srcs = basenames.map { |b| "#{b}.cpp" }
^^^^^
ext/nmatrix_atlas/extconf.rb:73:3: C: Style/GlobalVars: Do not introduce global variables.
  $libs += " -lclapack "
  ^^^^^
ext/nmatrix_atlas/extconf.rb:113:1: C: Style/GlobalVars: Do not introduce global variables.
$libs += " -llapack -lcblas -latlas "
^^^^^

@WaKeMaTTa WaKeMaTTa force-pushed the master-standarize-code-using-standard-gem branch from dde1123 to 9a8c821 Compare April 3, 2019 20:57
@WaKeMaTTa WaKeMaTTa force-pushed the master-standarize-code-using-standard-gem branch from 9a8c821 to 86e568d Compare April 3, 2019 21:09
@WaKeMaTTa WaKeMaTTa force-pushed the master-standarize-code-using-standard-gem branch from f44f2c7 to 17bc088 Compare April 3, 2019 21:12
@WaKeMaTTa WaKeMaTTa changed the title Standarize code using standard gem [WIP] Standarize code Apr 3, 2019
@WaKeMaTTa WaKeMaTTa marked this pull request as ready for review April 3, 2019 21:54
@WaKeMaTTa WaKeMaTTa changed the title [WIP] Standarize code [Woking in Progress] Standarize code Apr 3, 2019
@WaKeMaTTa WaKeMaTTa force-pushed the master-standarize-code-using-standard-gem branch from 48ae7fd to fb504a0 Compare April 3, 2019 21:56
['nmatrix_config.h', '$(archdir)'],
['nm_memory.h' , '$(archdir)'],
['ruby_constants.h', '$(archdir)']
["nmatrix.h", "$(archdir)"],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should leave the single quote, because the double quote is use when you want to do an interpolation. WDYT? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standard gem decides to use "double quotes" then we use "double quotes".

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok 👍

Dir.mkdir("data") unless Dir.exists?("data")
Dir.mkdir("util") unless Dir.exists?("util")
Dir.mkdir("storage") unless Dir.exists?("storage")
Dir.mkdir("data") unless Dir.exist?("data")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

directories = %w(data util storage yale list dense)

# if a directory not exist, it is create
directories.each do |directory|
  Dir.mkdir(directory) unless Dir.exist?(directory)
end

WDYT? 🤔

raise(ArgumentError, 'Expected dense NMatrices as first two arguments.') \
unless a.is_a?(NMatrix) and b.is_a? \
(NMatrix) and a.stype == :dense and b.stype == :dense
raise(ArgumentError, "Expected dense NMatrices as first two arguments.") \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could separate these validations into multiple functions to make this function more readable:

def gemm(.....)
  ...
  validate_argument?(a)
  validate_argument?(b)
  ...
end

private

def validate_argument(matrix)
  nmatrix?(matrix) && dense_stype?(matrix)
end

def nmatrix?(matrix)
  message = 'Expected NMatrices object as first two arguments.'
  raise(ArgumentError, message) unless matrix.is_a?(NMatrix)
end

def dense_stype?(matrix)
  message = 'Expected dense NMatrices as first two arguments.'
  raise(ArgumentError, message) unless (matrix.stype == :dense) 
end

WDYT? 🤔

@rubyFeedback
Copy link

This is why a project has to maintain maximum consistency.

Ruby is very flexible but this can negatively affect productivity,
e. g. when we have code such as:

gemspecs.map! { |gemspec| eval(IO.read(gemspec)) }

It does not seem to really necessary to write code like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants