metanorma / atmospheric

International Standard Atmosphere / ICAO Standard Atmosphere (ISA) from ICAO 7488 / ISO 2533
BSD 2-Clause "Simplified" License
1 stars 1 forks source link

Fix some Rubocop complaints #16

Closed newbthenewbd closed 8 months ago

newbthenewbd commented 8 months ago

This reduces the complaint count to a total to 23, which may actually be slightly more problematic to correct:

Inspecting 10 files
.....C....

Offenses:

lib/atmospheric/isa.rb:87:11: C: Use snake_case for method names.
      def temperature_at_layer_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:142:7: C: Assignment Branch Condition size for pressure_layers is too high. [<16, 19, 9> 26.42/15]
      def pressure_layers ...
      ^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:142:7: C: Method has too many lines. [37/10]
      def pressure_layers ...
      ^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:142:7: C: Perceived complexity for pressure_layers is too high. [8/7]
      def pressure_layers ...
      ^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:148:9: C: Block has too many lines. [31/25]
        TEMPERATURE_LAYERS.each_with_index do |_x, i| ...
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:211:7: C: Method has too many lines. [23/10]
      def pressure_from_H(geopotential_alt) ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:211:11: C: Use snake_case for method names.
      def pressure_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:238:11: C: Use snake_case for method names.
      def pressure_from_H_mbar(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:242:11: C: Use snake_case for method names.
      def pressure_from_H_mmhg(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:246:11: C: Use snake_case for method names.
      def p_p_n_from_H(geopotential_alt)
          ^^^^^^^^^^^^
lib/atmospheric/isa.rb:255:11: C: Use snake_case for method names.
      def density_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:262:11: C: Use snake_case for method names.
      def rho_rho_n_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:266:11: C: Use snake_case for method names.
      def root_rho_rho_n_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:273:11: C: Use snake_case for method names.
      def specific_weight_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:285:11: C: Use snake_case for method names.
      def pressure_scale_height_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:293:11: C: Use snake_case for method names.
      def air_number_density_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:308:11: C: Use snake_case for method names.
      def mean_air_particle_speed_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:316:11: C: Use snake_case for method names.
      def mean_free_path_of_air_particles_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:330:11: C: Use snake_case for method names.
      def air_particle_collision_frequency_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:346:11: C: Use snake_case for method names.
      def speed_of_sound_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:362:11: C: Use snake_case for method names.
      def dynamic_viscosity_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:374:11: C: Use snake_case for method names.
      def kinematic_viscosity_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/atmospheric/isa.rb:386:11: C: Use snake_case for method names.
      def thermal_conductivity_from_H(geopotential_alt)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^

10 files inspected, 23 offenses detected

Metanorma PR checklist

newbthenewbd commented 8 months ago

As I mentioned in #14, all the snake_case names that Rubocop thinks badly formatted could have the offending from_H changed to e.g. at_geopotential...

With the then-remaining issues, however, I feel that fixing some of them may actually go contrary to readability?

Take for example this complaint:

lib/atmospheric/isa.rb:211:7: C: Method has too many lines. [23/10]
      def pressure_from_H(geopotential_alt) ...
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Referring to this method:

      # Pressure for a given geopotential altitude `H` (m) above mean sea level
      def pressure_from_H(geopotential_alt)
        i = locate_lower_layer(geopotential_alt)
        lower_temperature_layer = TEMPERATURE_LAYERS[i]
        beta = lower_temperature_layer[:B]
        capital_h_b = lower_temperature_layer[:H]
        capital_t_b = lower_temperature_layer[:T]
        temp = temperature_at_layer_from_H(geopotential_alt)
        p_b = pressure_layers[i]

        if beta != 0
          # Formula (12)
          pressure_formula_beta_nonzero(
            p_b,
            beta,
            capital_t_b,
            geopotential_alt - capital_h_b,
          )
        else
          # Formula (13)
          pressure_formula_beta_zero(
            p_b,
            temp,
            geopotential_alt - capital_h_b,
          )
        end
      end

Can easily be compressed, but is it truly what we want?

ronaldtse commented 8 months ago

Can easily be compressed, but is it truly what we want?

We can add a line to ask Rubocop to ignore that method and get it done with.

ronaldtse commented 8 months ago

Merging first.