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

Use consistent style for Lint/SymbolConversion #600

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aliismayilov
Copy link
Contributor

I'd like to suggest to use consistent style for Lint/SymbolConversion. Examples from rubocop docs:

# bad
{
  a: 1,
  'b-c': 2
}

# good (quote all keys if any need quoting)
{
  'a': 1,
  'b-c': 2
}

# good (no quoting required)
{
  a: 1,
  b: 2
}

@searls searls added the rule change 👩‍⚖️ Suggest a style guide rule change label Jan 12, 2024
@searls
Copy link
Contributor

searls commented Jan 12, 2024

This is a tricky one, because there are two competing interests here. On one hand, I agree that consistency in hash format is important. For example, if a single => is required in a hash literal, Standard converts all entries to use => so that it and : aren't interspersed.

On the other hand, enforcing that the presence of a single illegal identifier should force all such identifiers to be quoted seems overkill. For example, if you carried the logic that the presence of one illegal symbol literal (:b-c) should require all legal symbol literals to be quoted, you could make the same argument for illegal method names (or any other construct).

I'd definitely disagree with a rule that did this, for example:

# bad
class Foo
  def legal_name
  end
  
  define_method :'illegal-name' do
  end
end

# good
class Foo
  define_method :legal_name do
  end
  
  define_method :'illegal-name' do
  end
end

One additional argument against, is that I'm always cautious of rules where a later line could force changes in prior lines. So if the 5th line of a hash literal contains an illegal symbol literal name, it shouldn't cause git churn for lines 1-4 without good reason. I think the =>/: rises to that bar, but I don't think this does.

As a result, I'd be 👎 to making this change.

@luizkowalski
Copy link

hey 👋🏻

I'm not sure I get the example. I might be wrong, but it looks like this rule, when using consistent configuration only applies to hashes and alias methods, for example, are skipped so I'm not sure I follow your example. SymbolConversion does not trigger anything for these examples you showed.

@searls
Copy link
Contributor

searls commented Jan 12, 2024

@luizkowalski no it doesn't. I was using it to illustrate the broader point of why I don't think consistency is an unqualified principle in cases where you're working around illegal identifiers.

@aliismayilov
Copy link
Contributor Author

This is a tricky one, because there are two competing interests here. On one hand, I agree that consistency in hash format is important. For example, if a single => is required in a hash literal, Standard converts all entries to use => so that it and : aren't interspersed.

On the other hand, enforcing that the presence of a single illegal identifier should force all such identifiers to be quoted seems overkill. For example, if you carried the logic that the presence of one illegal symbol literal (:b-c) should require all legal symbol literals to be quoted, you could make the same argument for illegal method names (or any other construct).

I'd definitely disagree with a rule that did this, for example:

# bad
class Foo
  def legal_name
  end
  
  define_method :'illegal-name' do
  end
end

# good
class Foo
  define_method :legal_name do
  end
  
  define_method :'illegal-name' do
  end
end

One additional argument against, is that I'm always cautious of rules where a later line could force changes in prior lines. So if the 5th line of a hash literal contains an illegal symbol literal name, it shouldn't cause git churn for lines 1-4 without good reason. I think the =>/: rises to that bar, but I don't think this does.

As a result, I'd be 👎 to making this change.

Fair points. To be honest, I don't have a good argument other than preferring consistency when reading a hash definition.

Due to configured Style/HashSyntax I can't even manually change

{
  a: 1,
  "b-c": 2
}

to

{
  :"a" => 1,
  :"b-c" => 2
}

🤷

@aliismayilov
Copy link
Contributor Author

I guess an example from a real project would have more weight to it :) See how it even messes up with syntax highlighting.

Screenshot 2024-01-12 at 19 32 52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule change 👩‍⚖️ Suggest a style guide rule change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants