From 1b88fa154eaa8db48ccefea26ac64b30a35fd652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Maniaci?= Date: Wed, 16 Oct 2024 11:01:14 +0200 Subject: [PATCH] ruby: include Rubocop (#20821) * ruby: include Rubocop We use a fair bit of Ruby logic here and there so until this website disappears (not soon), we might as well ensure we're hacking as one. * ci: include Rubocop in the flow --- .github/workflows/tests.yml | 3 + .rubocop.yml | 18 +++ .rubocop_todo.yml | 176 +++++++++++++++++++++++ Gemfile | 26 ++-- Gemfile.lock | 27 ++++ Guardfile | 2 + Makefile | 2 + Rakefile | 7 +- _plugins/community.rb | 125 ++++++++-------- _plugins/content_url_encoded_markdown.rb | 2 + _plugins/copy_to_dest.rb | 14 +- _plugins/dates.rb | 23 +-- _plugins/images.rb | 20 ++- _plugins/incubators.rb | 68 ++++----- _plugins/money.rb | 2 +- _plugins/national_impact.rb | 41 +++--- _plugins/phases.rb | 10 +- _plugins/sponsors.rb | 37 +++-- _plugins/startup.rb | 2 +- _plugins/startups.rb | 92 ++++++------ bin/beta-rb | 3 +- bin/htmlproofer | 9 +- bin/validate | 1 + lib/htmlproofer/check_img_http.rb | 6 +- spec/lib/models/member_spec.rb | 46 +++--- 25 files changed, 502 insertions(+), 260 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml mode change 100644 => 100755 bin/beta-rb diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f13e1cae4845..3b6ed01644d2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,6 +21,9 @@ jobs: ruby-version: 3.3.4 bundler-cache: true + - name: Lint Ruby with Rubocop + run: bundle exec rubocop + - name: Install npm dependencies uses: actions/setup-node@v4 with: diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000000..ac8c15d10856 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,18 @@ +inherit_from: .rubocop_todo.yml + +# The behavior of RuboCop can be controlled via the .rubocop.yml +# configuration file. It makes it possible to enable/disable +# certain cops (checks) and to alter their behavior if they accept +# any parameters. The file can be placed either in your home +# directory or in some project directory. +# +# RuboCop will start looking for the configuration file in the directory +# where the inspected file is and continue its way up to the root directory. +# +# See https://docs.rubocop.org/rubocop/configuration +require: + - rubocop-rspec + - rubocop-rake + +AllCops: + NewCops: enable diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000000..311145b917cd --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,176 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-10-16 07:34:36 UTC using RuboCop version 1.66.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: 2 +# This cop supports safe autocorrection (--autocorrect). +Lint/AmbiguousOperator: + Exclude: + - 'spec/lib/models/member_spec.rb' + +# Offense count: 2 +# Configuration parameters: DebuggerMethods, DebuggerRequires. +Lint/Debugger: + Exclude: + - '_site/bin/beta-rb' + - 'bin/beta-rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowPercentLiteralArrayArgument. +Lint/RedundantSplatExpansion: + Exclude: + - 'spec/lib/models/member_spec.rb' + +# Offense count: 2 +Lint/ShadowingOuterLocalVariable: + Exclude: + - '_site/bin/htmlproofer' + - 'bin/htmlproofer' + +# Offense count: 6 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 108 + +# Offense count: 1 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 42 + +# Offense count: 3 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 26 + +# Offense count: 7 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 67 + +# Offense count: 3 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 28 + +# Offense count: 2 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - '_site/bin/beta-rb' + - 'bin/beta-rb' + +# Offense count: 45 +# Configuration parameters: EnforcedStyle, AllowedIdentifiers, AllowedPatterns. +# SupportedStyles: snake_case, camelCase +Naming/VariableName: + Exclude: + - '_plugins/community.rb' + - '_plugins/incubators.rb' + - '_plugins/sponsors.rb' + - '_plugins/startups.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +RSpec/ContainExactly: + Exclude: + - 'spec/lib/models/member_spec.rb' + +# Offense count: 4 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/plugins/startup_spec.rb' + - 'spec/spec_helper.rb' + +# Offense count: 4 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 4 + +# Offense count: 4 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata. +# Include: **/*_spec.rb +RSpec/SpecFilePathFormat: + Exclude: + - '**/spec/routing/**/*' + - 'spec/lib/models/member_spec.rb' + - 'spec/plugins/community_spec.rb' + - 'spec/plugins/money_spec.rb' + - 'spec/plugins/startup_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Rake/Desc: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowOnConstant, AllowOnSelfClass. +Style/CaseEquality: + Exclude: + - '_plugins/incubators.rb' + +# Offense count: 17 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - '_plugins/community.rb' + - '_plugins/content_url_encoded_markdown.rb' + - '_plugins/dates.rb' + - '_plugins/images.rb' + - '_plugins/incubators.rb' + - '_plugins/national_impact.rb' + - '_plugins/phases.rb' + - '_plugins/sponsors.rb' + - '_plugins/startup.rb' + - '_plugins/startups.rb' + - '_site/bin/beta-rb' + - 'bin/beta-rb' + - 'lib/htmlproofer/check_img_http.rb' + - 'lib/models/member.rb' + +# Offense count: 1 +Style/OpenStructUse: + Exclude: + - 'spec/plugins/community_spec.rb' + +# Offense count: 1 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - '_plugins/startup.rb' + +# Offense count: 32 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Exclude: + - 'spec/lib/models/member_spec.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + EnforcedStyle: percent + MinSize: 4 + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 150 diff --git a/Gemfile b/Gemfile index 8ede094ab366..2cf91f25ccb7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,17 +1,25 @@ -source "https://rubygems.org" +# frozen_string_literal: true -ruby "3.3.4" +source 'https://rubygems.org' -gem "base64" -gem "csv" -gem "jekyll" +ruby '3.3.4' -gem "activemodel" +gem 'base64' +gem 'csv' +gem 'jekyll' + +gem 'activemodel' group :jekyll_plugins do gem 'jekyll-redirect-from' end +group :test, :development do + gem 'rubocop' + gem 'rubocop-rake' + gem 'rubocop-rspec' +end + group :test do gem 'debug' gem 'guard' @@ -23,10 +31,10 @@ group :test do gem 'rspec' end -gem 'rake', group: [:default, :test] +gem 'rake', group: %i[default test] # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] # Performance-booster for watching directories on Windows -gem "wdm", "~> 0.1.0" if Gem.win_platform? +gem 'wdm', '~> 0.1.0' if Gem.win_platform? diff --git a/Gemfile.lock b/Gemfile.lock index b952e63e7779..8dc7e31b1ac8 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -18,6 +18,7 @@ GEM addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) afm (0.2.2) + ast (2.4.2) async (2.11.0) console (~> 1.25, >= 1.25.2) fiber-annotation @@ -124,6 +125,7 @@ GEM kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) kwalify (0.7.2) + language_server-protocol (3.17.0.3) liquid (4.0.4) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) @@ -149,6 +151,10 @@ GEM addressable nokogiri optimist (3.1.0) + parallel (1.26.3) + parser (3.3.5.0) + ast (~> 2.4.1) + racc pathutil (0.16.2) forwardable-extended (~> 2.6) pdf-reader (2.12.0) @@ -171,6 +177,7 @@ GEM ffi (~> 1.0) rdoc (6.7.0) psych (>= 4.0.0) + regexp_parser (2.9.2) reline (0.5.8) io-console (~> 0.5) rexml (3.2.8) @@ -189,6 +196,23 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.1) + rubocop (1.66.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.3) + parser (>= 3.3.1.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (3.0.5) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) ruby-rc4 (0.1.5) safe_yaml (1.0.5) sass-embedded (1.77.4-aarch64-linux-gnu) @@ -236,6 +260,9 @@ DEPENDENCIES opengraph_parser rake rspec + rubocop + rubocop-rake + rubocop-rspec tzinfo-data RUBY VERSION diff --git a/Guardfile b/Guardfile index 870d372f85c9..f0392bfd399f 100644 --- a/Guardfile +++ b/Guardfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # More info at https://github.com/guard/guard#readme guard :rspec, cmd: 'bundle exec rspec' do diff --git a/Makefile b/Makefile index 49b24371e0ed..3287e294704e 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,8 @@ down: docker compose down sh: $(DOCKER-RUN) web bash +lint: + $(DOCKER-RUN) web $(BUNDLE-EXEC) rubocop html-proofer: bundle exec htmlproofer ./_site/ --ignore-files "/recrutement\/*/" --no-enforce-https --disable-external --root_dir _site/ --allow-missing-href diff --git a/Rakefile b/Rakefile index 91fd2a36449c..9bb82530365e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,5 @@ -task "assets:precompile" do - exec("jekyll build") -end +# frozen_string_literal: true +task 'assets:precompile' do + exec('jekyll build') +end diff --git a/_plugins/community.rb b/_plugins/community.rb index 97d90088a348..ddf9e8b2e491 100644 --- a/_plugins/community.rb +++ b/_plugins/community.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Jekyll module CommunityFilter def community(people, state, sort_by = 'oldest') @@ -11,11 +13,15 @@ def community(people, state, sort_by = 'oldest') result = state == 'past' ? past : current - if sort_by != 'alpha' - result = result.sort_by { |person| person.data['missions']&.map{ |e| e['start'] || Date.today }&.min || Date.today }.reverse - else - result = result.sort_by { |person| person.data['fullname'] } - end + result = if sort_by == 'alpha' + result.sort_by { |person| person.data['fullname'] } + else + result.sort_by do |person| + person.data['missions']&.map do |e| + e['start'] || Date.today + end&.min || Date.today + end.reverse + end if state == 'recent' result.first(3) @@ -25,73 +31,74 @@ def community(people, state, sort_by = 'oldest') end end -class RenderCommunityStatsTag < Liquid::Tag - def initialize(tag_name, input, tokens) - super - @input = input - end + class RenderCommunityStatsTag < Liquid::Tag + def initialize(tag_name, input, tokens) + super + @input = input + end + + def render(context) + result = { + 'employer' => { + 'admin' => [], + 'independent' => [], + 'service' => [] + }, + 'domaineOverDate' => { + 'Déploiement' => [], + 'Design' => [], + 'Développement' => [], + 'Coaching' => [], + 'Autre' => [], + 'Intraprenariat' => [], + 'Animation' => [], + 'Produit' => [], + 'Data' => [] + }, + 'domaine' => { + 'Déploiement' => 0, + 'Design' => 0, + 'Développement' => 0, + 'Coaching' => 0, + 'Autre' => 0, + 'Intraprenariat' => 0, + 'Animation' => 0, + 'Produit' => 0, + 'Data' => 0 + }, + 'total' => 0 + } + authors = context.registers[:site].collections['authors'] + now = Date.today + authors.docs.each do |author| + next unless author.data['missions'] - def render(context) - result = { - 'employer' => { - 'admin' => [], - 'independent' => [], - 'service' => [], - }, - 'domaineOverDate' => { - 'Déploiement' => [], - 'Design' => [], - 'Développement' => [], - 'Coaching' => [], - 'Autre' => [], - 'Intraprenariat' => [], - 'Animation' => [], - 'Produit' => [], - 'Data' => [] - }, - 'domaine' => { - 'Déploiement' => 0, - 'Design' => 0, - 'Développement' => 0, - 'Coaching' => 0, - 'Autre' => 0, - 'Intraprenariat' => 0, - 'Animation' => 0, - 'Produit' => 0, - 'Data' => 0 - }, - 'total' => 0 - } - authors = context.registers[:site].collections['authors'] - now = Date.today - authors.docs.each do |author| - if author.data['missions'] author.data['missions'].each do |mission| startDate = mission['start'] endDate = mission['end'] - result['employer'][mission['status']] << {date: startDate, increment: 1} if startDate and startDate != '' - result['employer'][mission['status']] << {date: endDate, increment: -1} if endDate and endDate != '' - result['domaineOverDate'][author.data['domaine']] << {date: startDate, increment: 1} if startDate and startDate != '' - result['domaineOverDate'][author.data['domaine']] << {date: endDate, increment: -1} if endDate and endDate != '' + result['employer'][mission['status']] << { date: startDate, increment: 1 } if startDate && (startDate != '') + result['employer'][mission['status']] << { date: endDate, increment: -1 } if endDate && (endDate != '') + if startDate && (startDate != '') + result['domaineOverDate'][author.data['domaine']] << { date: startDate, + increment: 1 } + end + if endDate && (endDate != '') + result['domaineOverDate'][author.data['domaine']] << { date: endDate, + increment: -1 } + end end - if author.data['missions']&.last['end'] >= now + if author.data['missions']&.last&.[]('end')&.>= now result['domaine'][author.data['domaine']] = result['domaine'][author.data['domaine']] + 1 result['total'] = result['total'] + 1 end end - end - if ( !@input.nil? && !@input.empty? ) + return result.to_json unless !@input.nil? && !@input.empty? + key = @input.strip - return result[key] - else - return result.to_json + result[key] end end end - -end - - Liquid::Template.register_filter(Jekyll::CommunityFilter) Liquid::Template.register_tag('render_community_stats', Jekyll::RenderCommunityStatsTag) diff --git a/_plugins/content_url_encoded_markdown.rb b/_plugins/content_url_encoded_markdown.rb index b0e54fb9b98d..704773e566e5 100644 --- a/_plugins/content_url_encoded_markdown.rb +++ b/_plugins/content_url_encoded_markdown.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ContentUrlEncodedMarkdown class Generator < Jekyll::Generator def generate(site) diff --git a/_plugins/copy_to_dest.rb b/_plugins/copy_to_dest.rb index 90af3b38e947..614cf1cf3c21 100644 --- a/_plugins/copy_to_dest.rb +++ b/_plugins/copy_to_dest.rb @@ -1,11 +1,13 @@ -require "fileutils" +# frozen_string_literal: true + +require 'fileutils' Jekyll::Hooks.register :site, :after_init do |site| - site.config["copy_to_dest"].each { |copy| - Jekyll.logger.info "Copying:", "#{copy["source"]} to #{copy["target"]}" - src = "#{site.source}/#{copy["source"]}" - dest = "#{site.dest}/#{copy["target"]}" + site.config['copy_to_dest'].each do |copy| + Jekyll.logger.info 'Copying:', "#{copy['source']} to #{copy['target']}" + src = "#{site.source}/#{copy['source']}" + dest = "#{site.dest}/#{copy['target']}" FileUtils.mkdir_p dest FileUtils.cp_r src, dest - } + end end diff --git a/_plugins/dates.rb b/_plugins/dates.rb index 7c76dbc3699f..e3cf17426318 100644 --- a/_plugins/dates.rb +++ b/_plugins/dates.rb @@ -1,16 +1,17 @@ -module Jekyll - module DateFilter - MONTHS_FR = %w(janvier février mars avril mai juin juillet aout septembre octobre novembre décembre) +# frozen_string_literal: true - def french_long_date(input) - day = time(input).strftime("%-d") # no leading zero - if day == "1"; day="1er"; end - month = time(input).strftime("%m") - year = time(input).strftime("%Y") - day+' '+ MONTHS_FR[month.to_i - 1]+' '+year - end +module Jekyll + module DateFilter + MONTHS_FR = %w[janvier février mars avril mai juin juillet aout septembre octobre novembre décembre].freeze + def french_long_date(input) + day = time(input).strftime('%-d') # no leading zero + day = '1er' if day == '1' + month = time(input).strftime('%m') + year = time(input).strftime('%Y') + "#{day} #{MONTHS_FR[month.to_i - 1]} #{year}" end + end end -Liquid::Template.register_filter(Jekyll::DateFilter) \ No newline at end of file +Liquid::Template.register_filter(Jekyll::DateFilter) diff --git a/_plugins/images.rb b/_plugins/images.rb index 2a0a8c885c8f..ab2f05025a47 100644 --- a/_plugins/images.rb +++ b/_plugins/images.rb @@ -5,9 +5,7 @@ require 'net/http' require 'uri' - - -S3_BASE_URL= ENV['S3_BASE_URL'] +S3_BASE_URL = ENV.fetch('S3_BASE_URL', nil) module Jekyll # provides a shortcut to the Jekyll static files @@ -104,17 +102,18 @@ def github_avatar(identifier) module IncubatorLogoFilter include StaticFiles include URLChecker - + FALLBACK = '/img/incubators/logo_beta.png' - + def incubator_logo(incubator) return FALLBACK if incubator.nil? + id = incubator_id(incubator) incubator_s3_img(id) || incubator_file(incubator) || FALLBACK end - + private - + def incubator_s3_img(id) s3_url = "#{S3_BASE_URL}/incubators/#{id}/logo.jpg" URLChecker.url_exists?(s3_url) ? s3_url : false @@ -123,11 +122,11 @@ def incubator_s3_img(id) def incubator_id(incubator) incubator.id.split('/').last.parameterize # they come as /incubateurs/{id} end - + def incubator_files static_files.filter { |f| f.data['incubators_img'] == true } end - + def incubator_file(incubator) file = incubator_files.find do |f| incubator['logo'].include?(f.basename) @@ -137,9 +136,6 @@ def incubator_file(incubator) end end - - Liquid::Template.register_filter(Jekyll::ScreenshotFilter) Liquid::Template.register_filter(Jekyll::AvatarFilter) Liquid::Template.register_filter(Jekyll::IncubatorLogoFilter) - diff --git a/_plugins/incubators.rb b/_plugins/incubators.rb index cd1ee6c68381..e42cecace035 100644 --- a/_plugins/incubators.rb +++ b/_plugins/incubators.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Jekyll # an active startup is considered being either in: # - investigation @@ -8,37 +10,37 @@ module Jekyll # we add an exception to always consider the main incubator at the top of the list module ActiveStartupsFilter def sort_incubators_by_active_startups(incubators, startups) - sorted_incubators = incubators.sort_by {|incubator| + sorted_incubators = incubators.sort_by do |incubator| count_incubator_active_startups(incubator, startups) - }.reverse + end.reverse # Place 'dinum' at the top - sorted_incubators = (sorted_incubators.partition { |incubator| incubator.id == '/incubateurs/dinum' }).flatten - - sorted_incubators + (sorted_incubators.partition { |incubator| incubator.id == '/incubateurs/dinum' }).flatten end def filter_incubators_with_active_startups(incubators, startups) - incubators.select {|incubator| - count_incubator_active_startups(incubator, startups) > 0 - } + incubators.select do |incubator| + count_incubator_active_startups(incubator, startups).positive? + end end def count_incubator_active_startups(incubator, startups) - startups.count { |startup| + startups.count do |startup| "/incubateurs/#{startup['incubator']}" === incubator.id && - ['investigation', 'construction', 'acceleration', 'transfer'].include?(get_phase(startup)) - } + %w[investigation construction acceleration transfer].include?(get_phase(startup)) + end end def count_all_active_startups(startups) - startups.count { |startup| ['investigation', 'construction', 'acceleration', 'transfer', 'success'].include?(get_phase(startup)) - } + startups.count do |startup| + %w[investigation construction acceleration transfer + success].include?(get_phase(startup)) + end end # copied from `_plugins/phases.rb` but it's too tricky to reapply the filter in another separated filter def get_phase(startup) - startup['phases'].last['name'] || startup.data['phases']&.last['name'] + startup['phases'].last['name'] || startup.data['phases']&.last&.[]('name') end end @@ -47,30 +49,28 @@ def render(context) result = {} startups = context.registers[:site].collections['startups'] incubators = context.registers[:site].collections['incubators'] - now = Date.today + Date.today startups.docs.each do |startup| - incubator = startup["incubator"] - if incubator - if !result[incubator] - result[incubator] = { - 'startups' => Array.new - } - end - result[incubator]['startups'].push({ - "id" => startup.id.gsub('/startups/', ''), - "name" => startup["title"], - "pitch" => startup["mission"], - "repository" => startup["repository"], - "contact" => startup["contact"], - "phases" => startup["phases"], - }) + incubator = startup['incubator'] + next unless incubator + + unless result[incubator] + result[incubator] = { + 'startups' => [] + } end + result[incubator]['startups'].push({ + 'id' => startup.id.gsub('/startups/', ''), + 'name' => startup['title'], + 'pitch' => startup['mission'], + 'repository' => startup['repository'], + 'contact' => startup['contact'], + 'phases' => startup['phases'] + }) end incubators.docs.each do |incubator| incubatorName = incubator.id.gsub('/incubateurs/', '') - if !result[incubatorName] - result[incubatorName] = {} - end + result[incubatorName] = {} unless result[incubatorName] result[incubatorName]['title'] = incubator['title'] result[incubatorName]['owner'] = incubator['owner'] result[incubatorName]['contact'] = incubator['contact'] @@ -78,7 +78,7 @@ def render(context) result[incubatorName]['website'] = incubator['website'] result[incubatorName]['github'] = incubator['github'] end - return JSON.pretty_generate(result) + JSON.pretty_generate(result) end end end diff --git a/_plugins/money.rb b/_plugins/money.rb index cd219fc44c9f..91f7a29c2ee8 100644 --- a/_plugins/money.rb +++ b/_plugins/money.rb @@ -16,7 +16,7 @@ def to_euros(number) .reverse .each_slice(3) .to_a - .map { |c| c.join('') } + .map(&:join) .join(' ') .reverse diff --git a/_plugins/national_impact.rb b/_plugins/national_impact.rb index fd2d822a18de..b0237c526f7a 100644 --- a/_plugins/national_impact.rb +++ b/_plugins/national_impact.rb @@ -1,27 +1,24 @@ +# frozen_string_literal: true + module Jekyll - module NationalImpactFilter - def get_national_impact(startup) - if startup['events'] - national_impact = startup['events'].select{ |event| event['name'] == 'national_impact' }.first() - if national_impact - return national_impact['date'].year - end - end - return + module NationalImpactFilter + def get_national_impact(startup) + if startup['events'] + national_impact = startup['events'].select { |event| event['name'] == 'national_impact' }.first + return national_impact['date'].year if national_impact end - - def where_national_impact(startups, date) - list = [] - startups.each do |startup| - if get_national_impact(startup) == date - list << startup - end - end - - return list + nil + end + + def where_national_impact(startups, date) + list = [] + startups.each do |startup| + list << startup if get_national_impact(startup) == date end + + list end end - - Liquid::Template.register_filter(Jekyll::NationalImpactFilter) - \ No newline at end of file +end + +Liquid::Template.register_filter(Jekyll::NationalImpactFilter) diff --git a/_plugins/phases.rb b/_plugins/phases.rb index 2407f8338328..3f1b9586002f 100644 --- a/_plugins/phases.rb +++ b/_plugins/phases.rb @@ -1,18 +1,18 @@ +# frozen_string_literal: true + module Jekyll module PhaseFilter def get_phase(startup) - startup['phases'].last['name'] || startup.data['phases']&.last['name'] + startup['phases'].last['name'] || startup.data['phases']&.last&.[]('name') end def where_phase(startups, phase) list = [] startups.each do |startup| - if get_phase(startup) == phase - list << startup - end + list << startup if get_phase(startup) == phase end - return list + list end end end diff --git a/_plugins/sponsors.rb b/_plugins/sponsors.rb index a5ad31b0d48b..9deeb552a998 100644 --- a/_plugins/sponsors.rb +++ b/_plugins/sponsors.rb @@ -1,23 +1,22 @@ +# frozen_string_literal: true + module Jekyll - class RenderSponsorsApi < Liquid::Tag - def render(context) - result = {} - sponsors = context.registers[:site].collections['organisations'] - now = Date.today - sponsors.docs.each do |incubator| - incubatorName = incubator.id.gsub('/organisations/', '') - if !result[incubatorName] - result[incubatorName] = {} - end - result[incubatorName]['name'] = incubator['name'] - result[incubatorName]['acronym'] = incubator['acronym'] - result[incubatorName]['domaine_ministeriel'] = incubator['domaine_ministeriel'] - result[incubatorName]['type'] = incubator['type'] - end - return JSON.pretty_generate(result) + class RenderSponsorsApi < Liquid::Tag + def render(context) + result = {} + sponsors = context.registers[:site].collections['organisations'] + Date.today + sponsors.docs.each do |incubator| + incubatorName = incubator.id.gsub('/organisations/', '') + result[incubatorName] = {} unless result[incubatorName] + result[incubatorName]['name'] = incubator['name'] + result[incubatorName]['acronym'] = incubator['acronym'] + result[incubatorName]['domaine_ministeriel'] = incubator['domaine_ministeriel'] + result[incubatorName]['type'] = incubator['type'] end + JSON.pretty_generate(result) end end - - Liquid::Template.register_tag('render_sponsors_api', Jekyll::RenderSponsorsApi) - \ No newline at end of file +end + +Liquid::Template.register_tag('render_sponsors_api', Jekyll::RenderSponsorsApi) diff --git a/_plugins/startup.rb b/_plugins/startup.rb index d38ff3726de4..5bdb66a5920f 100644 --- a/_plugins/startup.rb +++ b/_plugins/startup.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../lib/models/member" +require_relative '../lib/models/member' module Jekyll module StartupFilter diff --git a/_plugins/startups.rb b/_plugins/startups.rb index 5aebbf58f776..af46a736f898 100644 --- a/_plugins/startups.rb +++ b/_plugins/startups.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Jekyll class RenderStartupsApi < Liquid::Tag def render(context) @@ -5,51 +7,47 @@ def render(context) authors = context.registers[:site].collections['authors'] now = Date.today authors.docs.each do |author| - if author['startups'] - author['startups'].each do |startup| - if !result[startup] - result[startup] = { - 'active_members' => Array.new, - 'previous_members' => Array.new, - 'expired_members' => Array.new - } - end - if author.data['missions']&.last['end'] and author.data['missions']&.last['end'] <= now - result[startup]['expired_members'].push(author.id.gsub('/authors/', '')) - else - result[startup]['active_members'].push(author.id.gsub('/authors/', '')) - end + author['startups']&.each do |startup| + unless result[startup] + result[startup] = { + 'active_members' => [], + 'previous_members' => [], + 'expired_members' => [] + } + end + if author.data['missions']&.last&.[]('end') && (author.data['missions']&.last&.[]('end')&.<= now) + result[startup]['expired_members'].push(author.id.gsub('/authors/', '')) + else + result[startup]['active_members'].push(author.id.gsub('/authors/', '')) end end - if author['previously'] - author['previously'].each do |previous_startup| - if !result[previous_startup] - result[previous_startup] = { - 'active_members' => Array.new, - 'previous_members' => Array.new, - 'expired_members' => Array.new - } - end - result[previous_startup]['previous_members'].push(author.id.gsub('/authors/', '')) + author['previously']&.each do |previous_startup| + unless result[previous_startup] + result[previous_startup] = { + 'active_members' => [], + 'previous_members' => [], + 'expired_members' => [] + } end + result[previous_startup]['previous_members'].push(author.id.gsub('/authors/', '')) end - if author['missions'] - author['missions'].each do |mission| - if mission['startups'] - mission['startups'].each do |startup| - if !result[startup] - result[startup] = { - 'active_members' => Array.new, - 'previous_members' => Array.new, - 'expired_members' => Array.new - } - end - if !mission['end'] or (mission['start'] <= now and mission['end'] >= now) - result[startup]['active_members'].push(author.id.gsub('/authors/', '')) - elsif mission['end'] <= now - result[startup]['expired_members'].push(author.id.gsub('/authors/', '')) - end - end + next unless author['missions'] + + author['missions'].each do |mission| + next unless mission['startups'] + + mission['startups'].each do |startup| + unless result[startup] + result[startup] = { + 'active_members' => [], + 'previous_members' => [], + 'expired_members' => [] + } + end + if !mission['end'] || ((mission['start'] <= now) && (mission['end'] >= now)) + result[startup]['active_members'].push(author.id.gsub('/authors/', '')) + elsif mission['end'] <= now + result[startup]['expired_members'].push(author.id.gsub('/authors/', '')) end end end @@ -57,14 +55,14 @@ def render(context) startups = context.registers[:site].collections['startups'] startups.docs.each do |startup| startupId = startup.id.gsub('/startups/', '') - if !result[startupId] + unless result[startupId] result[startupId] = { - 'active_members' => Array.new, - 'previous_members' => Array.new, - 'expired_members' => Array.new + 'active_members' => [], + 'previous_members' => [], + 'expired_members' => [] } end - result[startupId]["id"] = startupId + result[startupId]['id'] = startupId result[startupId]['name'] = startup['title'] result[startupId]['repository'] = startup['repository'] result[startupId]['contact'] = startup['contact'] @@ -73,7 +71,7 @@ def render(context) result[startupId]['previous_members'] = result[startupId]['previous_members'].uniq result[startupId]['expired_members'] = result[startupId]['expired_members'].uniq end - return JSON.pretty_generate(result) + JSON.pretty_generate(result) end end diff --git a/bin/beta-rb b/bin/beta-rb old mode 100644 new mode 100755 index 3c2cc696c49e..5543999dc930 --- a/bin/beta-rb +++ b/bin/beta-rb @@ -1,8 +1,9 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'irb' -DSL_PATH = File.expand_path('../../lib', __FILE__) +DSL_PATH = File.expand_path('../lib', __dir__) $LOAD_PATH << DSL_PATH diff --git a/bin/htmlproofer b/bin/htmlproofer index ac40dcd9eea8..5e8cc0ccf914 100755 --- a/bin/htmlproofer +++ b/bin/htmlproofer @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'rubygems' require 'bundler' @@ -7,17 +8,15 @@ Bundler.setup :test require 'html-proofer' dir = ARGV[0] || '.' -args = ARGV[1] ? ARGV[1..-1] : [] +args = ARGV[1] ? ARGV[1..] : [] opts = args.each_with_object({}) do |option, opts| - option_name = option.to_s[2..-1].gsub('-', '_').to_sym + option_name = option.to_s[2..].gsub('-', '_').to_sym opts[option_name] = true end opts.keys.map(&:to_s).each do |check| - if File.file?(File.expand_path("#{__dir__}/../lib/htmlproofer/#{check}.rb")) - require_relative "../lib/htmlproofer/#{check}" - end + require_relative "../lib/htmlproofer/#{check}" if File.file?(File.expand_path("#{__dir__}/../lib/htmlproofer/#{check}.rb")) end HTMLProofer diff --git a/bin/validate b/bin/validate index bae7376d4dbe..bd13f60a3761 100755 --- a/bin/validate +++ b/bin/validate @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'rubygems' require 'bundler' diff --git a/lib/htmlproofer/check_img_http.rb b/lib/htmlproofer/check_img_http.rb index 76019a1d236d..088768fd8b67 100644 --- a/lib/htmlproofer/check_img_http.rb +++ b/lib/htmlproofer/check_img_http.rb @@ -1,7 +1,9 @@ -class CheckImgHTTP < ::HTMLProofer::Check +# frozen_string_literal: true + +class CheckImgHTTP < HTMLProofer::Check def run @html.css('img').each do |node| - if node.attributes['src'].try(:value) =~ %r{^http:} + if node.attributes['src'].try(:value) =~ /^http:/ return( add_issue( 'This image src is insecure. Including it would result in marking the whole page as insecure through mixed-content.', diff --git a/spec/lib/models/member_spec.rb b/spec/lib/models/member_spec.rb index 170cff0647fe..71a83f31ae3b 100644 --- a/spec/lib/models/member_spec.rb +++ b/spec/lib/models/member_spec.rb @@ -6,6 +6,8 @@ require_relative '../../../lib/models/member' describe Beta::Member do + subject(:member) { described_class.new(data) } + let(:yml) do <