Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lint/Unused{Local,Instance,Class}VariableAccess #542

Open
nobodywasishere opened this issue Jan 20, 2025 · 2 comments · May be fixed by #552
Open

Add Lint/Unused{Local,Instance,Class}VariableAccess #542

nobodywasishere opened this issue Jan 20, 2025 · 2 comments · May be fixed by #552
Assignees
Labels
Milestone

Comments

@nobodywasishere
Copy link
Contributor

As local, instance, and class vars are known and cannot point to methods, we can add rules that will report if a local / instance / class var is in a void context:

a = 1

begin
  a
# ^ error: local variable access in void context
  puts a
end

class MyClass
  @world : Int32 = 0

  def hello
    @world
    # ^^^^ error: instance var access in void context
    @world + 1
  end
end
@nobodywasishere nobodywasishere changed the title Add Lint/Unused{Local,Instance,Class}VarAccess Add Lint/Unused{Local,Instance,Class}VariableAccess Jan 20, 2025
@Sija
Copy link
Member

Sija commented Jan 20, 2025

As local, instance, and class vars are known and cannot point to methods [...]

While this statement is true for instance and class variables, it doesn't hold for local variables - since these could easily be calls to methods.

@nobodywasishere
Copy link
Contributor Author

For local vars, we will know what they are as they'll be assigned within the current scope (see the scope visitor).

@Sija Sija added the rule label Jan 21, 2025
@Sija Sija added this to the 1.7.0 milestone Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants