Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Discourage the use of writer methods with rescued exceptions #957

Open
@viralpraxis

Description

@viralpraxis

ref:rubocop/rubocop#13588

This is a little-known (I believe) and rarely used feature of the rescue operator, which allows assigning an exception using an object's writer method:

Foo=Struct.new(:exception)foo=Foo.newbegindo_something_that_might_raiserescue=>foo.exception# `Foo#exception=` will be calledRails.error.report(foo.exception)do_something_with_exception(foo.exception)end

I propose introducing a new cop that detects such patterns and suggests expanding them to

Foo=Struct.new(:exception)foo=Foo.newbegindo_something_that_might_raiserescue=>efoo.exception=e# if requiredRails.error.report(e)do_something_with_exception(e)end

This cop could also support an alternative style that, conversely, suggests using the writer variant (where applicable).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp