From dec29921ef89d3179a5ad0309c944fee751c9ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Thu, 8 Apr 2021 11:25:33 +0200 Subject: [PATCH] Decidim 0.24 compatiblity upgrade (#62) * initial changes * fix version views * fix items call * fix appraisal * use legacy editor for 0.23 * allow prerelease checking * relax specs for admin checker * rebase latests changes * downgrade missing gem * add codemirror to legacy admin * fix category and operation over hashtags * remove repeated test * update docs --- .github/workflows/{test.yml => test -23.yml} | 4 +- .github/workflows/test -24.yml | 65 + .rubocop.yml | 1254 +----------- .rubocop_rails.yml | 50 +- .rubocop_ruby.yml | 1752 +++++++++++++++++ Appraisals | 42 +- CHANGELOG.md | 24 +- Gemfile | 9 +- Gemfile.lock | 300 +-- README.md | 6 +- .../decidim_admin_decidim_awesome_manifest.js | 1 + .../decidim_decidim_awesome_manifest.js | 2 +- .../awesome_map/legacy_map.js.es6 | 218 -- .../awesome_map/legacy_proposals.js.es6 | 83 - .../awesome_map/meetings.js.es6 | 4 +- .../editors/legacy_quill_editor.js.es6 | 160 ++ .../editors/quill_editor.js.es6 | 21 +- .../decidim/decidim_awesome/legacy_admin.js | 3 + .../decidim_awesome/legacy_application.js | 4 + .../proposals/proposal_presenter_override.rb | 12 +- .../admin/checks_controller.rb | 2 +- .../admin/menu_hacks_controller.rb | 4 +- .../map_component/map_controller.rb | 5 +- .../decidim/decidim_awesome/map_helper.rb | 52 +- .../decidim/decidim_awesome/image_uploader.rb | 5 - .../admin/checks/index.html.erb | 2 +- .../map_component/map/show.html.erb | 34 +- .../v0.23/layouts/decidim/_head.html.erb | 2 +- .../layouts/decidim/admin/_header.html.erb | 2 +- .../layouts/decidim/_head.html.erb | 2 + .../layouts/decidim/admin/_header.html.erb | 1 + decidim-decidim_awesome.gemspec | 4 +- gemfiles/decidim_0.23.1.gemfile | 32 - ..._0.23.2.gemfile => decidim_0.23.4.gemfile} | 10 +- ...mfile.lock => decidim_0.23.4.gemfile.lock} | 244 ++- gemfiles/decidim_0.23.gemfile | 2 +- gemfiles/decidim_0.23.gemfile.lock | 96 +- ...idim_0.22.gemfile => decidim_0.24.gemfile} | 13 +- ...gemfile.lock => decidim_0.24.gemfile.lock} | 326 +-- lib/decidim/decidim_awesome/checksums.yml | 9 +- lib/decidim/decidim_awesome/config.rb | 4 +- lib/decidim/decidim_awesome/engine.rb | 4 +- .../iframe_component/component.rb | 2 +- .../map_component/component.rb | 2 +- lib/decidim/decidim_awesome/menu_hacker.rb | 2 +- lib/decidim/decidim_awesome/system_checker.rb | 2 +- lib/decidim/decidim_awesome/version.rb | 4 +- .../admin/checks_controller_spec.rb | 16 +- 48 files changed, 2677 insertions(+), 2220 deletions(-) rename .github/workflows/{test.yml => test -23.yml} (95%) create mode 100644 .github/workflows/test -24.yml create mode 100644 .rubocop_ruby.yml delete mode 100644 app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_map.js.es6 delete mode 100644 app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_proposals.js.es6 create mode 100644 app/assets/javascripts/decidim/decidim_awesome/editors/legacy_quill_editor.js.es6 create mode 100644 app/assets/javascripts/decidim/decidim_awesome/legacy_admin.js create mode 100644 app/assets/javascripts/decidim/decidim_awesome/legacy_application.js rename app/views/{v0.22 => v0.24}/layouts/decidim/_head.html.erb (96%) rename app/views/{v0.22 => v0.24}/layouts/decidim/admin/_header.html.erb (94%) delete mode 100644 gemfiles/decidim_0.23.1.gemfile rename gemfiles/{decidim_0.23.2.gemfile => decidim_0.23.4.gemfile} (79%) rename gemfiles/{decidim_0.23.2.gemfile.lock => decidim_0.23.4.gemfile.lock} (82%) rename gemfiles/{decidim_0.22.gemfile => decidim_0.24.gemfile} (74%) rename gemfiles/{decidim_0.22.gemfile.lock => decidim_0.24.gemfile.lock} (76%) diff --git a/.github/workflows/test.yml b/.github/workflows/test -23.yml similarity index 95% rename from .github/workflows/test.yml rename to .github/workflows/test -23.yml index d67ab8769..33bfbfd82 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test -23.yml @@ -1,4 +1,4 @@ -name: "[CI] Test" +name: "[CI] Test 0.23" on: push: @@ -13,7 +13,7 @@ jobs: matrix: os: [ubuntu] ruby: [2.7] - decidim: [decidim-0.22, decidim-0.23, decidim-0.23.2] + decidim: [decidim-0.23, decidim-0.23.4] runs-on: ${{ matrix.os }}-latest continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }} diff --git a/.github/workflows/test -24.yml b/.github/workflows/test -24.yml new file mode 100644 index 000000000..59a469520 --- /dev/null +++ b/.github/workflows/test -24.yml @@ -0,0 +1,65 @@ +name: "[CI] Test 0.24" + +on: + push: + branches: + - master + pull_request: + +jobs: + test-report: + strategy: + fail-fast: false + matrix: + os: [ubuntu] + ruby: [2.7] + decidim: [decidim-0.24] + runs-on: ${{ matrix.os }}-latest + continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }} + + services: + postgres: + image: postgres:11 + ports: ["5432:5432"] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_PASSWORD: postgres + env: + DATABASE_USERNAME: postgres + DATABASE_PASSWORD: postgres + DATABASE_HOST: localhost + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + # do not use cache as appraisal is not compatible with gems installed locally + + - name: Install Ruby deps + run: | + gem install bundler:2.1.4 + bundle install --jobs 4 --retry 3 + + - name: Install Appraisal + run: | + bundle exec appraisal install + + - name: Setup Database + run: bundle exec appraisal ${{ matrix.decidim }} rake test_app + + - name: Run RSpec + run: SIMPLECOV=1 CODECOV=1 bundle exec appraisal ${{ matrix.decidim }} rake + + - uses: actions/upload-artifact@v2-preview + if: always() + with: + name: screenshots + path: ./spec/decidim_dummy_app/tmp/screenshots diff --git a/.rubocop.yml b/.rubocop.yml index 98524b1c2..870c0b9ff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,1251 +1,3 @@ -require: rubocop-rspec - -# Common configuration. -AllCops: - Include: - - .simplecov - - "**/*.rb" - - "**/*.rake" - - "**/*.gemspec" - - "**/*.ru" - - "**/Gemfile" - - "**/Rakefile" - Exclude: - - "**/vendor/**/*" - - "development_app/**/*" - - "spec/decidim_dummy_app/**/*" - - "node_modules/**/*" - # Default formatter will be used if no -f/--format option is given. - DefaultFormatter: progress - # Cop names are not displayed in offense messages by default. Change behavior - # by overriding DisplayCopNames, or by giving the -D/--display-cop-names - # option. - DisplayCopNames: true - # Style guide URLs are not displayed in offense messages by default. Change - # behavior by overriding DisplayStyleGuide, or by giving the - # -S/--display-style-guide option. - DisplayStyleGuide: false - # Extra details are not displayed in offense messages by default. Change - # behavior by overriding ExtraDetails, or by giving the - # -E/--extra-details option. - ExtraDetails: false - # Additional cops that do not reference a style guide rule may be enabled by - # default. Change behavior by overriding StyleGuideCopsOnly, or by giving - # the --only-guide-cops option. - StyleGuideCopsOnly: false - # All cops except the ones in disabled.yml are enabled by default. Change - # this behavior by overriding DisabledByDefault. When DisabledByDefault is - # true, all cops in the default configuration are disabled, and and only cops - # in user configuration are enabled. This makes cops opt-in instead of - # opt-out. Note that when DisabledByDefault is true, cops in user - # configuration will be enabled even if they don't set the Enabled parameter. - DisabledByDefault: false - # Enables the result cache if true. Can be overridden by the --cache command - # line option. - UseCache: true - # Threshold for how many files can be stored in the result cache before some - # of the files are automatically removed. - MaxFilesInCache: 20000 - # The cache will be stored in "rubocop_cache" under this directory. The name - # "/tmp" is special and will be converted to the system temporary directory, - # which is "/tmp" on Unix-like systems, but could be something else on other - # systems. - CacheRootDirectory: /tmp - # The default cache root directory is /tmp, which on most systems is - # writable by any system user. This means that it is possible for a - # malicious user to anticipate the location of Rubocop's cache directory, - # and create a symlink in its place that could cause Rubocop to overwrite - # unintended files, or read malicious input. If you are certain that your - # cache location is secure from this kind of attack, and wish to use a - # symlinked cache location, set this value to "true". - AllowSymlinksInCacheRootDirectory: true - # What MRI version of the Ruby interpreter is the inspected code intended to - # run on? (If there is more than one, set this to the lowest version.) - # If a value is specified for TargetRubyVersion then it is used. - # Else if .ruby-version exists and it contains an MRI version it is used. - # Otherwise we fallback to the oldest officially supported Ruby version (2.0). - TargetRubyVersion: 2.5 - - RSpec: - Patterns: - - "(?:^|/)spec/" - - "(?:^|/)test/" - -# Indent private/protected/public as deep as method definitions -Layout/AccessModifierIndentation: - EnforcedStyle: indent - SupportedStyles: - - outdent - - indent - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - IndentationWidth: ~ - -Style/Alias: - EnforcedStyle: prefer_alias - SupportedStyles: - - prefer_alias - - prefer_alias_method - -# Align the elements of a hash literal if they span more than one line. -Layout/AlignHash: - # Alignment of entries using hash rocket as separator. Valid values are: - # - # key - left alignment of keys - # "a" => 2 - # "bb" => 3 - # separator - alignment of hash rockets, keys are right aligned - # "a" => 2 - # "bb" => 3 - # table - left alignment of keys, hash rockets, and values - # "a" => 2 - # "bb" => 3 - EnforcedHashRocketStyle: key - # Alignment of entries using colon as separator. Valid values are: - # - # key - left alignment of keys - # a: 0 - # bb: 1 - # separator - alignment of colons, keys are right aligned - # a: 0 - # bb: 1 - # table - left alignment of keys and values - # a: 0 - # bb: 1 - EnforcedColonStyle: key - # Select whether hashes that are the last argument in a method call should be - # inspected? Valid values are: - # - # always_inspect - Inspect both implicit and explicit hashes. - # Registers an offense for: - # function(a: 1, - # b: 2) - # Registers an offense for: - # function({a: 1, - # b: 2}) - # always_ignore - Ignore both implicit and explicit hashes. - # Accepts: - # function(a: 1, - # b: 2) - # Accepts: - # function({a: 1, - # b: 2}) - # ignore_implicit - Ignore only implicit hashes. - # Accepts: - # function(a: 1, - # b: 2) - # Registers an offense for: - # function({a: 1, - # b: 2}) - # ignore_explicit - Ignore only explicit hashes. - # Accepts: - # function({a: 1, - # b: 2}) - # Registers an offense for: - # function(a: 1, - # b: 2) - EnforcedLastArgumentHashStyle: always_inspect - SupportedLastArgumentHashStyles: - - always_inspect - - always_ignore - - ignore_implicit - - ignore_explicit - -Layout/AlignParameters: - # Alignment of parameters in multi-line method calls. - # - # The `with_first_parameter` style aligns the following lines along the same - # column as the first parameter. - # - # method_call(a, - # b) - # - # The `with_fixed_indentation` style aligns the following lines with one - # level of indentation relative to the start of the line with the method call. - # - # method_call(a, - # b) - EnforcedStyle: with_first_parameter - SupportedStyles: - - with_first_parameter - - with_fixed_indentation - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - IndentationWidth: ~ - -Style/AndOr: - # Whether `and` and `or` are banned only in conditionals (conditionals) - # or completely (always). - EnforcedStyle: always - SupportedStyles: - - always - - conditionals - -Style/AsciiComments: - Enabled: false - -# Checks if usage of %() or %Q() matches configuration. -Style/BarePercentLiterals: - EnforcedStyle: bare_percent - SupportedStyles: - - percent_q - - bare_percent - -Style/BlockDelimiters: - EnforcedStyle: line_count_based - SupportedStyles: - # The `line_count_based` style enforces braces around single line blocks and - # do..end around multi-line blocks. - - line_count_based - # The `semantic` style enforces braces around functional blocks, where the - # primary purpose of the block is to return a value and do..end for - # procedural blocks, where the primary purpose of the block is its - # side-effects. - # - # This looks at the usage of a block's method to determine its type (e.g. is - # the result of a `map` assigned to a variable or passed to another - # method) but exceptions are permitted in the `ProceduralMethods`, - # `FunctionalMethods` and `IgnoredMethods` sections below. - - semantic - # The `braces_for_chaining` style enforces braces around single line blocks - # and do..end around multi-line blocks, except for multi-line blocks whose - # return value is being chained with another method (in which case braces - # are enforced). - - braces_for_chaining - ProceduralMethods: - # Methods that are known to be procedural in nature but look functional from - # their usage, e.g. - # - # time = Benchmark.realtime do - # foo.bar - # end - # - # Here, the return value of the block is discarded but the return value of - # `Benchmark.realtime` is used. - - benchmark - - bm - - bmbm - - create - - each_with_object - - measure - - new - - realtime - - tap - - with_object - FunctionalMethods: - # Methods that are known to be functional in nature but look procedural from - # their usage, e.g. - # - # let(:foo) { Foo.new } - # - # Here, the return value of `Foo.new` is used to define a `foo` helper but - # doesn't appear to be used from the return value of `let`. - - let - - let! - - subject - - watch - IgnoredMethods: - # Methods that can be either procedural or functional and cannot be - # categorised from their usage alone, e.g. - # - # foo = lambda do |x| - # puts "Hello, #{x}" - # end - # - # foo = lambda do |x| - # x * 100 - # end - # - # Here, it is impossible to tell from the return value of `lambda` whether - # the inner block's return value is significant. - - lambda - - proc - - it - -Style/BracesAroundHashParameters: - EnforcedStyle: no_braces - SupportedStyles: - # The `braces` style enforces braces around all method parameters that are - # hashes. - - braces - # The `no_braces` style checks that the last parameter doesn't have braces - # around it. - - no_braces - # The `context_dependent` style checks that the last parameter doesn't have - # braces around it, but requires braces if the second to last parameter is - # also a hash literal. - - context_dependent - -# Indentation of `when`. -Layout/CaseIndentation: - EnforcedStyle: case - SupportedStyles: - - case - - end - IndentOneStep: false - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - # This only matters if IndentOneStep is true - IndentationWidth: ~ - -Style/ClassAndModuleChildren: - Enabled: false - # Checks the style of children definitions at classes and modules. - # - # Basically there are two different styles: - # - # `nested` - have each child on a separate line - # class Foo - # class Bar - # end - # end - # - # `compact` - combine definitions as much as possible - # class Foo::Bar - # end - # - # The compact style is only forced, for classes / modules with one child. - EnforcedStyle: nested - SupportedStyles: - - nested - - compact - -Style/ClassCheck: - EnforcedStyle: is_a? - SupportedStyles: - - is_a? - - kind_of? - -# Align with the style guide. -Style/CollectionMethods: - # Mapping from undesired method to desired_method - # e.g. to use `detect` over `find`: - # - # CollectionMethods: - # PreferredMethods: - # find: detect - PreferredMethods: - collect: "map" - collect!: "map!" - inject: "reduce" - detect: "find" - find_all: "select" - -# Use ` or %x around command literals. -Style/CommandLiteral: - EnforcedStyle: backticks - # backticks: Always use backticks. - # percent_x: Always use %x. - # mixed: Use backticks on single-line commands, and %x on multi-line commands. - SupportedStyles: - - backticks - - percent_x - - mixed - # If false, the cop will always recommend using %x if one or more backticks - # are found in the command string. - AllowInnerBackticks: false - -# Checks formatting of special comments -Style/CommentAnnotation: - Keywords: - - TODO - - FIXME - - OPTIMIZE - - HACK - - REVIEW - -Style/ConditionalAssignment: - EnforcedStyle: assign_to_condition - SupportedStyles: - - assign_to_condition - - assign_inside_condition - # When configured to `assign_to_condition`, `SingleLineConditionsOnly` - # will only register an offense when all branches of a condition are - # a single line. - # When configured to `assign_inside_condition`, `SingleLineConditionsOnly` - # will only register an offense for assignment to a condition that has - # at least one multiline branch. - SingleLineConditionsOnly: true - -# Checks that you have put a copyright in a comment before any code. -# -# You can override the default Notice in your .rubocop.yml file. -# -# In order to use autocorrect, you must supply a value for the -# AutocorrectNotice key that matches the regexp Notice. A blank -# AutocorrectNotice will cause an error during autocorrect. -# -# Autocorrect will add a copyright notice in a comment at the top -# of the file immediately after any shebang or encoding comments. -# -# Example rubocop.yml: -# -# Style/Copyright: -# Enabled: true -# Notice: 'Copyright (\(c\) )?2015 Yahoo! Inc' -# AutocorrectNotice: "# Copyright (c) 2015 Yahoo! Inc." -# -Style/Copyright: - Notice: '^Copyright (\(c\) )?2[0-9]{3} .+' - AutocorrectNotice: "" - -Style/DocumentationMethod: - RequireForNonPublicMethods: false - -# Multi-line method chaining should be done with leading dots. -Layout/DotPosition: - EnforcedStyle: leading - SupportedStyles: - - leading - - trailing - -# Warn on empty else statements -# empty - warn only on empty else -# nil - warn on else with nil in it -# both - warn on empty else and else with nil in it -Style/EmptyElse: - EnforcedStyle: both - SupportedStyles: - - empty - - nil - - both - -# Use empty lines between defs. -Layout/EmptyLineBetweenDefs: - # If true, this parameter means that single line method definitions don't - # need an empty line between them. - AllowAdjacentOneLineDefs: false - -Layout/EmptyLinesAroundBlockBody: - EnforcedStyle: no_empty_lines - SupportedStyles: - - empty_lines - - no_empty_lines - -Layout/EmptyLinesAroundClassBody: - EnforcedStyle: no_empty_lines - SupportedStyles: - - empty_lines - - no_empty_lines - -Layout/EmptyLinesAroundModuleBody: - EnforcedStyle: no_empty_lines - SupportedStyles: - - empty_lines - - no_empty_lines - -# Checks whether the source file has a utf-8 encoding comment or not -# AutoCorrectEncodingComment must match the regex -# /#.*coding\s?[:=]\s?(?:UTF|utf)-8/ -Style/Encoding: - Enabled: true - -Layout/ExtraSpacing: - # When true, allows most uses of extra spacing if the intent is to align - # things with the previous or next line, not counting empty lines or comment - # lines. - AllowForAlignment: false - # When true, forces the alignment of = in assignments on consecutive lines. - ForceEqualSignAlignment: false - -Naming/FileName: - Exclude: - - "**/Gemfile" - - "**/Rakefile" - - "**/*.gemspec" - # When true, requires that each source file should define a class or module - # with a name which matches the file name (converted to ... case). - # It further expects it to be nested inside modules which match the names - # of subdirectories in its path. - ExpectMatchingDefinition: false - # If non-nil, expect all source file names to match the following regex. - # Only the file name itself is matched, not the entire file path. - # Use anchors as necessary if you want to match the entire name rather than - # just a part of it. - Regex: ~ - # With `IgnoreExecutableScripts` set to `true`, this cop does not - # report offending filenames for executable scripts (i.e. source - # files with a shebang in the first line). - IgnoreExecutableScripts: true - -Layout/IndentFirstArgument: - EnforcedStyle: special_for_inner_method_call_in_parentheses - SupportedStyles: - # The first parameter should always be indented one step more than the - # preceding line. - - consistent - # The first parameter should normally be indented one step more than the - # preceding line, but if it's a parameter for a method call that is itself - # a parameter in a method call, then the inner parameter should be indented - # relative to the inner method. - - special_for_inner_method_call - # Same as special_for_inner_method_call except that the special rule only - # applies if the outer method call encloses its arguments in parentheses. - - special_for_inner_method_call_in_parentheses - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - IndentationWidth: ~ - -# Checks use of for or each in multiline loops. -Style/For: - EnforcedStyle: each - SupportedStyles: - - for - - each - -# Enforce the method used for string formatting. -Style/FormatString: - EnforcedStyle: format - SupportedStyles: - - format - - sprintf - - percent - -Style/FormatStringToken: - EnforcedStyle: template - -Style/FrozenStringLiteralComment: - EnforcedStyle: always - SupportedStyles: - - never - # `always` will always add the frozen string literal comment to a file - # regardless of the Ruby version or if `freeze` or `<<` are called on a - # string literal. If you run code against multiple versions of Ruby, it is - # possible that this will create errors in Ruby 2.3.0+. - - always - -# Built-in global variables are allowed by default. -Style/GlobalVars: - AllowedVariables: [] - -# `MinBodyLength` defines the number of lines of the a body of an if / unless -# needs to have to trigger this cop -Style/GuardClause: - MinBodyLength: 6 - -Style/HashSyntax: - EnforcedStyle: ruby19 - SupportedStyles: - # checks for 1.9 syntax (e.g. {a: 1}) for all symbol keys - - ruby19 - # checks for hash rocket syntax for all hashes - - hash_rockets - # forbids mixed key syntaxes (e.g. {a: 1, :b => 2}) - - no_mixed_keys - # enforces both ruby19 and no_mixed_keys styles - - ruby19_no_mixed_keys - # Force hashes that have a symbol value to use hash rockets - UseHashRocketsWithSymbolValues: false - # Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style - PreferHashRocketsForNonAlnumEndingSymbols: false - -Layout/IndentationConsistency: - # The difference between `rails` and `normal` is that the `rails` style - # prescribes that in classes and modules the `protected` and `private` - # modifier keywords shall be indented the same as public methods and that - # protected and private members shall be indented one step more than the - # modifiers. Other than that, both styles mean that entities on the same - # logical depth shall have the same indentation. - EnforcedStyle: normal - SupportedStyles: - - normal - - rails - -Layout/IndentationWidth: - # Number of spaces for each indentation level. - Width: 2 - -# Checks the indentation of the first element in an array literal. -Layout/IndentFirstArrayElement: - # The value `special_inside_parentheses` means that array literals with - # brackets that have their opening bracket on the same line as a surrounding - # opening round parenthesis, shall have their first element indented relative - # to the first position inside the parenthesis. - # - # The value `consistent` means that the indentation of the first element shall - # always be relative to the first position of the line where the opening - # bracket is. - # - # The value `align_brackets` means that the indentation of the first element - # shall always be relative to the position of the opening bracket. - EnforcedStyle: special_inside_parentheses - SupportedStyles: - - special_inside_parentheses - - consistent - - align_brackets - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - IndentationWidth: ~ - -# Checks the indentation of assignment RHS, when on a different line from LHS -Layout/IndentAssignment: - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - IndentationWidth: ~ - -# Checks the indentation of the first key in a hash literal. -Layout/IndentFirstHashElement: - # The value `special_inside_parentheses` means that hash literals with braces - # that have their opening brace on the same line as a surrounding opening - # round parenthesis, shall have their first key indented relative to the - # first position inside the parenthesis. - # - # The value `consistent` means that the indentation of the first key shall - # always be relative to the first position of the line where the opening - # brace is. - # - # The value `align_braces` means that the indentation of the first key shall - # always be relative to the position of the opening brace. - EnforcedStyle: special_inside_parentheses - SupportedStyles: - - special_inside_parentheses - - consistent - - align_braces - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - IndentationWidth: ~ - -Style/Lambda: - EnforcedStyle: line_count_dependent - SupportedStyles: - - line_count_dependent - - lambda - - literal - Exclude: - - "**/types/**/*" - - "**/*_interface.rb" - -Style/LambdaCall: - EnforcedStyle: call - SupportedStyles: - - call - - braces - -Style/Next: - # With `always` all conditions at the end of an iteration needs to be - # replaced by next - with `skip_modifier_ifs` the modifier if like this one - # are ignored: [1, 2].each { |a| return "yes" if a == 1 } - EnforcedStyle: skip_modifier_ifs - # `MinBodyLength` defines the number of lines of the a body of an if / unless - # needs to have to trigger this cop - MinBodyLength: 3 - SupportedStyles: - - skip_modifier_ifs - - always - -Style/NonNilCheck: - # With `IncludeSemanticChanges` set to `true`, this cop reports offenses for - # `!x.nil?` and autocorrects that and `x != nil` to solely `x`, which is - # **usually** OK, but might change behavior. - # - # With `IncludeSemanticChanges` set to `false`, this cop does not report - # offenses for `!x.nil?` and does no changes that might change behavior. - IncludeSemanticChanges: false - -Style/NumericPredicate: - EnforcedStyle: predicate - SupportedStyles: - - predicate - - comparison - -Style/MethodDefParentheses: - EnforcedStyle: require_parentheses - SupportedStyles: - - require_parentheses - - require_no_parentheses - - require_no_parentheses_except_multiline - -Naming/MethodName: - EnforcedStyle: snake_case - SupportedStyles: - - snake_case - - camelCase - -Style/ModuleFunction: - EnforcedStyle: module_function - SupportedStyles: - - module_function - - extend_self - -Layout/MultilineArrayBraceLayout: - EnforcedStyle: symmetrical - SupportedStyles: - # symmetrical: closing brace is positioned in same way as opening brace - # new_line: closing brace is always on a new line - # same_line: closing brace is always on the same line as last element - - symmetrical - - new_line - - same_line - -Layout/MultilineAssignmentLayout: - # The types of assignments which are subject to this rule. - SupportedTypes: - - block - - case - - class - - if - - kwbegin - - module - EnforcedStyle: new_line - SupportedStyles: - # Ensures that the assignment operator and the rhs are on the same line for - # the set of supported types. - - same_line - # Ensures that the assignment operator and the rhs are on separate lines - # for the set of supported types. - - new_line - -Layout/MultilineHashBraceLayout: - EnforcedStyle: symmetrical - SupportedStyles: - # symmetrical: closing brace is positioned in same way as opening brace - # new_line: closing brace is always on a new line - # same_line: closing brace is always on same line as last element - - symmetrical - - new_line - - same_line - -Layout/MultilineMethodCallBraceLayout: - EnforcedStyle: symmetrical - SupportedStyles: - # symmetrical: closing brace is positioned in same way as opening brace - # new_line: closing brace is always on a new line - # same_line: closing brace is always on the same line as last argument - - symmetrical - - new_line - - same_line - -Layout/MultilineMethodCallIndentation: - EnforcedStyle: aligned - SupportedStyles: - - aligned - - indented - - indented_relative_to_receiver - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - IndentationWidth: ~ - -Layout/MultilineMethodDefinitionBraceLayout: - EnforcedStyle: symmetrical - SupportedStyles: - # symmetrical: closing brace is positioned in same way as opening brace - # new_line: closing brace is always on a new line - # same_line: closing brace is always on the same line as last parameter - - symmetrical - - new_line - - same_line - -Layout/MultilineOperationIndentation: - EnforcedStyle: aligned - SupportedStyles: - - aligned - - indented - # By default, the indentation width from Style/IndentationWidth is used - # But it can be overridden by setting this parameter - IndentationWidth: ~ - -Style/NumericLiterals: - MinDigits: 5 - -Style/NumericLiteralPrefix: - EnforcedOctalStyle: zero_with_o - SupportedOctalStyles: - - zero_with_o - - zero_only - -Style/OptionHash: - # A list of parameter names that will be flagged by this cop. - SuspiciousParamNames: - - options - - opts - - args - - params - - parameters - -# Allow safe assignment in conditions. -Style/ParenthesesAroundCondition: - AllowSafeAssignment: true - -Style/PercentLiteralDelimiters: - PreferredDelimiters: - "%": () - "%i": () - "%q": () - "%Q": () - "%r": "{}" - "%s": () - "%w": () - "%W": () - "%x": () - -Style/PercentQLiterals: - EnforcedStyle: lower_case_q - SupportedStyles: - - lower_case_q # Use %q when possible, %Q when necessary - - upper_case_q # Always use %Q - -Naming/PredicateName: - # Predicate name prefixes. - NamePrefix: - - is_ - - has_ - - have_ - # Predicate name prefixes that should be removed. - NamePrefixBlacklist: - - is_ - - have_ - # Predicate names which, despite having a blacklisted prefix, or no ?, - # should still be accepted - NameWhitelist: - - is_a? - # Exclude Rspec specs because there is a strong convetion to write spec - # helpers in the form of `have_something` or `be_something`. - Exclude: - - "**/spec/**/*" - - "**/test/**/*" - -Style/PreferredHashMethods: - Enabled: true - EnforcedStyle: verbose - -Style/DateTime: - Enabled: true - -Style/Documentation: - Enabled: false - -Style/RaiseArgs: - EnforcedStyle: exploded - SupportedStyles: - - compact # raise Exception.new(msg) - - exploded # raise Exception, msg - -Style/RedundantReturn: - # When true allows code like `return x, y`. - AllowMultipleReturnValues: false - -# Use / or %r around regular expressions. -Style/RegexpLiteral: - EnforcedStyle: slashes - # slashes: Always use slashes. - # percent_r: Always use %r. - # mixed: Use slashes on single-line regexes, and %r on multi-line regexes. - SupportedStyles: - - slashes - - percent_r - - mixed - # If false, the cop will always recommend using %r if one or more slashes - # are found in the regexp string. - AllowInnerSlashes: false - -Style/SafeNavigation: - Enabled: false - -Style/Semicolon: - # Allow ; to separate several expressions on the same line. - AllowAsExpressionSeparator: false - -Style/SignalException: - EnforcedStyle: only_raise - SupportedStyles: - - only_raise - - only_fail - - semantic - -Style/SingleLineBlockParams: - Methods: - - reduce: - - a - - e - - inject: - - a - - e - -Style/SingleLineMethods: - AllowIfMethodIsEmpty: true - -Layout/SpaceBeforeFirstArg: - # When true, allows most uses of extra spacing if the intent is to align - # things with the previous or next line, not counting empty lines or comment - # lines. - AllowForAlignment: true - -Style/SpecialGlobalVars: - EnforcedStyle: use_english_names - SupportedStyles: - - use_perl_names - - use_english_names - -Style/StabbyLambdaParentheses: - EnforcedStyle: require_parentheses - SupportedStyles: - - require_parentheses - - require_no_parentheses - -Style/StringLiterals: - EnforcedStyle: double_quotes - SupportedStyles: - - single_quotes - - double_quotes - # If true, strings which span multiple lines using \ for continuation must - # use the same type of quotes on each line. - ConsistentQuotesInMultiline: false - -Style/StringLiteralsInInterpolation: - EnforcedStyle: double_quotes - SupportedStyles: - - single_quotes - - double_quotes - -Style/StringMethods: - # Mapping from undesired method to desired_method - # e.g. to use `to_sym` over `intern`: - # - # StringMethods: - # PreferredMethods: - # intern: to_sym - PreferredMethods: - intern: to_sym - -Layout/SpaceAroundBlockParameters: - EnforcedStyleInsidePipes: no_space - -Layout/SpaceAroundEqualsInParameterDefault: - EnforcedStyle: space - SupportedStyles: - - space - - no_space - -Layout/SpaceAroundOperators: - # When true, allows most uses of extra spacing if the intent is to align - # with an operator on the previous or next line, not counting empty lines - # or comment lines. - AllowForAlignment: true - -Layout/SpaceBeforeBlockBraces: - EnforcedStyle: space - SupportedStyles: - - space - - no_space - -Layout/SpaceInsideBlockBraces: - EnforcedStyle: space - SupportedStyles: - - space - - no_space - # Valid values are: space, no_space - EnforcedStyleForEmptyBraces: no_space - # Space between { and |. Overrides EnforcedStyle if there is a conflict. - SpaceBeforeBlockParameters: true - -Layout/SpaceInsideHashLiteralBraces: - EnforcedStyle: space - EnforcedStyleForEmptyBraces: no_space - SupportedStyles: - - space - - no_space - # "compact" normally requires a space inside hash braces, with the exception - # that successive left braces or right braces are collapsed together - - compact - -Layout/SpaceInsideStringInterpolation: - EnforcedStyle: no_space - SupportedStyles: - - space - - no_space - -Style/AccessModifierDeclarations: - Enabled: false - -Style/SymbolArray: - EnforcedStyle: brackets - SupportedStyles: - - percent - - brackets - -Style/SymbolProc: - # A list of method names to be ignored by the check. - # The names should be fairly unique, otherwise you'll end up ignoring lots of code. - IgnoredMethods: - - respond_to - - define_method - -Style/TernaryParentheses: - EnforcedStyle: require_no_parentheses - SupportedStyles: - - require_parentheses - - require_no_parentheses - AllowSafeAssignment: true - -Layout/TrailingBlankLines: - EnforcedStyle: final_newline - SupportedStyles: - - final_newline - - final_blank_line - -Style/TrailingCommaInArguments: - # If `comma`, the cop requires a comma after the last argument, but only for - # parenthesized method calls where each argument is on its own line. - # If `consistent_comma`, the cop requires a comma after the last argument, - # for all parenthesized method calls with arguments. - EnforcedStyleForMultiline: no_comma - -Style/TrailingCommaInArrayLiteral: - # If `comma`, the cop requires a comma after the last item in an array or - # hash, but only when each item is on its own line. - # If `consistent_comma`, the cop requires a comma after the last item of all - # non-empty array and hash literals. - EnforcedStyleForMultiline: no_comma - -Style/TrailingCommaInHashLiteral: - # If `comma`, the cop requires a comma after the last item in an array or - # hash, but only when each item is on its own line. - # If `consistent_comma`, the cop requires a comma after the last item of all - # non-empty array and hash literals. - EnforcedStyleForMultiline: no_comma - -# TrivialAccessors requires exact name matches and doesn't allow -# predicated methods by default. -Style/TrivialAccessors: - # When set to false the cop will suggest the use of accessor methods - # in situations like: - # - # def name - # @other_name - # end - # - # This way you can uncover "hidden" attributes in your code. - ExactNameMatch: true - AllowPredicates: true - # Allows trivial writers that don't end in an equal sign. e.g. - # - # def on_exception(action) - # @on_exception=action - # end - # on_exception :restart - # - # Commonly used in DSLs - AllowDSLWriters: false - IgnoreClassMethods: false - Whitelist: - - to_ary - - to_a - - to_c - - to_enum - - to_h - - to_hash - - to_i - - to_int - - to_io - - to_open - - to_path - - to_proc - - to_r - - to_regexp - - to_str - - to_s - - to_sym - -Naming/VariableName: - EnforcedStyle: snake_case - SupportedStyles: - - snake_case - - camelCase - -Naming/VariableNumber: - EnforcedStyle: normalcase - SupportedStyles: - - snake_case - - normalcase - - non_integer - -# WordArray enforces how array literals of word-like strings should be expressed. -Style/WordArray: - EnforcedStyle: percent - SupportedStyles: - # percent style: %w(word1 word2) - - percent - # bracket style: ["word1", "word2"] - - brackets - # The MinSize option causes the WordArray rule to be ignored for arrays - # smaller than a certain size. The rule is only applied to arrays - # whose element count is greater than or equal to MinSize. - MinSize: 2 - # The regular expression WordRegex decides what is considered a word. - WordRegex: !ruby/regexp '/\A[\p{Word}\n\t]+\z/' - -##################### Metrics ################################## - -Metrics/AbcSize: - # The ABC size is a calculated magnitude, so this number can be an Integer or - # a Float. - Max: 15 - Enabled: false - -Metrics/BlockNesting: - Max: 3 - -Metrics/ClassLength: - CountComments: false # count full line comments? - Max: 100 - Enabled: false - -Metrics/ModuleLength: - CountComments: false # count full line comments? - Max: 100 - Enabled: false - -# Avoid complex methods. -Metrics/CyclomaticComplexity: - Max: 9 - Exclude: - - "**/*/permissions.rb" - -Metrics/LineLength: - Max: 180 - # To make it possible to copy or click on URIs in the code, we allow lines - # containing a URI to be longer than Max. - AllowHeredoc: true - AllowURI: true - URISchemes: - - http - - https - Exclude: - - "**/spec/**/*" - -Metrics/MethodLength: - CountComments: false # count full line comments? - Max: 15 - Enabled: false - -Metrics/ParameterLists: - Max: 5 - CountKeywordArgs: true - Exclude: - - "decidim-core/lib/decidim/filter_form_builder.rb" - -Metrics/PerceivedComplexity: - Max: 10 - Exclude: - - "**/*/permissions.rb" - -##################### Lint ################################## - -Lint/AmbiguousBlockAssociation: - Enabled: true - Exclude: - - "**/abilities/**/*" - -# Allow safe assignment in conditions. -Lint/AssignmentInCondition: - AllowSafeAssignment: true - -# checks whether the end keywords are aligned properly for `do` `end` blocks. -Layout/BlockAlignment: - # The value `start_of_block` means that the `end` should be aligned with line - # where the `do` keyword appears. - # The value `start_of_line` means it should be aligned with the whole - # expression's starting line. - # The value `either` means both are allowed. - EnforcedStyleAlignWith: either - -# Align ends correctly. -Layout/EndAlignment: - # The value `keyword` means that `end` should be aligned with the matching - # keyword (if, while, etc.). - # The value `variable` means that in assignments, `end` should be aligned - # with the start of the variable on the left hand side of `=`. In all other - # situations, `end` should still be aligned with the keyword. - # The value `start_of_line` means that `end` should be aligned with the start - # of the line which the matching keyword appears on. - EnforcedStyleAlignWith: keyword - AutoCorrect: false - -Layout/DefEndAlignment: - # The value `def` means that `end` should be aligned with the def keyword. - # The value `start_of_line` means that `end` should be aligned with method - # calls like `private`, `public`, etc, if present in front of the `def` - # keyword on the same line. - EnforcedStyleAlignWith: start_of_line - AutoCorrect: false - -Lint/InheritException: - # The default base class in favour of `Exception`. - EnforcedStyle: runtime_error - SupportedStyles: - - runtime_error - - standard_error - -# Checks for unused block arguments -Lint/UnusedBlockArgument: - IgnoreEmptyBlocks: true - AllowUnusedKeywordArguments: false - -# Checks for unused method arguments. -Lint/UnusedMethodArgument: - AllowUnusedKeywordArguments: false - IgnoreEmptyMethods: true - -##################### Performance ############################ - -Metrics/BlockLength: - Enabled: false - -RSpec/BeforeAfterAll: - Enabled: true - -RSpec/ContextWording: - Enabled: true - Prefixes: - - when - - with - - without - - and - -RSpec/DescribeClass: - Exclude: - - spec/gemfiles_spec.rb - - spec/js_bundles_spec.rb - - spec/i18n_spec.rb - - "**/*/spec/**/*_badge_spec.rb" - - decidim-core/spec/lib/global_engines_spec.rb - - "**/tasks/**/*" - -RSpec/EmptyExampleGroup: - Exclude: - - decidim-core/spec/lib/participatory_space_manifest_spec.rb - -RSpec/ExampleLength: - Max: 49 - -RSpec/ExpectInHook: - Enabled: false - -RSpec/IteratedExpectation: - Enabled: true - -RSpec/LetSetup: - Enabled: false - -RSpec/MessageSpies: - Enabled: false - -RSpec/MultipleExpectations: - Enabled: false - -RSpec/NestedGroups: - Max: 7 - -RSpec/NamedSubject: - Enabled: false - -RSpec/VerifiedDoubles: - Enabled: false - -RSpec/LeakyConstantDeclaration: - Enabled: false - -RSpec/DescribedClass: - Enabled: false - -inherit_from: .rubocop_rails.yml +inherit_from: + - .rubocop_ruby.yml + - .rubocop_rails.yml diff --git a/.rubocop_rails.yml b/.rubocop_rails.yml index 19fe38fa9..0cf3b441c 100644 --- a/.rubocop_rails.yml +++ b/.rubocop_rails.yml @@ -5,22 +5,25 @@ Rails: Rails/ActionFilter: Include: - - decidim-*/app/controllers/**/*.rb + - app/controllers/**/*.rb + +Rails/ContentTag: + Enabled: false Rails/CreateTableWithTimestamps: Enabled: false Rails/EnumUniqueness: Include: - - decidim-*/app/models/**/*.rb + - app/models/**/*.rb Rails/Exit: Include: - - decidim-*/app/**/*.rb - - decidim-*/config/**/*.rb - - decidim-*/lib/**/*.rb + - app/**/*.rb + - config/**/*.rb + - lib/**/*.rb Exclude: - - decidim-*/lib/**/*.rake + - lib/**/*.rake Rails/FindBy: Include: @@ -28,56 +31,57 @@ Rails/FindBy: Rails/FindEach: Include: - - decidim-*/app/models/**/*.rb + - app/models/**/*.rb Rails/HasAndBelongsToMany: Include: - - decidim-*/app/models/**/*.rb + - app/models/**/*.rb Rails/HasManyOrHasOneDependent: Include: - - decidim-*/app/models/**/*.rb + - app/models/**/*.rb Rails/InverseOf: Enabled: false Rails/LexicallyScopedActionFilter: Include: - - decidim-*/app/controllers/**/*.rb + - app/controllers/**/*.rb Rails/NotNullColumn: Enabled: false Rails/Output: Include: - - decidim-*/app/**/*.rb - - decidim-*/config/**/*.rb - - decidim-*/db/**/*.rb - - decidim-*/lib/**/*.rb + - app/**/*.rb + - config/**/*.rb + - db/**/*.rb + - lib/**/*.rb Exclude: - - decidim-core/db/seeds.rb - - decidim-core/lib/decidim/core.rb - - decidim-core/lib/decidim/component_manifest.rb - - decidim-core/lib/decidim/participatory_space_manifest.rb - - decidim-system/db/seeds.rb - + - db/seeds.rb Rails/OutputSafety: Enabled: false +Rails/Pluck: + Enabled: false + +Rails/RakeEnvironment: + Enabled: false + Rails/ReadWriteAttribute: Include: - - decidim-*/app/models/**/*.rb + - app/models/**/*.rb Rails/ReversibleMigration: Enabled: false Rails/ScopeArgs: Include: - - decidim-*/app/models/**/*.rb + - app/models/**/*.rb Rails/SkipsModelValidations: Enabled: true Rails/Validation: Include: - - decidim-*/app/models/**/*.rb + - app/models/**/*.rb diff --git a/.rubocop_ruby.yml b/.rubocop_ruby.yml new file mode 100644 index 000000000..b05a2f7a8 --- /dev/null +++ b/.rubocop_ruby.yml @@ -0,0 +1,1752 @@ +require: + - rubocop-rspec + - rubocop-faker + +# Common configuration. +AllCops: + Include: + - .simplecov + - "**/*.rb" + - "**/*.rake" + - "**/*.gemspec" + - "**/*.ru" + - "**/Gemfile" + - "**/Rakefile" + Exclude: + - "**/vendor/**/*" + - "development_app/**/*" + - "spec/decidim_dummy_app/**/*" + - "node_modules/**/*" + # Default formatter will be used if no -f/--format option is given. + DefaultFormatter: progress + # Cop names are not displayed in offense messages by default. Change behavior + # by overriding DisplayCopNames, or by giving the -D/--display-cop-names + # option. + DisplayCopNames: true + # Style guide URLs are not displayed in offense messages by default. Change + # behavior by overriding DisplayStyleGuide, or by giving the + # -S/--display-style-guide option. + DisplayStyleGuide: false + # Extra details are not displayed in offense messages by default. Change + # behavior by overriding ExtraDetails, or by giving the + # -E/--extra-details option. + ExtraDetails: false + NewCops: enable + # Additional cops that do not reference a style guide rule may be enabled by + # default. Change behavior by overriding StyleGuideCopsOnly, or by giving + # the --only-guide-cops option. + StyleGuideCopsOnly: false + # All cops except the ones in disabled.yml are enabled by default. Change + # this behavior by overriding DisabledByDefault. When DisabledByDefault is + # true, all cops in the default configuration are disabled, and and only cops + # in user configuration are enabled. This makes cops opt-in instead of + # opt-out. Note that when DisabledByDefault is true, cops in user + # configuration will be enabled even if they don't set the Enabled parameter. + DisabledByDefault: false + # Enables the result cache if true. Can be overridden by the --cache command + # line option. + UseCache: true + # Threshold for how many files can be stored in the result cache before some + # of the files are automatically removed. + MaxFilesInCache: 20000 + # The cache will be stored in "rubocop_cache" under this directory. The name + # "/tmp" is special and will be converted to the system temporary directory, + # which is "/tmp" on Unix-like systems, but could be something else on other + # systems. + CacheRootDirectory: /tmp + # The default cache root directory is /tmp, which on most systems is + # writable by any system user. This means that it is possible for a + # malicious user to anticipate the location of Rubocop's cache directory, + # and create a symlink in its place that could cause Rubocop to overwrite + # unintended files, or read malicious input. If you are certain that your + # cache location is secure from this kind of attack, and wish to use a + # symlinked cache location, set this value to "true". + AllowSymlinksInCacheRootDirectory: true + # What MRI version of the Ruby interpreter is the inspected code intended to + # run on? (If there is more than one, set this to the lowest version.) + # If a value is specified for TargetRubyVersion then it is used. + # Else if .ruby-version exists and it contains an MRI version it is used. + # Otherwise we fallback to the oldest officially supported Ruby version (2.0). + TargetRubyVersion: 2.7 + + RSpec: + Patterns: + - "(?:^|/)spec/" + - "(?:^|/)test/" + +# Indent private/protected/public as deep as method definitions +Layout/AccessModifierIndentation: + EnforcedStyle: indent + SupportedStyles: + - outdent + - indent + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + IndentationWidth: ~ + +Style/Alias: + EnforcedStyle: prefer_alias + SupportedStyles: + - prefer_alias + - prefer_alias_method + +# Align the elements of a hash literal if they span more than one line. +Layout/HashAlignment: + # Alignment of entries using hash rocket as separator. Valid values are: + # + # key - left alignment of keys + # "a" => 2 + # "bb" => 3 + # separator - alignment of hash rockets, keys are right aligned + # "a" => 2 + # "bb" => 3 + # table - left alignment of keys, hash rockets, and values + # "a" => 2 + # "bb" => 3 + EnforcedHashRocketStyle: key + # Alignment of entries using colon as separator. Valid values are: + # + # key - left alignment of keys + # a: 0 + # bb: 1 + # separator - alignment of colons, keys are right aligned + # a: 0 + # bb: 1 + # table - left alignment of keys and values + # a: 0 + # bb: 1 + EnforcedColonStyle: key + # Select whether hashes that are the last argument in a method call should be + # inspected? Valid values are: + # + # always_inspect - Inspect both implicit and explicit hashes. + # Registers an offense for: + # function(a: 1, + # b: 2) + # Registers an offense for: + # function({a: 1, + # b: 2}) + # always_ignore - Ignore both implicit and explicit hashes. + # Accepts: + # function(a: 1, + # b: 2) + # Accepts: + # function({a: 1, + # b: 2}) + # ignore_implicit - Ignore only implicit hashes. + # Accepts: + # function(a: 1, + # b: 2) + # Registers an offense for: + # function({a: 1, + # b: 2}) + # ignore_explicit - Ignore only explicit hashes. + # Accepts: + # function({a: 1, + # b: 2}) + # Registers an offense for: + # function(a: 1, + # b: 2) + EnforcedLastArgumentHashStyle: always_inspect + SupportedLastArgumentHashStyles: + - always_inspect + - always_ignore + - ignore_implicit + - ignore_explicit + +Layout/ParameterAlignment: + # Alignment of parameters in multi-line method calls. + # + # The `with_first_parameter` style aligns the following lines along the same + # column as the first parameter. + # + # method_call(a, + # b) + # + # The `with_fixed_indentation` style aligns the following lines with one + # level of indentation relative to the start of the line with the method call. + # + # method_call(a, + # b) + EnforcedStyle: with_first_parameter + SupportedStyles: + - with_first_parameter + - with_fixed_indentation + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + IndentationWidth: ~ + +Style/AndOr: + # Whether `and` and `or` are banned only in conditionals (conditionals) + # or completely (always). + EnforcedStyle: always + SupportedStyles: + - always + - conditionals + +Style/AsciiComments: + Enabled: false + +# Checks if usage of %() or %Q() matches configuration. +Style/BarePercentLiterals: + EnforcedStyle: bare_percent + SupportedStyles: + - percent_q + - bare_percent + +Style/BlockDelimiters: + EnforcedStyle: line_count_based + SupportedStyles: + # The `line_count_based` style enforces braces around single line blocks and + # do..end around multi-line blocks. + - line_count_based + # The `semantic` style enforces braces around functional blocks, where the + # primary purpose of the block is to return a value and do..end for + # procedural blocks, where the primary purpose of the block is its + # side-effects. + # + # This looks at the usage of a block's method to determine its type (e.g. is + # the result of a `map` assigned to a variable or passed to another + # method) but exceptions are permitted in the `ProceduralMethods`, + # `FunctionalMethods` and `IgnoredMethods` sections below. + - semantic + # The `braces_for_chaining` style enforces braces around single line blocks + # and do..end around multi-line blocks, except for multi-line blocks whose + # return value is being chained with another method (in which case braces + # are enforced). + - braces_for_chaining + ProceduralMethods: + # Methods that are known to be procedural in nature but look functional from + # their usage, e.g. + # + # time = Benchmark.realtime do + # foo.bar + # end + # + # Here, the return value of the block is discarded but the return value of + # `Benchmark.realtime` is used. + - benchmark + - bm + - bmbm + - create + - each_with_object + - measure + - new + - realtime + - tap + - with_object + FunctionalMethods: + # Methods that are known to be functional in nature but look procedural from + # their usage, e.g. + # + # let(:foo) { Foo.new } + # + # Here, the return value of `Foo.new` is used to define a `foo` helper but + # doesn't appear to be used from the return value of `let`. + - let + - let! + - subject + - watch + IgnoredMethods: + # Methods that can be either procedural or functional and cannot be + # categorised from their usage alone, e.g. + # + # foo = lambda do |x| + # puts "Hello, #{x}" + # end + # + # foo = lambda do |x| + # x * 100 + # end + # + # Here, it is impossible to tell from the return value of `lambda` whether + # the inner block's return value is significant. + - lambda + - proc + - it + +Style/ExplicitBlockArgument: + Enabled: false + +Style/HashEachMethods: + Enabled: false + +Style/HashLikeCase: + MinBranchesCount: 5 + +# Indentation of `when`. +Layout/CaseIndentation: + EnforcedStyle: case + SupportedStyles: + - case + - end + IndentOneStep: false + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + # This only matters if IndentOneStep is true + IndentationWidth: ~ + +Style/ClassAndModuleChildren: + Enabled: false + # Checks the style of children definitions at classes and modules. + # + # Basically there are two different styles: + # + # `nested` - have each child on a separate line + # class Foo + # class Bar + # end + # end + # + # `compact` - combine definitions as much as possible + # class Foo::Bar + # end + # + # The compact style is only forced, for classes / modules with one child. + EnforcedStyle: nested + SupportedStyles: + - nested + - compact + +Style/ClassCheck: + EnforcedStyle: is_a? + SupportedStyles: + - is_a? + - kind_of? + +# Align with the style guide. +Style/CollectionMethods: + # Mapping from undesired method to desired_method + # e.g. to use `detect` over `find`: + # + # CollectionMethods: + # PreferredMethods: + # find: detect + PreferredMethods: + collect: "map" + collect!: "map!" + inject: "reduce" + detect: "find" + find_all: "select" + +# Use ` or %x around command literals. +Style/CommandLiteral: + EnforcedStyle: backticks + # backticks: Always use backticks. + # percent_x: Always use %x. + # mixed: Use backticks on single-line commands, and %x on multi-line commands. + SupportedStyles: + - backticks + - percent_x + - mixed + # If false, the cop will always recommend using %x if one or more backticks + # are found in the command string. + AllowInnerBackticks: false + +# Checks formatting of special comments +Style/CommentAnnotation: + Keywords: + - TODO + - FIXME + - OPTIMIZE + - HACK + - REVIEW + +Style/ConditionalAssignment: + EnforcedStyle: assign_to_condition + SupportedStyles: + - assign_to_condition + - assign_inside_condition + # When configured to `assign_to_condition`, `SingleLineConditionsOnly` + # will only register an offense when all branches of a condition are + # a single line. + # When configured to `assign_inside_condition`, `SingleLineConditionsOnly` + # will only register an offense for assignment to a condition that has + # at least one multiline branch. + SingleLineConditionsOnly: true + +# Checks that you have put a copyright in a comment before any code. +# +# You can override the default Notice in your .rubocop.yml file. +# +# In order to use autocorrect, you must supply a value for the +# AutocorrectNotice key that matches the regexp Notice. A blank +# AutocorrectNotice will cause an error during autocorrect. +# +# Autocorrect will add a copyright notice in a comment at the top +# of the file immediately after any shebang or encoding comments. +# +# Example rubocop.yml: +# +# Style/Copyright: +# Enabled: true +# Notice: 'Copyright (\(c\) )?2015 Yahoo! Inc' +# AutocorrectNotice: "# Copyright (c) 2015 Yahoo! Inc." +# +Style/Copyright: + Notice: '^Copyright (\(c\) )?2[0-9]{3} .+' + AutocorrectNotice: "" + +Style/DocumentationMethod: + RequireForNonPublicMethods: false + +# Multi-line method chaining should be done with leading dots. +Layout/DotPosition: + EnforcedStyle: leading + SupportedStyles: + - leading + - trailing + +# Warn on empty else statements +# empty - warn only on empty else +# nil - warn on else with nil in it +# both - warn on empty else and else with nil in it +Style/EmptyElse: + EnforcedStyle: both + SupportedStyles: + - empty + - nil + - both + +# Use empty lines between defs. +Layout/EmptyLineBetweenDefs: + # If true, this parameter means that single line method definitions don't + # need an empty line between them. + AllowAdjacentOneLineDefs: false + +Layout/EmptyLinesAroundBlockBody: + EnforcedStyle: no_empty_lines + SupportedStyles: + - empty_lines + - no_empty_lines + +Layout/EmptyLinesAroundClassBody: + EnforcedStyle: no_empty_lines + SupportedStyles: + - empty_lines + - no_empty_lines + +Layout/EmptyLinesAroundModuleBody: + EnforcedStyle: no_empty_lines + SupportedStyles: + - empty_lines + - no_empty_lines + +# Checks whether the source file has a utf-8 encoding comment or not +# AutoCorrectEncodingComment must match the regex +# /#.*coding\s?[:=]\s?(?:UTF|utf)-8/ +Style/Encoding: + Enabled: true + +Layout/ExtraSpacing: + # When true, allows most uses of extra spacing if the intent is to align + # things with the previous or next line, not counting empty lines or comment + # lines. + AllowForAlignment: false + # When true, forces the alignment of = in assignments on consecutive lines. + ForceEqualSignAlignment: false + +Naming/FileName: + Exclude: + - "**/Gemfile" + - "**/Rakefile" + - "**/*.gemspec" + # When true, requires that each source file should define a class or module + # with a name which matches the file name (converted to ... case). + # It further expects it to be nested inside modules which match the names + # of subdirectories in its path. + ExpectMatchingDefinition: false + # If non-nil, expect all source file names to match the following regex. + # Only the file name itself is matched, not the entire file path. + # Use anchors as necessary if you want to match the entire name rather than + # just a part of it. + Regex: ~ + # With `IgnoreExecutableScripts` set to `true`, this cop does not + # report offending filenames for executable scripts (i.e. source + # files with a shebang in the first line). + IgnoreExecutableScripts: true + +Layout/FirstArgumentIndentation: + EnforcedStyle: special_for_inner_method_call_in_parentheses + SupportedStyles: + # The first parameter should always be indented one step more than the + # preceding line. + - consistent + # The first parameter should normally be indented one step more than the + # preceding line, but if it's a parameter for a method call that is itself + # a parameter in a method call, then the inner parameter should be indented + # relative to the inner method. + - special_for_inner_method_call + # Same as special_for_inner_method_call except that the special rule only + # applies if the outer method call encloses its arguments in parentheses. + - special_for_inner_method_call_in_parentheses + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + IndentationWidth: ~ + +# Checks use of for or each in multiline loops. +Style/For: + EnforcedStyle: each + SupportedStyles: + - for + - each + +# Enforce the method used for string formatting. +Style/FormatString: + EnforcedStyle: format + SupportedStyles: + - format + - sprintf + - percent + +Style/FormatStringToken: + EnforcedStyle: template + +Style/FrozenStringLiteralComment: + EnforcedStyle: always + SupportedStyles: + - never + # `always` will always add the frozen string literal comment to a file + # regardless of the Ruby version or if `freeze` or `<<` are called on a + # string literal. If you run code against multiple versions of Ruby, it is + # possible that this will create errors in Ruby 2.3.0+. + - always + +# Built-in global variables are allowed by default. +Style/GlobalVars: + AllowedVariables: [] + +# `MinBodyLength` defines the number of lines of the a body of an if / unless +# needs to have to trigger this cop +Style/GuardClause: + MinBodyLength: 6 + +Style/HashSyntax: + EnforcedStyle: ruby19 + SupportedStyles: + # checks for 1.9 syntax (e.g. {a: 1}) for all symbol keys + - ruby19 + # checks for hash rocket syntax for all hashes + - hash_rockets + # forbids mixed key syntaxes (e.g. {a: 1, :b => 2}) + - no_mixed_keys + # enforces both ruby19 and no_mixed_keys styles + - ruby19_no_mixed_keys + # Force hashes that have a symbol value to use hash rockets + UseHashRocketsWithSymbolValues: false + # Do not suggest { a?: 1 } over { :a? => 1 } in ruby19 style + PreferHashRocketsForNonAlnumEndingSymbols: false + +Layout/IndentationConsistency: + # The difference between `rails` and `normal` is that the `rails` style + # prescribes that in classes and modules the `protected` and `private` + # modifier keywords shall be indented the same as public methods and that + # protected and private members shall be indented one step more than the + # modifiers. Other than that, both styles mean that entities on the same + # logical depth shall have the same indentation. + EnforcedStyle: normal + SupportedStyles: + - normal + - rails + +Layout/IndentationWidth: + # Number of spaces for each indentation level. + Width: 2 + +# Checks the indentation of the first element in an array literal. +Layout/FirstArrayElementIndentation: + # The value `special_inside_parentheses` means that array literals with + # brackets that have their opening bracket on the same line as a surrounding + # opening round parenthesis, shall have their first element indented relative + # to the first position inside the parenthesis. + # + # The value `consistent` means that the indentation of the first element shall + # always be relative to the first position of the line where the opening + # bracket is. + # + # The value `align_brackets` means that the indentation of the first element + # shall always be relative to the position of the opening bracket. + EnforcedStyle: special_inside_parentheses + SupportedStyles: + - special_inside_parentheses + - consistent + - align_brackets + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + IndentationWidth: ~ + +# Checks the indentation of assignment RHS, when on a different line from LHS +Layout/AssignmentIndentation: + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + IndentationWidth: ~ + +# Checks the indentation of the first key in a hash literal. +Layout/FirstHashElementIndentation: + # The value `special_inside_parentheses` means that hash literals with braces + # that have their opening brace on the same line as a surrounding opening + # round parenthesis, shall have their first key indented relative to the + # first position inside the parenthesis. + # + # The value `consistent` means that the indentation of the first key shall + # always be relative to the first position of the line where the opening + # brace is. + # + # The value `align_braces` means that the indentation of the first key shall + # always be relative to the position of the opening brace. + EnforcedStyle: special_inside_parentheses + SupportedStyles: + - special_inside_parentheses + - consistent + - align_braces + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + IndentationWidth: ~ + +Style/Lambda: + EnforcedStyle: line_count_dependent + SupportedStyles: + - line_count_dependent + - lambda + - literal + Exclude: + - "**/types/**/*" + - "**/*_interface.rb" + +Style/LambdaCall: + EnforcedStyle: call + SupportedStyles: + - call + - braces + +Style/Next: + # With `always` all conditions at the end of an iteration needs to be + # replaced by next - with `skip_modifier_ifs` the modifier if like this one + # are ignored: [1, 2].each { |a| return "yes" if a == 1 } + EnforcedStyle: skip_modifier_ifs + # `MinBodyLength` defines the number of lines of the a body of an if / unless + # needs to have to trigger this cop + MinBodyLength: 3 + SupportedStyles: + - skip_modifier_ifs + - always + +Style/NonNilCheck: + # With `IncludeSemanticChanges` set to `true`, this cop reports offenses for + # `!x.nil?` and autocorrects that and `x != nil` to solely `x`, which is + # **usually** OK, but might change behavior. + # + # With `IncludeSemanticChanges` set to `false`, this cop does not report + # offenses for `!x.nil?` and does no changes that might change behavior. + IncludeSemanticChanges: false + +Style/NumericPredicate: + EnforcedStyle: predicate + SupportedStyles: + - predicate + - comparison + +Style/MethodDefParentheses: + EnforcedStyle: require_parentheses + SupportedStyles: + - require_parentheses + - require_no_parentheses + - require_no_parentheses_except_multiline + +Naming/MethodName: + EnforcedStyle: snake_case + SupportedStyles: + - snake_case + - camelCase + +Style/ModuleFunction: + EnforcedStyle: module_function + SupportedStyles: + - module_function + - extend_self + +Layout/MultilineArrayBraceLayout: + EnforcedStyle: symmetrical + SupportedStyles: + # symmetrical: closing brace is positioned in same way as opening brace + # new_line: closing brace is always on a new line + # same_line: closing brace is always on the same line as last element + - symmetrical + - new_line + - same_line + +Layout/MultilineAssignmentLayout: + # The types of assignments which are subject to this rule. + SupportedTypes: + - block + - case + - class + - if + - kwbegin + - module + EnforcedStyle: new_line + SupportedStyles: + # Ensures that the assignment operator and the rhs are on the same line for + # the set of supported types. + - same_line + # Ensures that the assignment operator and the rhs are on separate lines + # for the set of supported types. + - new_line + +Layout/MultilineHashBraceLayout: + EnforcedStyle: symmetrical + SupportedStyles: + # symmetrical: closing brace is positioned in same way as opening brace + # new_line: closing brace is always on a new line + # same_line: closing brace is always on same line as last element + - symmetrical + - new_line + - same_line + +Layout/MultilineMethodCallBraceLayout: + EnforcedStyle: symmetrical + SupportedStyles: + # symmetrical: closing brace is positioned in same way as opening brace + # new_line: closing brace is always on a new line + # same_line: closing brace is always on the same line as last argument + - symmetrical + - new_line + - same_line + +Layout/MultilineMethodCallIndentation: + EnforcedStyle: aligned + SupportedStyles: + - aligned + - indented + - indented_relative_to_receiver + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + IndentationWidth: ~ + +Layout/MultilineMethodDefinitionBraceLayout: + EnforcedStyle: symmetrical + SupportedStyles: + # symmetrical: closing brace is positioned in same way as opening brace + # new_line: closing brace is always on a new line + # same_line: closing brace is always on the same line as last parameter + - symmetrical + - new_line + - same_line + +Layout/MultilineOperationIndentation: + EnforcedStyle: aligned + SupportedStyles: + - aligned + - indented + # By default, the indentation width from Style/IndentationWidth is used + # But it can be overridden by setting this parameter + IndentationWidth: ~ + +Style/NumericLiterals: + MinDigits: 5 + +Style/NumericLiteralPrefix: + EnforcedOctalStyle: zero_with_o + SupportedOctalStyles: + - zero_with_o + - zero_only + +Style/OptionHash: + # A list of parameter names that will be flagged by this cop. + SuspiciousParamNames: + - options + - opts + - args + - params + - parameters + +# Allow safe assignment in conditions. +Style/ParenthesesAroundCondition: + AllowSafeAssignment: true + +Style/PercentLiteralDelimiters: + PreferredDelimiters: + "%": () + "%i": () + "%q": () + "%Q": () + "%r": "{}" + "%s": () + "%w": () + "%W": () + "%x": () + +Style/PercentQLiterals: + EnforcedStyle: lower_case_q + SupportedStyles: + - lower_case_q # Use %q when possible, %Q when necessary + - upper_case_q # Always use %Q + +Style/SlicingWithRange: + Enabled: false + +Naming/PredicateName: + # Predicate name prefixes. + NamePrefix: + - is_ + - has_ + - have_ + # Predicate name prefixes that should be removed. + ForbiddenPrefixes: + - is_ + - have_ + # Predicate names which, despite having a blacklisted prefix, or no ?, + # should still be accepted + AllowedMethods: + - is_a? + # Exclude Rspec specs because there is a strong convetion to write spec + # helpers in the form of `have_something` or `be_something`. + Exclude: + - "**/spec/**/*" + - "**/test/**/*" + +Style/PreferredHashMethods: + Enabled: true + EnforcedStyle: verbose + +Style/DateTime: + Enabled: true + +Style/Documentation: + Enabled: false + +Style/RaiseArgs: + EnforcedStyle: exploded + SupportedStyles: + - compact # raise Exception.new(msg) + - exploded # raise Exception, msg + +Style/RedundantReturn: + # When true allows code like `return x, y`. + AllowMultipleReturnValues: false + +# Use / or %r around regular expressions. +Style/RegexpLiteral: + EnforcedStyle: slashes + # slashes: Always use slashes. + # percent_r: Always use %r. + # mixed: Use slashes on single-line regexes, and %r on multi-line regexes. + SupportedStyles: + - slashes + - percent_r + - mixed + # If false, the cop will always recommend using %r if one or more slashes + # are found in the regexp string. + AllowInnerSlashes: false + +Style/SafeNavigation: + Enabled: false + +Style/Semicolon: + # Allow ; to separate several expressions on the same line. + AllowAsExpressionSeparator: false + +Style/SignalException: + EnforcedStyle: only_raise + SupportedStyles: + - only_raise + - only_fail + - semantic + +Style/SingleLineBlockParams: + Methods: + - reduce: + - a + - e + - inject: + - a + - e + +Style/SingleLineMethods: + AllowIfMethodIsEmpty: true + +Layout/SpaceBeforeFirstArg: + # When true, allows most uses of extra spacing if the intent is to align + # things with the previous or next line, not counting empty lines or comment + # lines. + AllowForAlignment: true + +Style/SpecialGlobalVars: + EnforcedStyle: use_english_names + SupportedStyles: + - use_perl_names + - use_english_names + +Style/StabbyLambdaParentheses: + EnforcedStyle: require_parentheses + SupportedStyles: + - require_parentheses + - require_no_parentheses + +Style/StringLiterals: + EnforcedStyle: double_quotes + SupportedStyles: + - single_quotes + - double_quotes + # If true, strings which span multiple lines using \ for continuation must + # use the same type of quotes on each line. + ConsistentQuotesInMultiline: false + +Style/StringLiteralsInInterpolation: + EnforcedStyle: double_quotes + SupportedStyles: + - single_quotes + - double_quotes + +Style/StringMethods: + # Mapping from undesired method to desired_method + # e.g. to use `to_sym` over `intern`: + # + # StringMethods: + # PreferredMethods: + # intern: to_sym + PreferredMethods: + intern: to_sym + +Layout/SpaceAroundBlockParameters: + EnforcedStyleInsidePipes: no_space + +Layout/SpaceAroundEqualsInParameterDefault: + EnforcedStyle: space + SupportedStyles: + - space + - no_space + +Layout/SpaceAroundOperators: + # When true, allows most uses of extra spacing if the intent is to align + # with an operator on the previous or next line, not counting empty lines + # or comment lines. + AllowForAlignment: true + +Layout/SpaceBeforeBlockBraces: + EnforcedStyle: space + SupportedStyles: + - space + - no_space + +Layout/SpaceInsideBlockBraces: + EnforcedStyle: space + SupportedStyles: + - space + - no_space + # Valid values are: space, no_space + EnforcedStyleForEmptyBraces: no_space + # Space between { and |. Overrides EnforcedStyle if there is a conflict. + SpaceBeforeBlockParameters: true + +Layout/SpaceInsideHashLiteralBraces: + EnforcedStyle: space + EnforcedStyleForEmptyBraces: no_space + SupportedStyles: + - space + - no_space + # "compact" normally requires a space inside hash braces, with the exception + # that successive left braces or right braces are collapsed together + - compact + +Layout/SpaceInsideStringInterpolation: + EnforcedStyle: no_space + SupportedStyles: + - space + - no_space + +Style/AccessModifierDeclarations: + Enabled: false + +Style/SymbolArray: + EnforcedStyle: brackets + SupportedStyles: + - percent + - brackets + +Style/SymbolProc: + # A list of method names to be ignored by the check. + # The names should be fairly unique, otherwise you'll end up ignoring lots of code. + IgnoredMethods: + - respond_to + - define_method + +Style/TernaryParentheses: + EnforcedStyle: require_no_parentheses + SupportedStyles: + - require_parentheses + - require_no_parentheses + AllowSafeAssignment: true + +Layout/TrailingEmptyLines: + EnforcedStyle: final_newline + SupportedStyles: + - final_newline + - final_blank_line + +Style/TrailingCommaInArguments: + # If `comma`, the cop requires a comma after the last argument, but only for + # parenthesized method calls where each argument is on its own line. + # If `consistent_comma`, the cop requires a comma after the last argument, + # for all parenthesized method calls with arguments. + EnforcedStyleForMultiline: no_comma + +Style/TrailingCommaInArrayLiteral: + # If `comma`, the cop requires a comma after the last item in an array or + # hash, but only when each item is on its own line. + # If `consistent_comma`, the cop requires a comma after the last item of all + # non-empty array and hash literals. + EnforcedStyleForMultiline: no_comma + +Style/TrailingCommaInHashLiteral: + # If `comma`, the cop requires a comma after the last item in an array or + # hash, but only when each item is on its own line. + # If `consistent_comma`, the cop requires a comma after the last item of all + # non-empty array and hash literals. + EnforcedStyleForMultiline: no_comma + +# TrivialAccessors requires exact name matches and doesn't allow +# predicated methods by default. +Style/TrivialAccessors: + # When set to false the cop will suggest the use of accessor methods + # in situations like: + # + # def name + # @other_name + # end + # + # This way you can uncover "hidden" attributes in your code. + ExactNameMatch: true + AllowPredicates: true + # Allows trivial writers that don't end in an equal sign. e.g. + # + # def on_exception(action) + # @on_exception=action + # end + # on_exception :restart + # + # Commonly used in DSLs + AllowDSLWriters: false + IgnoreClassMethods: false + AllowedMethods: + - to_ary + - to_a + - to_c + - to_enum + - to_h + - to_hash + - to_i + - to_int + - to_io + - to_open + - to_path + - to_proc + - to_r + - to_regexp + - to_str + - to_s + - to_sym + +Naming/VariableName: + EnforcedStyle: snake_case + SupportedStyles: + - snake_case + - camelCase + +Naming/VariableNumber: + EnforcedStyle: normalcase + SupportedStyles: + - snake_case + - normalcase + - non_integer + +# WordArray enforces how array literals of word-like strings should be expressed. +Style/WordArray: + EnforcedStyle: percent + SupportedStyles: + # percent style: %w(word1 word2) + - percent + # bracket style: ["word1", "word2"] + - brackets + # The MinSize option causes the WordArray rule to be ignored for arrays + # smaller than a certain size. The rule is only applied to arrays + # whose element count is greater than or equal to MinSize. + MinSize: 2 + # The regular expression WordRegex decides what is considered a word. + WordRegex: !ruby/regexp '/\A[\p{Word}\n\t]+\z/' + +##################### Metrics ################################## + +Metrics/AbcSize: + # The ABC size is a calculated magnitude, so this number can be an Integer or + # a Float. + Max: 15 + Enabled: false + +Metrics/BlockNesting: + Max: 3 + +Metrics/ClassLength: + CountComments: false # count full line comments? + Max: 100 + Enabled: false + +Metrics/ModuleLength: + CountComments: false # count full line comments? + Max: 100 + Enabled: false + +# Avoid complex methods. +Metrics/CyclomaticComplexity: + Max: 9 + Exclude: + - "bin/bundle" + - "decidim-admin/app/queries/decidim/admin/newsletter_recipients.rb" + - "**/*/dummy_authorization_handler.rb" + - "**/*/permissions.rb" + +Metrics/MethodLength: + CountComments: false # count full line comments? + Max: 15 + Enabled: false + +Metrics/ParameterLists: + Max: 5 + CountKeywordArgs: true + Exclude: + - "decidim-core/lib/decidim/filter_form_builder.rb" + +Metrics/PerceivedComplexity: + Max: 10 + Exclude: + - "decidim-admin/app/queries/decidim/admin/newsletter_recipients.rb" + - "**/*/dummy_authorization_handler.rb" + - "**/*/permissions.rb" + +##################### Lint ################################## + +Lint/AmbiguousBlockAssociation: + Enabled: true + Exclude: + - "**/abilities/**/*" + +# Allow safe assignment in conditions. +Lint/AssignmentInCondition: + AllowSafeAssignment: true + +Lint/ConstantDefinitionInBlock: + Enabled: false + +# Call super to initialize state of the parent class. +Lint/MissingSuper: + Enabled: false + +# checks whether the end keywords are aligned properly for `do` `end` blocks. +Layout/BlockAlignment: + # The value `start_of_block` means that the `end` should be aligned with line + # where the `do` keyword appears. + # The value `start_of_line` means it should be aligned with the whole + # expression's starting line. + # The value `either` means both are allowed. + EnforcedStyleAlignWith: either + +# Align ends correctly. +Layout/EndAlignment: + # The value `keyword` means that `end` should be aligned with the matching + # keyword (if, while, etc.). + # The value `variable` means that in assignments, `end` should be aligned + # with the start of the variable on the left hand side of `=`. In all other + # situations, `end` should still be aligned with the keyword. + # The value `start_of_line` means that `end` should be aligned with the start + # of the line which the matching keyword appears on. + EnforcedStyleAlignWith: keyword + AutoCorrect: false + +Layout/DefEndAlignment: + # The value `def` means that `end` should be aligned with the def keyword. + # The value `start_of_line` means that `end` should be aligned with method + # calls like `private`, `public`, etc, if present in front of the `def` + # keyword on the same line. + EnforcedStyleAlignWith: start_of_line + AutoCorrect: false + +Lint/InheritException: + # The default base class in favour of `Exception`. + EnforcedStyle: runtime_error + SupportedStyles: + - runtime_error + - standard_error + +Layout/LineLength: + Max: 180 + # To make it possible to copy or click on URIs in the code, we allow lines + # containing a URI to be longer than Max. + AllowHeredoc: true + AllowURI: true + URISchemes: + - http + - https + Exclude: + - "**/spec/**/*" + +# Checks for unused block arguments +Lint/UnusedBlockArgument: + IgnoreEmptyBlocks: true + AllowUnusedKeywordArguments: false + +# Checks for unused method arguments. +Lint/UnusedMethodArgument: + AllowUnusedKeywordArguments: false + IgnoreEmptyMethods: true + +##################### Performance ############################ + +Metrics/BlockLength: + Enabled: false + +RSpec/BeforeAfterAll: + Enabled: true + +RSpec/ContextWording: + Enabled: true + Prefixes: + - when + - with + - without + - and + +RSpec/DescribeClass: + Exclude: + - spec/gemfiles_spec.rb + - spec/js_bundles_spec.rb + - spec/i18n_spec.rb + - "**/*/spec/**/*_badge_spec.rb" + - decidim-core/spec/lib/global_engines_spec.rb + - "**/tasks/**/*" + +RSpec/EmptyExampleGroup: + Exclude: + - decidim-core/spec/lib/participatory_space_manifest_spec.rb + +RSpec/ExampleLength: + Max: 49 + +RSpec/ExpectInHook: + Enabled: false + +RSpec/IteratedExpectation: + Enabled: true + +RSpec/LetSetup: + Enabled: false + +RSpec/MessageSpies: + Enabled: false + +RSpec/MultipleExpectations: + Enabled: false + +RSpec/MultipleMemoizedHelpers: + Max: 35 + +RSpec/NestedGroups: + Max: 7 + +RSpec/NamedSubject: + Enabled: false + +RSpec/RepeatedExampleGroupDescription: + Enabled: false + +RSpec/RepeatedExampleGroupBody: + Enabled: false +RSpec/VerifiedDoubles: + Enabled: false + +RSpec/LeakyConstantDeclaration: + Enabled: false + +RSpec/DescribedClass: + Enabled: false + +# This is the default configuration file. + +Faker/DeprecatedArguments: + Description: 'Checks that Faker arguments style is based on Faker 2.' + Enabled: true + VersionAdded: '0.1' + Reference: 'https://github.com/faker-ruby/faker/blob/master/CHANGELOG.md#v20-2019-31-07' + ArgumentKeywords: + # + # FakerClassName: + # method_name: + # - keyword_name_for_first_argument + # - keyword_name_for_second_argument + # - keyword_name_for_third_argument + # + Faker::Dune: + quote: + - character + saying: + - source + Faker::Books::Lovecraft: + fhtagn: + - number + sentence: + - word_count + - random_words_to_add + words: + - number + - spaces_allowed + sentences: + - number + paragraph: + - sentence_count + - random_sentences_to_add + paragraphs: + - number + paragraph_by_chars: + - characters + Faker::Address: + city: + - options + street_address: + - include_secondary + zip_code: + - state_abbreviation + country_by_code: + - code + country_name_to_code: + - name + Faker::Alphanumeric: + alpha: + - number + alphanumeric: + - number + Faker::App: + semantic_version: + - major + - minor + - patch + Faker::Avatar: + image: + - slug + - size + - format + - set + - bgset + Faker::Bank: + account_number: + - digits + iban: + - country_code + Faker::Boolean: + boolean: + - true_ratio + Faker::ChileRut: + rut: + - min_rut + - fixed + full_rut: + - min_rut + - fixed + Faker::Code: + isbn: + - base + ean: + - base + nric: + - min_age + - max_age + Faker::Commerce: + promotion_code: + - digits + department: + - max + - fixed_amount + price: + - range + - as_string + Faker::Company: + polish_register_of_national_economy: + - length + brazilian_company_number: + - formatted + Faker::CryptoCoin: + coin_name: + - coin + acronym: + - coin + url_logo: + - coin + Faker::Date: + between: + - from + - to + between_except: + - from + - to + - excepted + forward: + - days + backward: + - days + birthday: + - min_age + - max_age + Faker::Demographic: + height: + - unit + Faker::DrivingLicence: + british_driving_licence: + - last_name + - initials + - gender + - date_of_birth + Faker::File: + dir: + - segment_count + - root + - directory_separator + file_name: + - dir + - name + - ext + - directory_separator + Faker::Fillmurray: + image: + - grayscale + - width + - height + Faker::Finance: + vat_number: + - country + Faker::Hipster: + words: + - number + - supplemental + - spaces_allowed + sentence: + - word_count + - supplemental + - random_words_to_add + sentences: + - number + - supplemental + paragraph: + - sentence_count + - supplemental + - random_sentences_to_add + paragraphs: + - number + - supplemental + paragraph_by_chars: + - characters + - supplemental + Faker::IDNumber: + brazilian_citizen_number: + - formatted + brazilian_id: + - formatted + Faker::Internet: + email: + - name + - separators + free_email: + - name + safe_email: + - name + username: + - specifier + - separators + password: + - min_length + - max_length + - mix_case + - special_characters + domain_name: + - subdomain + fix_umlauts: + - string + mac_address: + - prefix + url: + - host + - path + - scheme + slug: + - words + - glue + user_agent: + - vendor + Faker::Invoice: + amount_between: + - from + - to + creditor_reference: + - ref + reference: + - ref + Faker::Json: + shallow_json: + - width + - options + add_depth_to_json: + - json + - width + - options + Faker::Lorem: + words: + - number + - supplemental + characters: + - number + sentence: + - word_count + - supplemental + - random_words_to_add + sentences: + - number + - supplemental + paragraph: + - sentence_count + - supplemental + - random_sentences_to_add + paragraphs: + - number + - supplemental + paragraph_by_chars: + - number + - supplemental + question: + - word_count + - supplemental + - random_words_to_add + questions: + - number + - supplemental + Faker::LoremFlickr: + image: + - size + - search_terms + - match_all + grayscale_image: + - size + - search_terms + - match_all + pixelated_image: + - size + - search_terms + - match_all + colorized_image: + - size + - color + - search_terms + - match_all + Faker::LoremPixel: + image: + - size + - is_gray + - category + - number + - text + - secure + Faker::Markdown: + sandwich: + - sentences + - repeat + Faker::Measurement: + height: + - amount + length: + - amount + volume: + - amount + weight: + - amount + metric_height: + - amount + metric_length: + - amount + metric_volume: + - amount + metric_weight: + - amount + Faker::Name: + initials: + - number + Faker::NationalHealthService: + check_digit: + - number + Faker::Number: + number: + - digits + leading_zero_number: + - digits + decimal_part: + - digits + decimal: + - l_digits + - r_digits + hexadecimal: + - digits + normal: + - mean + - standard_deviation + between: + - from + - to + within: + - range + positive: + - from + - to + negative: + - from + - to + Faker::Omniauth: + google: + - name + - email + - uid + facebook: + - name + - email + - username + - uid + twitter: + - name + - nickname + - uid + linkedin: + - name + - email + - uid + github: + - name + - email + - uid + Faker::PhoneNumber: + subscriber_number: + - length + Faker::Placeholdit: + image: + - size + - format + - background_color + - text_color + - text + Faker::Relationship: + familial: + - connection + Faker::Source: + hello_world: + - lang + print: + - str + - lang + print_1_to_10: + - lang + Faker::String: + random: + - length + Faker::Stripe: + valid_card: + - card_type + valid_token: + - card_type + invalid_card: + - card_error + ccv: + - card_type + Faker::Time: + between: + - from + - to + - format + between_dates: + - from + - to + - period + - format + forward: + - days + - period + - format + backward: + - days + - period + - format + Faker::Twitter: + user: + - include_status + - include_email + status: + - include_user + - include_photo + status_entities: + - include_photo + Faker::Types: + rb_string: + - words + rb_integer: + - from + - to + rb_hash: + - number + - type + complex_rb_hash: + - number + rb_array: + - len + Faker::Vehicle: + model: + - make_of_model + mileage: + - min + - max + license_plate: + - state_abbreviation + Faker::WorldCup: + group: + - group + roster: + - country + - type + Faker::Dota: + quote: + - hero + Faker::Movies::StarWars: + quote: + - character + Decidim::Faker::Localized: + words: + - number + - supplemental + characters: + - number + sentence: + - word_count + - supplemental + - random_words_to_add + sentences: + - number + - supplemental + paragraph: + - sentence_count + - supplemental + - random_sentences_to_add + paragraphs: + - number + - supplemental + paragraph_by_chars: + - number + - supplemental + question: + - word_count + - supplemental + - random_words_to_add + questions: + - number + - supplemental + diff --git a/Appraisals b/Appraisals index 22434ec8e..9b0d7a2f5 100644 --- a/Appraisals +++ b/Appraisals @@ -1,30 +1,42 @@ -appraise "decidim-0.22" do - gem "decidim", "0.22" - gem "decidim-admin", "0.22" - gem "decidim-core", "0.22" - gem "puma", ">= 4.3" - group :development, :test do - gem "decidim-dev", "0.22" - end -end - appraise "decidim-0.23" do gem "decidim", "0.23" gem "decidim-admin", "0.23" gem "decidim-core", "0.23" gem "puma", ">= 4.3.5" + gem "faker", "~> 1.9" + group :development, :test do gem "decidim-dev", "0.23" end + + group :development do + remove_gem "rubocop-faker" + end end -appraise "decidim-0.23.2" do - gem "decidim", "0.23.2" - gem "decidim-admin", "0.23.2" - gem "decidim-core", "0.23.2" +appraise "decidim-0.23.4" do + gem "decidim", "0.23.4" + gem "decidim-admin", "0.23.4" + gem "decidim-core", "0.23.4" gem "puma", ">= 4.3.5" + gem "faker", "~> 1.9" + group :development, :test do + gem "decidim-dev", "0.23.4" + end + + group :development do + remove_gem "rubocop-faker" + end +end + +appraise "decidim-0.24" do + gem "decidim", "0.24" + gem "decidim-admin", "0.24" + gem "decidim-core", "0.24" + gem "puma", ">= 5.0.0" + group :development, :test do - gem "decidim-dev", "0.23.2" + gem "decidim-dev", "0.24" end end diff --git a/CHANGELOG.md b/CHANGELOG.md index 1585ede19..1fd9eb859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +v0.7.0 +------ + +Compatibility: + - Decidim v0.24 + - Decidim v0.23.x + - Decidim v0.23 + v0.6.7 ------ @@ -18,8 +26,8 @@ v0.6.6 ------ Compatibility: - - Decidim 0.23.3 - - Decidim 0.23.2 + - Decidim v0.23.3 + - Decidim v0.23.2 - Decidim v0.23.1 - Decidim v0.23 - Decidim v0.22 @@ -32,8 +40,8 @@ v0.6.5 ------ Compatibility: - - Decidim 0.23.3 - - Decidim 0.23.2 + - Decidim v0.23.3 + - Decidim v0.23.2 - Decidim v0.23.1 - Decidim v0.23 - Decidim v0.22 @@ -45,8 +53,8 @@ v0.6.4 ------ Compatibility: - - Decidim 0.23.3 - - Decidim 0.23.2 + - Decidim v0.23.3 + - Decidim v0.23.2 - Decidim v0.23.1 - Decidim v0.23 - Decidim v0.22 @@ -59,8 +67,8 @@ v0.6.3 ------ Compatibility: - - Decidim 0.23.3 - - Decidim 0.23.2 + - Decidim v0.23.3 + - Decidim v0.23.2 - Decidim v0.23.1 - Decidim v0.23 - Decidim v0.22 diff --git a/Gemfile b/Gemfile index 1eeb30811..4fa4c5eae 100644 --- a/Gemfile +++ b/Gemfile @@ -5,15 +5,18 @@ source "https://rubygems.org" ruby RUBY_VERSION # We need to keep version here for Appraisal compatibility -DECIDIM_VERSION = "0.23.4" +DECIDIM_VERSION = "0.24" gem "decidim", DECIDIM_VERSION gem "decidim-decidim_awesome", path: "." gem "bootsnap", "~> 1.4" -gem "puma", ">= 4.3.5" + +gem "puma", ">= 5.0.0" gem "uglifier", "~> 4.1" +gem "faker", "~> 2.14" + group :development, :test do gem "byebug", "~> 11.0", platform: :mri @@ -21,9 +24,9 @@ group :development, :test do end group :development do - gem "faker", "~> 1.9" gem "letter_opener_web", "~> 1.3" gem "listen", "~> 3.1" + gem "rubocop-faker" gem "spring", "~> 2.0" gem "spring-watcher-listen", "~> 2.0" gem "web-console", "~> 3.5" diff --git a/Gemfile.lock b/Gemfile.lock index c198e6104..54c9f08d7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,11 @@ PATH remote: . specs: - decidim-decidim_awesome (0.6.7) - decidim-admin (>= 0.22.0, < 0.24) - decidim-core (>= 0.22.0, < 0.24) + decidim-decidim_awesome (0.7.0) + decidim-admin (>= 0.23.0, < 0.25) + decidim-core (>= 0.23.0, < 0.25) redcarpet (~> 3.4) - sassc (~> 2.3.0) + sassc (~> 2.3) GEM remote: https://rubygems.org/ @@ -99,10 +99,13 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - carrierwave (1.3.2) - activemodel (>= 4.0.0) - activesupport (>= 4.0.0) - mime-types (>= 1.16) + carrierwave (2.2.0) + activemodel (>= 5.0.0) + activesupport (>= 5.0.0) + addressable (~> 2.6) + image_processing (~> 1.1) + mimemagic (>= 0.3.0) + mini_mime (>= 0.1.3) ssrf_filter (~> 1.0) cells (4.1.7) declarative-builder (< 0.2.0) @@ -130,6 +133,7 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.1.8) + cookiejar (0.3.3) crack (0.4.5) rexml crass (1.0.6) @@ -141,76 +145,76 @@ GEM db-query-matchers (0.9.0) activesupport (>= 4.0, <= 6.0) rspec (~> 3.0) - decidim (0.23.4) - decidim-accountability (= 0.23.4) - decidim-admin (= 0.23.4) - decidim-api (= 0.23.4) - decidim-assemblies (= 0.23.4) - decidim-blogs (= 0.23.4) - decidim-budgets (= 0.23.4) - decidim-comments (= 0.23.4) - decidim-core (= 0.23.4) - decidim-debates (= 0.23.4) - decidim-forms (= 0.23.4) - decidim-generators (= 0.23.4) - decidim-meetings (= 0.23.4) - decidim-pages (= 0.23.4) - decidim-participatory_processes (= 0.23.4) - decidim-proposals (= 0.23.4) - decidim-sortitions (= 0.23.4) - decidim-surveys (= 0.23.4) - decidim-system (= 0.23.4) - decidim-verifications (= 0.23.4) - decidim-accountability (0.23.4) - decidim-comments (= 0.23.4) - decidim-core (= 0.23.4) + decidim (0.24.0) + decidim-accountability (= 0.24.0) + decidim-admin (= 0.24.0) + decidim-api (= 0.24.0) + decidim-assemblies (= 0.24.0) + decidim-blogs (= 0.24.0) + decidim-budgets (= 0.24.0) + decidim-comments (= 0.24.0) + decidim-core (= 0.24.0) + decidim-debates (= 0.24.0) + decidim-forms (= 0.24.0) + decidim-generators (= 0.24.0) + decidim-meetings (= 0.24.0) + decidim-pages (= 0.24.0) + decidim-participatory_processes (= 0.24.0) + decidim-proposals (= 0.24.0) + decidim-sortitions (= 0.24.0) + decidim-surveys (= 0.24.0) + decidim-system (= 0.24.0) + decidim-templates (= 0.24.0) + decidim-verifications (= 0.24.0) + decidim-accountability (0.24.0) + decidim-comments (= 0.24.0) + decidim-core (= 0.24.0) kaminari (~> 1.2, >= 1.2.1) searchlight (~> 4.1) - decidim-admin (0.23.4) + decidim-admin (0.24.0) active_link_to (~> 1.0) - decidim-core (= 0.23.4) + decidim-core (= 0.24.0) devise (~> 4.7) devise-i18n (~> 1.2) devise_invitable (~> 1.7) - jquery-rails (~> 4.3) - sassc (~> 2.3.0) + jquery-rails (~> 4.4) + sassc (~> 2.4.0) sassc-rails (~> 2.1.2) - decidim-api (0.23.4) + decidim-api (0.24.0) graphiql-rails (~> 1.4, < 1.5) - graphql (~> 1.9) + graphql (~> 1.12, >= 1.12.3) rack-cors (~> 1.0) - redcarpet (~> 3.4) + redcarpet (~> 3.5, >= 3.5.1) sprockets-es6 (~> 0.9.2) - decidim-assemblies (0.23.4) - decidim-core (= 0.23.4) - decidim-blogs (0.23.4) - decidim-admin (= 0.23.4) - decidim-comments (= 0.23.4) - decidim-core (= 0.23.4) - httparty (~> 0.17) + decidim-assemblies (0.24.0) + decidim-core (= 0.24.0) + decidim-blogs (0.24.0) + decidim-admin (= 0.24.0) + decidim-comments (= 0.24.0) + decidim-core (= 0.24.0) jquery-tmpl-rails (~> 1.1) kaminari (~> 1.2, >= 1.2.1) - decidim-budgets (0.23.4) - decidim-comments (= 0.23.4) - decidim-core (= 0.23.4) + decidim-budgets (0.24.0) + decidim-comments (= 0.24.0) + decidim-core (= 0.24.0) kaminari (~> 1.2, >= 1.2.1) searchlight (~> 4.1) - decidim-comments (0.23.4) - decidim-core (= 0.23.4) - jquery-rails (~> 4.3) - redcarpet (~> 3.4) - decidim-core (0.23.4) + decidim-comments (0.24.0) + decidim-core (= 0.24.0) + jquery-rails (~> 4.4) + redcarpet (~> 3.5, >= 3.5.1) + decidim-core (0.24.0) active_link_to (~> 1.0) - anchored (>= 1.1.0) + anchored (~> 1.1) autoprefixer-rails (~> 8.0) batch-loader (~> 1.2) browser (~> 2.7) - carrierwave (~> 1.3) + carrierwave (~> 2.2.0) cells-erb (~> 0.1.0) cells-rails (~> 0.0.9) charlock_holmes (~> 0.7) date_validator (~> 0.9.0) - decidim-api (= 0.23.4) + decidim-api (= 0.24.0) devise (~> 4.7) devise-i18n (~> 1.2) diffy (~> 3.3) @@ -218,12 +222,13 @@ GEM doorkeeper-i18n (~> 4.0) etherpad-lite (~> 0.3) file_validators (~> 2.1) + fog-local (~> 0.6) foundation-rails (~> 6.6, < 6.7) foundation_rails_helper (~> 3.0) - geocoder (>= 1.5) + geocoder (~> 1.5) hashdiff (>= 0.4.0, < 2.0.0) invisible_captcha (~> 0.12) - jquery-rails (~> 4.3) + jquery-rails (~> 4.4) kaminari (~> 1.2, >= 1.2.1) loofah (~> 2.3.1) mini_magick (~> 4.9) @@ -238,15 +243,15 @@ GEM pg (~> 1.1.4, < 2) pg_search (~> 2.2) premailer-rails (~> 1.10) - rack (>= 2.2.3) + rack (~> 2.2, >= 2.2.3) rack-attack (~> 6.0) - rails (>= 5.2.4.4, < 6.0.x) + rails (~> 5.2.4.5) rails-i18n (~> 5.0) rectify (~> 0.13.0) redis (~> 4.1) request_store (~> 1.5.0) rubyzip (~> 2.0) - sassc (~> 2.3.0) + sassc (~> 2.4.0) sassc-rails (~> 2.1.2) seven_zip_ruby (~> 1.3) social-share-button (~> 1.2, >= 1.2.1) @@ -257,86 +262,91 @@ GEM uglifier (~> 4.1) valid_email2 (~> 2.1) wisper (~> 2.0) - decidim-debates (0.23.4) - decidim-comments (= 0.23.4) - decidim-core (= 0.23.4) + decidim-debates (0.24.0) + decidim-comments (= 0.24.0) + decidim-core (= 0.24.0) kaminari (~> 1.2, >= 1.2.1) searchlight (~> 4.1) - decidim-dev (0.23.4) + decidim-dev (0.24.0) byebug (~> 11.0) capybara (~> 3.24) db-query-matchers (~> 0.9.0) - decidim (= 0.23.4) + decidim (= 0.24.0) erb_lint (~> 0.0.28) factory_bot_rails (~> 4.8) i18n-tasks (~> 0.9.18) mdl (~> 0.5) - nokogiri (>= 1.10.8) - puma (>= 4.3) + nokogiri (~> 1.11, >= 1.11.1) + puffing-billy (~> 2.4.0) + puma (~> 5.0) rails-controller-testing (~> 1.0) rspec-cells (~> 0.3.4) rspec-html-matchers (~> 0.9.1) rspec-rails (~> 3.7) rspec-retry (~> 0.6.2) rspec_junit_formatter (~> 0.3.0) - rubocop (~> 0.71.0) + rubocop (~> 0.92.0) rubocop-rails (~> 2.0) rubocop-rspec (~> 1.21) selenium-webdriver (~> 3.142) simplecov (~> 0.19.0) simplecov-cobertura (~> 1.3.1) system_test_html_screenshots (~> 0.1.1) + vcr (~> 6.0) webmock (~> 3.6) wisper-rspec (~> 1.0) - decidim-forms (0.23.4) - decidim-core (= 0.23.4) + decidim-forms (0.24.0) + decidim-core (= 0.24.0) wicked_pdf (~> 1.4) wkhtmltopdf-binary (~> 0.12) - decidim-generators (0.23.4) - decidim-core (= 0.23.4) - decidim-meetings (0.23.4) + decidim-generators (0.24.0) + decidim-core (= 0.24.0) + decidim-meetings (0.24.0) cells-erb (~> 0.1.0) cells-rails (~> 0.0.9) - decidim-core (= 0.23.4) - decidim-forms (= 0.23.4) - httparty (~> 0.17) + decidim-core (= 0.24.0) + decidim-forms (= 0.24.0) icalendar (~> 2.5) jquery-tmpl-rails (~> 1.1) kaminari (~> 1.2, >= 1.2.1) searchlight (~> 4.1) - decidim-pages (0.23.4) - decidim-core (= 0.23.4) - decidim-participatory_processes (0.23.4) - decidim-core (= 0.23.4) - decidim-proposals (0.23.4) + decidim-pages (0.24.0) + decidim-core (= 0.24.0) + decidim-participatory_processes (0.24.0) + decidim-core (= 0.24.0) + decidim-proposals (0.24.0) acts_as_list (~> 0.9) cells-erb (~> 0.1.0) cells-rails (~> 0.0.9) - decidim-comments (= 0.23.4) - decidim-core (= 0.23.4) - doc2text (~> 0.4.2) + decidim-comments (= 0.24.0) + decidim-core (= 0.24.0) + doc2text (~> 0.4.3) kaminari (~> 1.2, >= 1.2.1) ransack (~> 2.1.1) - redcarpet (~> 3.4) - decidim-sortitions (0.23.4) - decidim-admin (= 0.23.4) - decidim-comments (= 0.23.4) - decidim-core (= 0.23.4) - decidim-proposals (= 0.23.4) - decidim-surveys (0.23.4) - decidim-core (= 0.23.4) - decidim-forms (= 0.23.4) - decidim-system (0.23.4) + redcarpet (~> 3.5, >= 3.5.1) + decidim-sortitions (0.24.0) + decidim-admin (= 0.24.0) + decidim-comments (= 0.24.0) + decidim-core (= 0.24.0) + decidim-proposals (= 0.24.0) + decidim-surveys (0.24.0) + decidim-core (= 0.24.0) + decidim-forms (= 0.24.0) + decidim-templates (= 0.24.0) + decidim-system (0.24.0) active_link_to (~> 1.0) - decidim-core (= 0.23.4) + decidim-core (= 0.24.0) devise (~> 4.7) devise-i18n (~> 1.2) devise_invitable (~> 1.7) - jquery-rails (~> 4.3) - sassc (~> 2.3.0) + jquery-rails (~> 4.4) + sassc (~> 2.4.0) sassc-rails (~> 2.1.2) - decidim-verifications (0.23.4) - decidim-core (= 0.23.4) + decidim-templates (0.24.0) + decidim-core (= 0.24.0) + decidim-forms (= 0.24.0) + decidim-verifications (0.24.0) + decidim-core (= 0.24.0) declarative-builder (0.1.0) declarative-option (< 0.2.0) declarative-option (0.1.0) @@ -364,6 +374,16 @@ GEM doorkeeper (5.5.0) railties (>= 5) doorkeeper-i18n (4.0.1) + em-http-request (1.1.7) + addressable (>= 2.3.4) + cookiejar (!= 0.3.1) + em-socksify (>= 0.3) + eventmachine (>= 1.0.3) + http_parser.rb (>= 0.6.0) + em-socksify (0.3.2) + eventmachine (>= 1.0.0.beta.4) + em-synchrony (1.0.6) + eventmachine (>= 1.0.0.beta.1) equalizer (0.0.11) erb_lint (0.0.37) activesupport @@ -378,14 +398,17 @@ GEM erubi (1.10.0) etherpad-lite (0.3.0) rest-client (>= 1.6) + eventmachine (1.2.7) + eventmachine_httpserver (0.2.1) + excon (0.79.0) execjs (2.7.0) factory_bot (4.11.1) activesupport (>= 3.0.0) factory_bot_rails (4.11.1) factory_bot (~> 4.11.1) railties (>= 3.0.0) - faker (1.9.6) - i18n (>= 0.7) + faker (2.17.0) + i18n (>= 1.6, < 2) faraday (1.3.0) faraday-net_http (~> 1.0) multipart-post (>= 1.2, < 3) @@ -395,6 +418,14 @@ GEM file_validators (2.3.0) activemodel (>= 3.2) mime-types (>= 1.0) + fog-core (2.2.3) + builder + excon (~> 0.71) + formatador (~> 0.2) + mime-types + fog-local (0.6.0) + fog-core (>= 1.27, < 3.0) + formatador (0.2.5) foundation-rails (6.6.2.0) railties (>= 3.1.0) sass (>= 3.3.0) @@ -420,10 +451,8 @@ GEM http-accept (1.7.0) http-cookie (1.0.3) domain_name (~> 0.5) - httparty (0.18.1) - mime-types (~> 3.0) - multi_xml (>= 0.5.2) - i18n (1.8.9) + http_parser.rb (0.6.0) + i18n (1.8.10) concurrent-ruby (~> 1.0) i18n-tasks (0.9.34) activesupport (>= 4.0.2) @@ -439,9 +468,11 @@ GEM ice_cube (~> 0.16) ice_cube (0.16.3) ice_nine (0.11.2) + image_processing (1.12.1) + mini_magick (>= 4.9.5, < 5) + ruby-vips (>= 2.0.17, < 3) invisible_captcha (0.13.0) rails (>= 3.2.0) - jaro_winkler (1.5.4) jquery-rails (4.4.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -473,7 +504,7 @@ GEM actionmailer (>= 3.2) letter_opener (~> 1.0) railties (>= 3.2) - listen (3.5.0) + listen (3.5.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) loofah (2.3.1) @@ -513,7 +544,7 @@ GEM netrc (0.11.0) nio4r (2.5.7) nobspw (0.6.2) - nokogiri (1.11.3) + nokogiri (1.11.2) mini_portile2 (~> 2.5.0) racc (~> 1.4) oauth (0.5.5) @@ -564,6 +595,14 @@ GEM actionmailer (>= 3) premailer (~> 1.7, >= 1.7.9) public_suffix (4.0.6) + puffing-billy (2.4.1) + addressable (~> 2.5) + em-http-request (~> 1.1, >= 1.1.0) + em-synchrony + eventmachine (~> 1.2) + eventmachine_httpserver + http_parser.rb (~> 0.6.0) + multi_json puma (5.2.2) nio4r (~> 2.0) racc (1.5.2) @@ -666,20 +705,31 @@ GEM rspec-support (3.9.4) rspec_junit_formatter (0.3.0) rspec-core (>= 2, < 4, != 2.12.0) - rubocop (0.71.0) - jaro_winkler (~> 1.5.1) + rubocop (0.92.0) parallel (~> 1.10) - parser (>= 2.6) + parser (>= 2.7.1.5) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.7) + rexml + rubocop-ast (>= 0.5.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) - rubocop-rails (2.0.1) + unicode-display_width (>= 1.4.0, < 2.0) + rubocop-ast (1.4.1) + parser (>= 2.7.1.5) + rubocop-faker (1.1.0) + faker (>= 2.12.0) + rubocop (>= 0.82.0) + rubocop-rails (2.9.1) + activesupport (>= 4.2.0) rack (>= 1.1) - rubocop (>= 0.70.0) - rubocop-rspec (1.41.0) - rubocop (>= 0.68.1) + rubocop (>= 0.90.0, < 2.0) + rubocop-rspec (1.44.1) + rubocop (~> 0.87) + rubocop-ast (>= 0.7.1) ruby-ole (1.2.12.2) ruby-progressbar (1.11.0) + ruby-vips (2.1.0) + ffi (~> 1.12) ruby2_keywords (0.0.4) rubyzip (2.3.0) sass (3.7.4) @@ -687,7 +737,7 @@ GEM sass-listen (4.0.0) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - sassc (2.3.0) + sassc (2.4.0) ffi (~> 1.9) sassc-rails (2.1.2) railties (>= 4.0.0) @@ -747,10 +797,11 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.7) - unicode-display_width (1.6.1) + unicode-display_width (1.7.0) valid_email2 (2.3.1) activemodel (>= 3.2) mail (~> 2.5) + vcr (6.0.0) virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) @@ -763,7 +814,7 @@ GEM activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) - webmock (3.12.1) + webmock (3.12.2) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) @@ -786,13 +837,14 @@ DEPENDENCIES bootsnap (~> 1.4) byebug (~> 11.0) codecov - decidim (= 0.23.4) + decidim (= 0.24) decidim-decidim_awesome! - decidim-dev (= 0.23.4) - faker (~> 1.9) + decidim-dev (= 0.24) + faker (~> 2.14) letter_opener_web (~> 1.3) listen (~> 3.1) - puma (>= 4.3.5) + puma (>= 5.0.0) + rubocop-faker spring (~> 2.0) spring-watcher-listen (~> 2.0) uglifier (~> 4.1) diff --git a/README.md b/README.md index cf8ff1f9a..84f23aa29 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Decidim::DecidimAwesome -[![Build](https://github.com/Platoniq/decidim-module-decidim_awesome/workflows/Build/badge.svg)](https://github.com/Platoniq/decidim-module-decidim_awesome/actions) +[![[CI] Test 0.24](https://github.com/Platoniq/decidim-module-decidim_awesome/actions/workflows/test%20-24.yml/badge.svg)](https://github.com/Platoniq/decidim-module-decidim_awesome/actions/workflows/test%20-24.yml) +[![[CI] Test 0.23](https://github.com/Platoniq/decidim-module-decidim_awesome/actions/workflows/test%20-23.yml/badge.svg)](https://github.com/Platoniq/decidim-module-decidim_awesome/actions/workflows/test%20-23.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/2dada53525dd5a944089/maintainability)](https://codeclimate.com/github/Platoniq/decidim-module-decidim_awesome/maintainability) [![Test Coverage](https://codecov.io/gh/Platoniq/decidim-module-decidim_awesome/branch/master/graph/badge.svg?token=TFBMCLLZJG)](undefined) @@ -135,7 +136,7 @@ Some things in the road-map: Add this line to your application's Gemfile: ```ruby -gem "decidim-decidim_awesome", "~> 0.6.6" +gem "decidim-decidim_awesome", "~> 0.7.0" ``` And then execute: @@ -152,6 +153,7 @@ Depending on your Decidim version, choose the corresponding Awesome version to e |---|---| | 0.5.x | 0.21.x, 0.22.x | | 0.6.x | 0.22.x, 0.23.x | +| 0.7.x | 0.23.x, 0.24.x | ## Configuration diff --git a/app/assets/config/decidim_admin_decidim_awesome_manifest.js b/app/assets/config/decidim_admin_decidim_awesome_manifest.js index 771d9de08..53eb2a49e 100644 --- a/app/assets/config/decidim_admin_decidim_awesome_manifest.js +++ b/app/assets/config/decidim_admin_decidim_awesome_manifest.js @@ -1,2 +1,3 @@ // = link decidim/decidim_awesome/admin.js +// = link decidim/decidim_awesome/legacy_admin.js // = link decidim/decidim_awesome/admin/form_exit_warn.js diff --git a/app/assets/config/decidim_decidim_awesome_manifest.js b/app/assets/config/decidim_decidim_awesome_manifest.js index 99055125b..d668a43c7 100644 --- a/app/assets/config/decidim_decidim_awesome_manifest.js +++ b/app/assets/config/decidim_decidim_awesome_manifest.js @@ -1,3 +1,3 @@ +// = link decidim/decidim_awesome/legacy_application.js // = link decidim/decidim_awesome/application.js -// = link decidim/decidim_awesome/awesome_map/legacy_map.js // = link decidim/decidim_awesome/awesome_map/map.js diff --git a/app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_map.js.es6 b/app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_map.js.es6 deleted file mode 100644 index 23ee6cdd6..000000000 --- a/app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_map.js.es6 +++ /dev/null @@ -1,218 +0,0 @@ -// = require jsrender.min -// = require decidim/map -// = require leaflet.featuregroup.subgroup -// = require decidim/decidim_awesome/awesome_map/utilities -// = require decidim/decidim_awesome/awesome_map/categories -// = require decidim/decidim_awesome/awesome_map/legacy_proposals -// = require decidim/decidim_awesome/awesome_map/meetings -// = require_self - -((exports) => { - const { fetchProposals, fetchMeetings, getCategory, amendments } = exports.AwesomeMap; - - const collapsedMenu = $("#map").data("collapsed"); - const show = { - withdrawn: $("#map").data("show-withdrawn"), - accepted: $("#map").data("show-accepted"), - evaluating: $("#map").data("show-evaluating"), - notAnswered: $("#map").data("show-not-answered"), - rejected: $("#map").data("show-rejected") - }; - const components = $("#map").data("components"); - const popupMeetingTemplateId = "marker-meeting-popup"; - const popupProposalTemplateId = "legacy-marker-proposal-popup"; - - const cluster = L.markerClusterGroup(); - const layers = {}; - - const control = L.control.layers(null, null, { - position: 'topleft', - sortLayers: false, - collapsed: collapsedMenu, - // hideSingleBase: true - }); - const allMarkers = []; - - const drawMarker = (element, marker, component) => { - let tmpl = component.type === "proposals" ? popupProposalTemplateId : popupMeetingTemplateId, - node = document.createElement("div"); - - $($.templates(`#${tmpl}`).render(element)).appendTo(node); - - marker.bindPopup(node, { - maxwidth: 640, - minWidth: 500, - keepInView: true, - className: "map-info" - }).openPopup(); - - allMarkers.push({ - marker: marker, - component: component, - element: element - }); - - // Add to category layer - let cat = getCategory(element.category); - if(layers[cat.id]) { - marker.addTo(layers[cat.id].group); - // show category if hidden - const $label = $(`.awesome_map-category_${cat.id}`).closest("label"); - const $parent = $(`.awesome_map-category_${cat.parent}`).closest("label"); - $label.show(); - // update number of items - $label.attr("title", parseInt($label.attr("title") || 0) + 1); - // show parent if apply - $parent.show(); - $parent.attr("title", parseInt($parent.attr("title") || 0) + 1); - // update component stats - const $component = $(`#awesome_map-component-${component.id}`); - $component.attr("title", parseInt($component.attr("title") || 0) + 1); - } - - return marker; - }; - - const loadElements = (map) => { - // legends - control.addTo(map); - cluster.addTo(map); - - // Load markers - components.forEach((component) => { - if(component.type == "proposals") { - // add control layer for proposals - layers.proposals = { - label: `${component.name || window.DecidimAwesome.texts.proposals}`, - group: L.featureGroup.subGroup(cluster) - }; - control.addOverlay(layers.proposals.group, layers.proposals.label); - layers.proposals.group.addTo(map); - - // add control layer for amendments if any - if(component.amendments) { - layers.amendments = { - label: `${window.DecidimAwesome.texts.amendments}`, - group: L.featureGroup.subGroup(cluster) - } - control.addOverlay(layers.amendments.group, layers.amendments.label); - layers.amendments.group.addTo(map); - } - - fetchProposals(component, '', (element, marker) => { - if(show[element.state || 'notAnswered']) { - drawMarker(element, marker, component).addTo(layers.proposals.group) - } - }, () => { - // finall call - map.fitBounds(cluster.getBounds(), { padding: [50, 50] }); - allMarkers.forEach((item) => { - // add marker to amendments layers if it's an amendment - if(amendments.find((a) => a == item.element.id)) { - item.marker.removeFrom(layers.proposals.group); - item.marker.addTo(layers.amendments.group); - } - }); - }); - } - - if(component.type == "meetings") { - // add control layer for meetings - layers.meetings = { - label: `${component.name || window.DecidimAwesome.texts.meetings}`, - group: L.featureGroup.subGroup(cluster) - }; - control.addOverlay(layers.meetings.group, layers.meetings.label); - layers.meetings.group.addTo(map); - - fetchMeetings(component, '', (element, marker) => { - drawMarker(element, marker, component).addTo(layers.meetings.group); - }, () => { - map.fitBounds(cluster.getBounds(), { padding: [50, 50] }); - }); - } - }); - - - // add categories control layers - if(window.AwesomeMap.categories.length) { - let lastLayer = layers[Object.keys(layers)[Object.keys(layers).length - 1]]; - // Add Categories "title" - if(lastLayer) { - lastLayer.label = `${lastLayer.label}
${window.DecidimAwesome.texts.categories}`; - control.removeLayer(lastLayer.group); - control.addOverlay(lastLayer.group, lastLayer.label); - } - - window.AwesomeMap.categories.forEach((category) => { - // add control layer for this category - layers[category.id] = { - label: ` ${category.name}`, - group: L.featureGroup.subGroup(cluster) - }; - layers[category.id].group.addTo(map); - control.addOverlay(layers[category.id].group, layers[category.id].label); - // hide layer by default, it will be activated if there's any marker in it - setTimeout(() => { - $(`.awesome_map-category_${category.id}`).closest("label").hide(); - }); - }); - - // watch events for subcategories syncronitzation - const getCatFromClass = (name) => { - let id = name.match(/awesome_map-category_(\d+)/) - if(!id) return; - const cat = getCategory(id[1]); - if(!cat || !cat.name) return; - - return cat; - }; - - const indeterminateInput = (id) => { - $('[class^="awesome_map-category_"]').parent().prev().prop("indeterminate", false); - if(id) { - let $input = $(`.awesome_map-category_${id}`).parent().prev(); - if(!$input.prop("checked")) { - $input.prop("indeterminate", true); - } - } - }; - - map.on('overlayadd', (e) => { - const cat = getCatFromClass(e.name); - if(!cat) return; - // if it's a children, put the parent to indeterminate - indeterminateInput(cat.parent); - }); - - // on remove a parent category, remove all children - map.on('overlayremove', (e) => { - const cat = getCatFromClass(e.name); - if(!cat) return; - cat.children().forEach((c) => { - let $el = $(`.awesome_map-category_${c.id}`); - if($el.parent().prev().prop("checked")) { - $el.click(); - } - }); - }); - - } - - }; - - // currentMap might not be loaded yet so let's delay a bit - // TODO: improve this - const waitMap = () => { - if(exports.Decidim && exports.Decidim.currentMap) { - loadElements(exports.Decidim.currentMap); - } else { - setTimeout(() => { - waitMap(); - }, 100); - } - }; - - waitMap(); - -})(window); diff --git a/app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_proposals.js.es6 b/app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_proposals.js.es6 deleted file mode 100644 index ad7b135ea..000000000 --- a/app/assets/javascripts/decidim/decidim_awesome/awesome_map/legacy_proposals.js.es6 +++ /dev/null @@ -1,83 +0,0 @@ -// = require decidim/decidim_awesome/awesome_map/api_fetcher -// = require decidim/decidim_awesome/awesome_map/categories -// = require decidim/decidim_awesome/awesome_map/utilities - -((exports) => { - const { getCategory, truncate } = exports.AwesomeMap; - const query = `query ($id: ID!, $after: String!) { - component(id: $id) { - id - __typename - ... on Proposals { - proposals(first: 50, after: $after){ - pageInfo { - hasNextPage - endCursor - } - edges { - node { - id - state - title - body - address - coordinates { - latitude - longitude - } - amendments { - emendation { - id - } - } - category { - id - } - } - } - } - } - } - }`; - - const ProposalIcon = L.DivIcon.SVGIcon.DecidimIcon; - - const createMarker = (element, callback) => { - const marker = L.marker([element.coordinates.latitude, element.coordinates.longitude], { - icon: new ProposalIcon({ - fillColor: getCategory(element.category).color - }) - }); - - element.body = truncate(element.body.replace(/\n/g, "
")); - callback(element, marker); - }; - - const fetchProposals = (component, after, callback, finalCall = () => {}) => { - const variables = { - "id": component.id, - "after": after - }; - const api = new ApiFetcher(query, variables); - api.fetchAll((result) => { - if(result) { - result.component.proposals.edges.forEach((element) => { - if(!element.node) return; - - if(element.node.coordinates) { - element.node.link = component.url + '/proposals/' + element.node.id; - createMarker(element.node, callback); - } - }); - if (result.component.proposals.pageInfo.hasNextPage) { - fetchProposals(component, result.component.proposals.pageInfo.endCursor, callback, finalCall); - } else { - finalCall(); - } - } - }); - }; - - exports.AwesomeMap = exports.AwesomeMap || {}; - exports.AwesomeMap.fetchProposals = fetchProposals; -})(window); diff --git a/app/assets/javascripts/decidim/decidim_awesome/awesome_map/meetings.js.es6 b/app/assets/javascripts/decidim/decidim_awesome/awesome_map/meetings.js.es6 index e4961d79b..1397807b4 100644 --- a/app/assets/javascripts/decidim/decidim_awesome/awesome_map/meetings.js.es6 +++ b/app/assets/javascripts/decidim/decidim_awesome/awesome_map/meetings.js.es6 @@ -101,7 +101,7 @@ }; const fetchMeetings = (component, after, callback, finalCall = () => {}) => { - + const variables = { "id": component.id, "after": after @@ -111,7 +111,7 @@ if(result) { result.component.meetings.edges.forEach((element) => { if(!element.node) return; - + if(element.node.coordinates) { element.node.link = component.url + '/meetings/' + element.node.id; createMarker(element.node, callback); diff --git a/app/assets/javascripts/decidim/decidim_awesome/editors/legacy_quill_editor.js.es6 b/app/assets/javascripts/decidim/decidim_awesome/editors/legacy_quill_editor.js.es6 new file mode 100644 index 000000000..446a00153 --- /dev/null +++ b/app/assets/javascripts/decidim/decidim_awesome/editors/legacy_quill_editor.js.es6 @@ -0,0 +1,160 @@ +// = require image-upload.min +// = require image-resize.min +// = require inscrybmde.min.js +// = require inline-attachment.js +// = require codemirror-4.inline-attachment.js +// = require jquery.inline-attachment.js +// = require_self + +((exports) => { + exports.DecidimAwesome = exports.DecidimAwesome || {}; + + // Redefines Quill editor with images + if(exports.DecidimAwesome.allow_images_in_full_editor || exports.DecidimAwesome.allow_images_in_small_editor || exports.DecidimAwesome.use_markdown_editor) { + + const quillFormats = ["bold", "italic", "link", "underline", "header", "list", "video", "image", "alt"]; + + const createQuillEditor = (container) => { + const toolbar = $(container).data("toolbar"); + const disabled = $(container).data("disabled"); + + let quillToolbar = [ + ["bold", "italic", "underline"], + [{ list: "ordered" }, { list: "bullet" }], + ["link", "clean"] + ]; + + let addImage = false; + + if (toolbar === "full") { + quillToolbar = [ + [{ header: [1, 2, 3, 4, 5, 6, false] }], + ...quillToolbar + ]; + if(exports.DecidimAwesome.allow_images_in_full_editor) { + quillToolbar.push(["video", "image"]); + addImage = true; + } else { + quillToolbar.push(["video"]); + } + } else if (toolbar === "basic") { + if(exports.DecidimAwesome.allow_images_in_small_editor) { + quillToolbar.push(["video", "image"]); + addImage = true; + } else { + quillToolbar.push(["video"]); + } + } else if(exports.DecidimAwesome.allow_images_in_small_editor) { + quillToolbar.push(["image"]); + addImage = true; + } + + let modules = { + toolbar: quillToolbar + }; + const $input = $(container).siblings('input[type="hidden"]'); + container.innerHTML = $input.val() || ""; + const token = $( 'meta[name="csrf-token"]' ).attr( 'content' ); + + if(addImage) { + modules.imageResize = { + modules: ["Resize", "DisplaySize"] + } + modules.imageUpload = { + url: exports.DecidimAwesome.editor_uploader_path, // server url. If the url is empty then the base64 returns + method: 'POST', // change query method, default 'POST' + name: 'image', // custom form name + withCredentials: false, // withCredentials + headers: { 'X-CSRF-Token': token }, // add custom headers, example { token: 'your-token'} + // personalize successful callback and call next function to insert new url to the editor + callbackOK: (serverResponse, next) => { + $(quill.getModule("toolbar").container).last().removeClass('editor-loading') + next(serverResponse.url); + }, + // personalize failed callback + callbackKO: serverError => { + $(quill.getModule("toolbar").container).last().removeClass('editor-loading') + alert(serverError.message); + }, + checkBeforeSend: (file, next) => { + $(quill.getModule("toolbar").container).last().addClass('editor-loading') + next(file); // go back to component and send to the server + } + } + } + + const quill = new Quill(container, { + modules: modules, + formats: quillFormats, + theme: "snow" + }); + + if (disabled) { + quill.disable(); + } + + quill.on("text-change", () => { + const text = quill.getText(); + + // Triggers CustomEvent with the cursor position + // It is required in input_mentions.js + let event = new CustomEvent("quill-position", { + detail: quill.getSelection() + }); + container.dispatchEvent(event); + + if (text === "\n") { + $input.val(""); + } else { + $input.val(quill.root.innerHTML); + } + }); + + if(addImage) { + const t = window.DecidimAwesome.texts["drag_and_drop_image"]; + $(container).after(`

${t}

`); + } + }; + + const createMarkdownEditor = (container) => { + $(container).hide(); + const t = window.DecidimAwesome.texts["drag_and_drop_image"]; + const token = $( 'meta[name="csrf-token"]' ).attr( 'content' ); + const $input = $(container).siblings('input[type="hidden"]'); + const inscrybmde = new InscrybMDE({ + element: $input[0], + spellChecker: false, + renderingConfig: { + codeSyntaxHighlighting: true + } + }); + + // Allow image upload + if(window.DecidimAwesome.allow_images_in_markdown_editor) { + $(inscrybmde.gui.statusbar).prepend(`${t}`); + inlineAttachment.editors.codemirror4.attach(inscrybmde.codemirror, { + uploadUrl: window.DecidimAwesome.editor_uploader_path, + uploadFieldName: "image", + jsonFieldName: "url", + extraHeaders: { "X-CSRF-Token": token } + }); + } + }; + + const quillEditor = () => { + $(".editor-container").each((idx, container) => { + if(exports.DecidimAwesome.use_markdown_editor) { + createMarkdownEditor(container); + } else { + createQuillEditor(container); + } + }); + }; + + exports.Decidim = exports.Decidim || {}; + exports.Decidim.quillEditor = quillEditor; + exports.Decidim.createQuillEditor = createQuillEditor; + exports.Decidim.createMarkdownEditor = createMarkdownEditor; + + } +})(window); diff --git a/app/assets/javascripts/decidim/decidim_awesome/editors/quill_editor.js.es6 b/app/assets/javascripts/decidim/decidim_awesome/editors/quill_editor.js.es6 index cd94589d7..6ab1a9388 100644 --- a/app/assets/javascripts/decidim/decidim_awesome/editors/quill_editor.js.es6 +++ b/app/assets/javascripts/decidim/decidim_awesome/editors/quill_editor.js.es6 @@ -12,14 +12,14 @@ // Redefines Quill editor with images if(exports.DecidimAwesome.allow_images_in_full_editor || exports.DecidimAwesome.allow_images_in_small_editor || exports.DecidimAwesome.use_markdown_editor) { - const quillFormats = ["bold", "italic", "link", "underline", "header", "list", "video", "image", "alt"]; + const quillFormats = ["bold", "italic", "link", "underline", "header", "list", "video", "image", "alt", "break"]; const createQuillEditor = (container) => { const toolbar = $(container).data("toolbar"); const disabled = $(container).data("disabled"); let quillToolbar = [ - ["bold", "italic", "underline"], + ["bold", "italic", "underline", "linebreak"], [{ list: "ordered" }, { list: "bullet" }], ["link", "clean"] ]; @@ -50,7 +50,13 @@ } let modules = { - toolbar: quillToolbar + linebreak: {}, + toolbar: { + container: quillToolbar, + handlers: { + "linebreak": exports.Decidim.Editor.lineBreakButtonHandler + } + } }; const $input = $(container).siblings('input[type="hidden"]'); container.innerHTML = $input.val() || ""; @@ -109,11 +115,16 @@ $input.val(quill.root.innerHTML); } }); - + if(addImage) { const t = window.DecidimAwesome.texts["drag_and_drop_image"]; $(container).after(`

${t}

`); } + + // After editor is ready, linebreak_module deletes two extraneous new lines + quill.emitter.emit("editor-ready"); + + return quill; }; const createMarkdownEditor = (container) => { @@ -157,4 +168,4 @@ exports.Decidim.createMarkdownEditor = createMarkdownEditor; } -})(window); \ No newline at end of file +})(window); diff --git a/app/assets/javascripts/decidim/decidim_awesome/legacy_admin.js b/app/assets/javascripts/decidim/decidim_awesome/legacy_admin.js new file mode 100644 index 000000000..172d2ce00 --- /dev/null +++ b/app/assets/javascripts/decidim/decidim_awesome/legacy_admin.js @@ -0,0 +1,3 @@ +// = require decidim/decidim_awesome/admin/constraints +// = require decidim/decidim_awesome/admin/codemirror +// = require decidim/decidim_awesome/editors/legacy_quill_editor diff --git a/app/assets/javascripts/decidim/decidim_awesome/legacy_application.js b/app/assets/javascripts/decidim/decidim_awesome/legacy_application.js new file mode 100644 index 000000000..038bf46e0 --- /dev/null +++ b/app/assets/javascripts/decidim/decidim_awesome/legacy_application.js @@ -0,0 +1,4 @@ +// = require decidim/decidim_awesome/proposals/images +// = require decidim/decidim_awesome/editors/legacy_quill_editor +// = require decidim/decidim_awesome/editors/markdown_view +// = require decidim/decidim_awesome/forms/autosave diff --git a/app/awesome_overrides/presenters/decidim/proposals/proposal_presenter_override.rb b/app/awesome_overrides/presenters/decidim/proposals/proposal_presenter_override.rb index 7c0317474..23850095c 100644 --- a/app/awesome_overrides/presenters/decidim/proposals/proposal_presenter_override.rb +++ b/app/awesome_overrides/presenters/decidim/proposals/proposal_presenter_override.rb @@ -25,15 +25,9 @@ def body(links: false, extras: true, strip_tags: false, all_locales: false) # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/PerceivedComplexity - if defined? translated_attribute - text = translated_attribute(proposal.body) - - text = strip_tags(sanitize_text(text)) if strip_tags - else - # TODO: remove when 0.22 is diched - text = proposal.body - text = strip_tags(text) if strip_tags - end + # TODO: remove when 0.23 is ditched + text = translated_attribute(proposal.body) + text = strip_tags(sanitize_text(text)) if strip_tags renderer = Decidim::ContentRenderers::HashtagRenderer.new(text) text = renderer.render(links: links, extras: extras).html_safe diff --git a/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb b/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb index 04052f5ef..ee5e45ae9 100644 --- a/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb +++ b/app/controllers/decidim/decidim_awesome/admin/checks_controller.rb @@ -37,7 +37,7 @@ def decidim_version end def decidim_version_valid? - Gem::Dependency.new("", DecidimAwesome::COMPAT_DECIDIM_VERSION).match?("", decidim_version) + Gem::Dependency.new("", DecidimAwesome::COMPAT_DECIDIM_VERSION).match?("", decidim_version, true) end def head_addons(part) diff --git a/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb b/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb index 627bdf9b6..975182efa 100644 --- a/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb +++ b/app/controllers/decidim/decidim_awesome/admin/menu_hacks_controller.rb @@ -85,7 +85,7 @@ def menu_item end def current_items - @current_items ||= current_menu.items(true) + @current_items ||= current_menu.items(include_invisible: true) end def current_menu @@ -101,7 +101,7 @@ def md5(text) end def visibility_options - MenuForm::VISIBILITY_STATES.map { |key| [I18n.t(".menu_hacks.form.visibility.#{key}", scope: "decidim.decidim_awesome.admin"), key] }.to_h + MenuForm::VISIBILITY_STATES.index_by { |key| I18n.t(".menu_hacks.form.visibility.#{key}", scope: "decidim.decidim_awesome.admin") } end def target_options diff --git a/app/controllers/decidim/decidim_awesome/map_component/map_controller.rb b/app/controllers/decidim/decidim_awesome/map_component/map_controller.rb index 19b1eeadf..2557a49fe 100644 --- a/app/controllers/decidim/decidim_awesome/map_component/map_controller.rb +++ b/app/controllers/decidim/decidim_awesome/map_component/map_controller.rb @@ -14,10 +14,7 @@ def show private def maps_enabled? - return Decidim::Map.configured? if defined?(Decidim::Map) - - # TODO: remove when 0.22 support is diched - Decidim.geocoder.present? + Decidim::Map.configured? end def map_components diff --git a/app/helpers/decidim/decidim_awesome/map_helper.rb b/app/helpers/decidim/decidim_awesome/map_helper.rb index 28d970faf..a2db289cd 100644 --- a/app/helpers/decidim/decidim_awesome/map_helper.rb +++ b/app/helpers/decidim/decidim_awesome/map_helper.rb @@ -6,8 +6,6 @@ module MapHelper include Decidim::MapHelper def awesome_map_for(components, &block) - return legacy_map_for(components, &block) unless defined?(Decidim::Map) - map = dynamic_map_for({}, {}, &block) return unless map @@ -39,50 +37,6 @@ def awesome_map_for(components, &block) content_tag(:div, map, map_html_options) end - # TODO: remove when 0.22 support is diched - def legacy_map_for(components) - return if Decidim.geocoder.blank? - - map_html_options = { - class: "google-map", - id: "map", - "data-components" => components.map do |component| - { - id: component.id, - type: component.manifest.name, - name: translated_attribute(component.name), - url: Decidim::EngineRouter.main_proxy(component).root_path, - amendments: component.manifest.name == :proposals ? Decidim::Proposals::Proposal.where(component: component).only_emendations.count : 0 - } - end.to_json, - "data-collapsed" => current_component.settings.collapse, - "data-show-not-answered" => current_component.current_settings.show_not_answered, - "data-show-accepted" => current_component.current_settings.show_accepted, - "data-show-withdrawn" => current_component.current_settings.show_withdrawn, - "data-show-evaluating" => current_component.current_settings.show_evaluating, - "data-show-rejected" => current_component.current_settings.show_rejected, - "data-markers-data" => [].to_json - } - - if Decidim.geocoder[:here_api_key] - map_html_options["data-here-api-key"] = Decidim.geocoder[:here_api_key] - else - # Compatibility mode for old api_id/app_code configurations - map_html_options["data-here-app-id"] = Decidim.geocoder[:here_app_id] - map_html_options["data-here-app-code"] = Decidim.geocoder[:here_app_code] - end - - content = capture { yield }.html_safe - help = content_tag(:div, class: "map__help") do - content_tag(:p, I18n.t("screen_reader_explanation", scope: "decidim.map.dynamic"), class: "show-for-sr") - end - content_tag :div, class: "awesome-map" do - map = content_tag(:div, "", map_html_options) - - help + map + content - end - end - # rubocop:disable Rails/HelperInstanceVariable def current_categories return @current_categories if @current_categories @@ -102,6 +56,7 @@ def current_categories private + # rubocop:disable Style/FormatStringToken def append_category(category) @h += @golden_ratio_conjugate @h %= 1 @@ -114,11 +69,12 @@ def append_category(category) color: format("#%02x%02x%02x", r, g, b) ) end + # rubocop:enable Style/FormatStringToken # rubocop:enable Rails/HelperInstanceVariable - # rubocop:disable Naming/UncommunicativeMethodParamName # HSV values in [0..1[ # returns [r, g, b] values from 0 to 255 + # rubocop:disable Naming/MethodParameterName def hsv_to_rgb(h, s, v) h_i = (h * 6).to_i f = h * 6 - h_i @@ -157,7 +113,7 @@ def hsv_to_rgb(h, s, v) end [(r * 256).to_i, (g * 256).to_i, (b * 256).to_i] end - # rubocop:enable Naming/UncommunicativeMethodParamName end + # rubocop:enable Naming/MethodParameterName end end diff --git a/app/uploaders/decidim/decidim_awesome/image_uploader.rb b/app/uploaders/decidim/decidim_awesome/image_uploader.rb index c874d8427..533720229 100644 --- a/app/uploaders/decidim/decidim_awesome/image_uploader.rb +++ b/app/uploaders/decidim/decidim_awesome/image_uploader.rb @@ -10,11 +10,6 @@ class ImageUploader < Decidim::ImageUploader process resize_to_fit: [nil, 237] end - # TODO: remove when diching 0.22 support - def extension_white_list - %w(jpg jpeg png) - end - def extension_whitelist %w(jpg jpeg png) end diff --git a/app/views/decidim/decidim_awesome/admin/checks/index.html.erb b/app/views/decidim/decidim_awesome/admin/checks/index.html.erb index bce15f792..3dcd4ebc5 100644 --- a/app/views/decidim/decidim_awesome/admin/checks/index.html.erb +++ b/app/views/decidim/decidim_awesome/admin/checks/index.html.erb @@ -57,7 +57,7 @@