Feature #14153
open[PATCH] resurrection of # -*- warn_past_scope: true -*-
Description
From 2addeedcf8838dc15d127fffd888962b34879439 Mon Sep 17 00:00:00 2001
From: "Urabe, Shyouhei" <shyouhei@ruby-lang.org>
Date: Mon, 4 Dec 2017 19:28:55 +0900
Subject: [PATCH] resurrection of # -*- warn_past_scope: true -*-
I understand this feature was killed due to [Bug #10661].
However sometimes i _do_ want to check variable name collisions.
Please consider this feature again, with default off; no warning shall
be emitted unless theere are the dedicated magic comment in the source
code.
Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>
---
parse.y | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/parse.y b/parse.y
index 03b9ed992e..a4a31af5e0 100644
--- a/parse.y
+++ b/parse.y
@@ -37,7 +37,7 @@
#include "probes.h"
#ifndef WARN_PAST_SCOPE
-# define WARN_PAST_SCOPE 0
+# define WARN_PAST_SCOPE 1
#endif
#define TAB_WIDTH 8
--
2.15.1
Updated by shyouhei (Shyouhei Urabe) about 7 years ago
- Related to Bug #10661: The "possible reference to past scope" warning is quite frustrating and is forcing me to change my variable names from what I want added
Updated by shyouhei (Shyouhei Urabe) about 7 years ago
This patch works like this:
% ./ruby --disable-gems -w -ve '[1, 2, 3].sample.tap { |rand| puts "Random value: #{rand}" }; puts "Another random value: #{rand}"'
ruby 2.5.0dev (2017-12-04 warn_past_scope 61011) [x86_64-darwin15]
Random value: 3
Another random value: 0.25989520023218615
%
%
% ./ruby --disable-gems -w -ve '# warn_past_scope: true' -e '[1, 2, 3].sample.tap { |rand| puts "Random value: #{rand}" }; puts "Another random value: #{rand}"'
ruby 2.5.0dev (2017-12-04 warn_past_scope 61011) [x86_64-darwin15]
-e:2: warning: possible reference to past scope - rand
Random value: 2
Another random value: 0.5832209137869108
%
Updated by shevegen (Robert A. Heiler) about 7 years ago
I have no pro or con opinion so I will not comment on the suggestion.
I have one question though, apologies for a bit of side tracking:
- Can this be combined with other comment options such as "# frozen_string_literal: true"
?
Perhaps it may not apply as your example is only commandline but
I wanted to ask just in case anyone may want to combine more
than one option, for whatever reason, into the .rb file at hand.
Updated by marcandre (Marc-Andre Lafortune) about 7 years ago
Seems to me to be more appropriate as a Rubocop cop.
Updated by shyouhei (Shyouhei Urabe) about 7 years ago
@shevegen (Robert A. Heiler) Yes. You can write multiple magic comments
-
at once, like this:
# -*- coding: utf-8; frozen_string_literal: true; warn_indent: true; warn_past_scope: true -*-
-
or, line by line like this:
# coding: utf-8 # frozen_string_literal: true # warn_indent: true # warn_past_scope: true
Updated by matz (Yukihiro Matsumoto) almost 7 years ago
At least, I don't like the name warn_past_code
. It's not intuitive.
And it may be better to be handled by Rubocop as Marc-Andre said.
Matz.
Updated by dsferreira (Daniel Ferreira) almost 7 years ago
Are we relying on rubocop as ruby’s official linter?
This question comes inline with my recent previous comment around core functionalities that I believe should be better managed as part of ruby API.
Debugger, Coverage, Unit tests, Benchmarks, Performance tools and yes Linter.
Missing Documentation here.
Maybe something else?