diff --git a/.rubocop.yml b/.rubocop.yml index 4fc00db..9daa722 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,13 +1,184 @@ -Style/NumericLiterals: +AllCops: + SuggestExtensions: false + +Gemspec/RequiredRubyVersion: + Exclude: + - 'open-weather-ruby-client.gemspec' + +Naming/FileName: + Exclude: + - 'lib/open-weather-ruby-client.rb' + +Gemspec/DevelopmentDependencies: + Enabled: false +Gemspec/RequireMFA: Enabled: false +Gemspec/DeprecatedAttributeAssignment: + Enabled: true +Style/NumericLiterals: + Enabled: false Style/ModuleFunction: Enabled: false - Style/Documentation: Enabled: false - Metrics: Enabled: false - -inherit_from: .rubocop_todo.yml +Layout/LineContinuationLeadingSpace: + Enabled: true +Layout/LineContinuationSpacing: + Enabled: true +Layout/LineEndStringConcatenationIndentation: + Enabled: true +Layout/SpaceBeforeBrackets: + Enabled: true +Lint/AmbiguousAssignment: + Enabled: true +Lint/AmbiguousOperatorPrecedence: + Enabled: true +Lint/AmbiguousRange: + Enabled: true +Lint/ConstantOverwrittenInRescue: + Enabled: true +Lint/DeprecatedConstants: + Enabled: true +Lint/DuplicateBranch: + Enabled: true +Lint/DuplicateMagicComment: + Enabled: true +Lint/DuplicateRegexpCharacterClassElement: + Enabled: true +Lint/EmptyBlock: + Enabled: true +Lint/EmptyClass: + Enabled: true +Lint/EmptyInPattern: + Enabled: true +Lint/IncompatibleIoSelectWithFiberScheduler: + Enabled: true +Lint/LambdaWithoutLiteralBlock: + Enabled: true +Lint/NoReturnInBeginEndBlocks: + Enabled: true +Lint/NonAtomicFileOperation: + Enabled: true +Lint/NumberedParameterAssignment: + Enabled: true +Lint/OrAssignmentToConstant: + Enabled: true +Lint/RedundantDirGlobSort: + Enabled: true +Lint/RefinementImportMethods: + Enabled: true +Lint/RequireRangeParentheses: + Enabled: true +Lint/RequireRelativeSelfPath: + Enabled: true +Lint/SymbolConversion: + Enabled: true +Lint/ToEnumArguments: + Enabled: true +Lint/TripleQuotes: + Enabled: true +Lint/UnexpectedBlockArity: + Enabled: true +Lint/UnmodifiedReduceAccumulator: + Enabled: true +Lint/UselessRescue: + Enabled: true +Lint/UselessRuby2Keywords: + Enabled: true +Naming/BlockForwarding: + Enabled: true +Security/CompoundHash: + Enabled: true +Security/IoMethods: + Enabled: true +Style/ArgumentsForwarding: + Enabled: true +Style/ArrayIntersect: + Enabled: true +Style/CollectionCompact: + Enabled: true +Style/ComparableClamp: + Enabled: true +Style/ConcatArrayLiterals: + Enabled: true +Style/DirEmpty: + Enabled: true +Style/DocumentDynamicEvalDefinition: + Enabled: true +Style/EmptyHeredoc: + Enabled: true +Style/EndlessMethod: + Enabled: true +Style/EnvHome: + Enabled: true +Style/FetchEnvVar: + Enabled: true +Style/FileEmpty: + Enabled: true +Style/FileRead: + Enabled: true +Style/FileWrite: + Enabled: true +Style/HashConversion: + Enabled: true +Style/HashExcept: + Enabled: true +Style/IfWithBooleanLiteralBranches: + Enabled: true +Style/InPatternThen: + Enabled: true +Style/MagicCommentFormat: + Enabled: true +Style/MapCompactWithConditionalBlock: + Enabled: true +Style/MapToHash: + Enabled: true +Style/MapToSet: + Enabled: true +Style/MinMaxComparison: + Enabled: true +Style/MultilineInPatternThen: + Enabled: true +Style/NegatedIfElseCondition: + Enabled: true +Style/NestedFileDirname: + Enabled: true +Style/NilLambda: + Enabled: true +Style/NumberedParameters: + Enabled: true +Style/NumberedParametersLimit: + Enabled: true +Style/ObjectThen: + Enabled: true +Style/OpenStructUse: + Enabled: true +Style/OperatorMethodCall: + Enabled: true +Style/QuotedSymbols: + Enabled: true +Style/RedundantArgument: + Enabled: true +Style/RedundantConstantBase: + Enabled: true +Style/RedundantDoubleSplatHashBraces: + Enabled: true +Style/RedundantEach: + Enabled: true +Style/RedundantHeredocDelimiterQuotes: + Enabled: true +Style/RedundantInitialize: + Enabled: true +Style/RedundantSelfAssignmentBranch: + Enabled: true +Style/RedundantStringEscape: + Enabled: true +Style/SelectByRegexp: + Enabled: true +Style/StringChars: + Enabled: true +Style/SwapValues: + Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml deleted file mode 100644 index d65d3e8..0000000 --- a/.rubocop_todo.yml +++ /dev/null @@ -1,44 +0,0 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2023-03-20 09:58:58 UTC using RuboCop version 1.48.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -# Offense count: 1 -# Configuration parameters: Severity, Include. -# Include: **/*.gemspec -Gemspec/RequiredRubyVersion: - Exclude: - - 'open-weather-ruby-client.gemspec' - -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowedMethods. -# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal? -Lint/RedundantSafeNavigation: - Exclude: - - 'lib/open_weather/endpoints/stations.rb' - -# Offense count: 1 -# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. -# CheckDefinitionPathHierarchyRoots: lib, spec, test, src -# 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 -Naming/FileName: - Exclude: - - 'lib/open-weather-ruby-client.rb' - -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -Style/GlobalStdStream: - Exclude: - - 'lib/open_weather/logger.rb' - - 'spec/open_weather/client_spec.rb' - -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. -# URISchemes: http, https -Layout/LineLength: - Max: 181 diff --git a/CHANGELOG.md b/CHANGELOG.md index e7d9a85..0841bdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### 0.5.1 (Next) +* [#40](https://github.com/dblock/open-weather-ruby-client/pull/40): Fixing rubocop violations and improved .rubocop.yml - [@troya2](https://github.com/troya2). * Your contribution here. ### 0.5.0 (2024/07/03) diff --git a/lib/open_weather/endpoints/stations.rb b/lib/open_weather/endpoints/stations.rb index b3ba880..366086f 100644 --- a/lib/open_weather/endpoints/stations.rb +++ b/lib/open_weather/endpoints/stations.rb @@ -46,7 +46,7 @@ def get_measurements(options) private def validate_id(id) - raise ArgumentError, 'Invalid ID' unless id&.is_a?(String) + raise ArgumentError, 'Invalid ID' unless id.is_a?(String) end end end diff --git a/lib/open_weather/logger.rb b/lib/open_weather/logger.rb index 6ec5a6f..8673f48 100644 --- a/lib/open_weather/logger.rb +++ b/lib/open_weather/logger.rb @@ -6,7 +6,7 @@ module OpenWeather class Logger < ::Logger def self.logger @logger ||= begin - logger = new STDOUT + logger = new $stdout logger.level = Logger::WARN logger end diff --git a/lib/open_weather/models/forecast/forecast.rb b/lib/open_weather/models/forecast/forecast.rb index 53745dc..bf4f7c1 100644 --- a/lib/open_weather/models/forecast/forecast.rb +++ b/lib/open_weather/models/forecast/forecast.rb @@ -13,7 +13,7 @@ class Forecast < Model property 'rain' property 'snow' property 'visibility' # Average visibility, metres. The maximum value of the visibility is 10km - property 'pop' # Probability of precipitation. The values of the parameter vary between 0 and 1, where 0 is equal to 0%, 1 is equal to 100% + property 'pop' # Probability of precipitation. Varies from 0 and 1, where 0 is equal to 0%, 1 is equal to 100% property 'sys' def initialize(args = nil, options = {}) diff --git a/lib/open_weather/models/mixins/temp.rb b/lib/open_weather/models/mixins/temp.rb index fb648b6..8369ec7 100644 --- a/lib/open_weather/models/mixins/temp.rb +++ b/lib/open_weather/models/mixins/temp.rb @@ -31,7 +31,7 @@ def to_kelvin(value) when :metric (value.to_f + 273.15).round(2) when :imperial - ((value.to_f - 32) * 5 / 9 + 273.15).round(2) + (((value.to_f - 32) * 5 / 9) + 273.15).round(2) else value end @@ -55,7 +55,7 @@ def to_farenheit(value) when :imperial value else - ((value.to_f - 273.15) * 9 / 5 + 32).round(2) + (((value.to_f - 273.15) * 9 / 5) + 32).round(2) end end end diff --git a/lib/open_weather/models/one_call/current_weather.rb b/lib/open_weather/models/one_call/current_weather.rb index d66cf25..bd8285b 100644 --- a/lib/open_weather/models/one_call/current_weather.rb +++ b/lib/open_weather/models/one_call/current_weather.rb @@ -11,7 +11,9 @@ class CurrentWeather < Model temperature_property 'feels_like' # temperature, accounts for the human perception of weather property 'pressure' # atmospheric pressure on the sea level, hPa property 'humidity' # humidity, % - temperature_property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form + # atmospheric temperature (varying according to pressure and humidity) + # below which water droplets begin to condense and dew can form + temperature_property 'dew_point' property 'clouds' # cloudiness, % property 'uvi' # UV index property 'visibility' # average visibility, meters diff --git a/lib/open_weather/models/one_call/daily_weather.rb b/lib/open_weather/models/one_call/daily_weather.rb index a3b0652..1c4b1a3 100644 --- a/lib/open_weather/models/one_call/daily_weather.rb +++ b/lib/open_weather/models/one_call/daily_weather.rb @@ -11,7 +11,9 @@ class DailyWeather < Model property 'feels_like' property 'pressure' # atmospheric pressure on the sea level, hPa property 'humidity' # humidity, % - temperature_property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form + # atmospheric temperature (varying according to pressure and humidity) + # below which water droplets begin to condense and dew can form + temperature_property 'dew_point' speed_property 'wind_speed' # wind speed speed_property 'wind_gust' # wind gust property 'wind_deg' # wind direction, degrees (meteorological) diff --git a/lib/open_weather/models/one_call/hourly_weather.rb b/lib/open_weather/models/one_call/hourly_weather.rb index e0ba4f2..b76534c 100644 --- a/lib/open_weather/models/one_call/hourly_weather.rb +++ b/lib/open_weather/models/one_call/hourly_weather.rb @@ -9,7 +9,9 @@ class HourlyWeather < Model temperature_property 'feels_like' property 'pressure' # atmospheric pressure on the sea level, hPa property 'humidity' # humidity, % - temperature_property 'dew_point' # atmospheric temperature (varying according to pressure and humidity) below which water droplets begin to condense and dew can form + # atmospheric temperature (varying according to pressure and humidity) + # below which water droplets begin to condense and dew can form + temperature_property 'dew_point' property 'clouds' # cloudiness, % property 'visibility' # average visibility, meters speed_property 'wind_speed' # wind speed. diff --git a/lib/open_weather/models/stations/measurement.rb b/lib/open_weather/models/stations/measurement.rb index 2761fe0..fa36ec1 100644 --- a/lib/open_weather/models/stations/measurement.rb +++ b/lib/open_weather/models/stations/measurement.rb @@ -5,7 +5,7 @@ module Models module Stations class Measurement < Model property 'station_id' # The internal ID of the station - property 'type' # Type of the aggregated data - minute, hour or day. Specifies the letters m, h or d respectively + property 'type' # Type of the aggregated data - minute, hour or day - the letters m, h or d respectively property 'date' # Time of measurement property 'temp' property 'humidity' diff --git a/spec/open_weather/client_spec.rb b/spec/open_weather/client_spec.rb index f83d73b..00d795f 100644 --- a/spec/open_weather/client_spec.rb +++ b/spec/open_weather/client_spec.rb @@ -99,7 +99,7 @@ end end context 'logger option' do - let(:logger) { Logger.new(STDOUT) } + let(:logger) { Logger.new($stdout) } before do OpenWeather::Client.configure do |config| config.logger = logger @@ -110,7 +110,7 @@ expect(client.logger).to eq logger end it 'creates a connection with a logger' do - expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger + expect(client.send(:connection).builder.handlers).to include Faraday::Response::Logger end end end diff --git a/spec/open_weather/current/cities_box_spec.rb b/spec/open_weather/current/cities_box_spec.rb index 8923a03..a043b43 100644 --- a/spec/open_weather/current/cities_box_spec.rb +++ b/spec/open_weather/current/cities_box_spec.rb @@ -28,7 +28,9 @@ expect(data.cnt).to eq 15 end it 'returns cities in a box weather with coordinates' do - data = client.current_cities_geo_box(lon_left: 12, lat_bottom: 32, lon_right: 15, lat_top: 37, zoom: 10, cluster: true) + data = client.current_cities_geo_box( + lon_left: 12, lat_bottom: 32, lon_right: 15, lat_top: 37, zoom: 10, cluster: true + ) expect(data).to be_a OpenWeather::Models::List expect(data.cnt).to eq 15 end diff --git a/spec/open_weather/endpoints/stations_spec.rb b/spec/open_weather/endpoints/stations_spec.rb index f25fb22..a3de01f 100644 --- a/spec/open_weather/endpoints/stations_spec.rb +++ b/spec/open_weather/endpoints/stations_spec.rb @@ -98,17 +98,17 @@ describe '#create_measurements' do it 'creates measurements', vcr: { cassette_name: 'stations/create_measurement_success' } do create_params = { - "station_id": '5ed21a12cca8ce0001f1aef1', - "dt": 1479817340, - "temperature": 18.7, - "wind_speed": 1.2, - "wind_gust": 3.4, - "pressure": 1021, - "humidity": 87, - "rain_1h": 2, - "clouds": [ + station_id: '5ed21a12cca8ce0001f1aef1', + dt: 1479817340, + temperature: 18.7, + wind_speed: 1.2, + wind_gust: 3.4, + pressure: 1021, + humidity: 87, + rain_1h: 2, + clouds: [ { - "condition": 'NSC' + condition: 'NSC' } ] } @@ -124,17 +124,17 @@ context 'when station does not exist' do it 'raises error', vcr: { cassette_name: 'stations/create_measurement_failed_with_invalid_station' } do create_params = { - "station_id": 'abcde', - "dt": 1479817340, - "temperature": 18.7, - "wind_speed": 1.2, - "wind_gust": 3.4, - "pressure": 1021, - "humidity": 87, - "rain_1h": 2, - "clouds": [ + station_id: 'abcde', + dt: 1479817340, + temperature: 18.7, + wind_speed: 1.2, + wind_gust: 3.4, + pressure: 1021, + humidity: 87, + rain_1h: 2, + clouds: [ { - "condition": 'NSC' + condition: 'NSC' } ] } @@ -187,7 +187,8 @@ context 'without required params' do it 'raises error' do - expect { client.get_measurements(something: 'something') }.to raise_error(ArgumentError, /station_id, type, limit, from, to/) + expect { client.get_measurements(something: 'something') } + .to raise_error(ArgumentError, /station_id, type, limit, from, to/) end end end diff --git a/spec/open_weather/errors/access_denied_spec.rb b/spec/open_weather/errors/access_denied_spec.rb index 7a6fe42..adac277 100644 --- a/spec/open_weather/errors/access_denied_spec.rb +++ b/spec/open_weather/errors/access_denied_spec.rb @@ -6,6 +6,8 @@ include_context 'API client' it 'raises error', vcr: { cassette_name: 'errors/access_denied' } do - expect { client.current_weather(city: 'London') }.to raise_error(OpenWeather::Errors::Fault, 'Invalid API key. Please see http://openweathermap.org/faq#error401 for more info.') + expect { client.current_weather(city: 'London') } + .to raise_error(OpenWeather::Errors::Fault, + 'Invalid API key. Please see http://openweathermap.org/faq#error401 for more info.') end end